📄 shoeboxtypfile.java
字号:
if (label.equals("\\+intprc")) { // reset lastFrom = ""; lastTo = ""; // procType = "Lookup"; procType = "Parse"; // hb, 7 sep 04, change default } if (label.equals("\\mkrFrom")) { lastFrom = content; } if (label.equals("\\mkrTo")) { lastTo = content; } if (line.indexOf("Lookup") >= 0) { // line contains ParseProc // procType = "Parse"; procType = "Lookup"; // hb, 7 sep 04 } // hb, 16 sep 04 if (line.indexOf("ParseProc") >= 0) { procType = "Parse"; } if (label.equals("\\-intprc")) { // store results in Hashtables and arrays fromArray.add("\\" + lastFrom); toArray.add("\\" + lastTo); tofromHash.put("\\" + lastTo, "\\" + lastFrom); procedureTypeHash.put("\\" + lastTo, procType); } //MK:02/08/16 add language for tier if (label.equals("\\+mkr")) { tierToSetLanguageFor = content; } if (label.equals("\\lng")) { if (content == null) { continue; } if (!content.equals("IPA") && !content.equals("Phonetic")) { continue; } if (tierToSetLanguageFor == null) { continue; } tiersWithIPA.add(tierToSetLanguageFor); } if (label.equals("\\-mkr")) { tierToSetLanguageFor = null; } } br.close(); filereader.close(); // HS july 2005 do some post processing; the first mkrFrom under the RecordMarker // is typically not listed in the 'intproclst'. Now assume that a marker that is // direct child of the RecordMarker and has a child with proc "Parse" that this // in between marker also has a "Parse" relation to the RecordMarker and add it // to the hash // HS 29 sep 2005: it seems to be save to assume a "Parse" relation in the above // situation even this direct child of the RecordMarker only has a "Lookup" child. int size = toArray.size(); //loop only over existing entries for (int i = 0; i < size; i++) { String key = (String) toArray.get(i); String val = (String) procedureTypeHash.get(key); if ((val != null) && (val.equals("Parse") || val.equals("Lookup"))) { String from = (String) tofromHash.get(key); if ((from != null) && !toArray.contains(from)) { // assume a Parse relation to RecordMarker fromArray.add("\\" + recordMarker); toArray.add(from); tofromHash.put(from, "\\" + recordMarker); procedureTypeHash.put(from, "Parse"); } } } } // HB, 30 jul 02: added because necessary in ShoeboxArray class to determine number of spaces // to pad lines in case of 'broken' interlinear blocks. /** * Returns all shoebox tier markers that take part in the interlinear setup. * * Note: HS july 2005 * Changed the way the set of markers that participate in the interlinear setup * is build: (based on a very basic understanding of what is possible in a Shoebox file)<br> * - before: * - include all markers except the root tier marker * - after: * - include all markers (and their descendants) that have a "Parse" or "TimeSubdivision" * relationship with the root tier marker or that have at least one descendant marker * that has a "Parse" or "TimeSubdivision" relationship with its parent * * Question: should markers that are marked for exclusion from import (and their descendants) * be excluded from this Set (or is this handled by ShoeboxArray/Parser)?? */ public HashSet getInterlinearTierMarkers() { //printStats(); HashSet markerSet = new HashSet(); String rootMkr = "\\" + interlinearRootMarker; for (int i = 0; i < toArray.size(); i++) { String mkrLabel = (String) toArray.get(i); if (mkrLabel.equals(rootMkr) || excludeFromImport(mkrLabel)) { //System.out.println("Skipping marker: " + mkrLabel); continue; } String proc = (String) procedureTypeHash.get(mkrLabel); String parent = (String) tofromHash.get(mkrLabel); if ((proc != null) && (parent != null) && parent.equals(rootMkr)) { if (proc.equals("Parse") || proc.equals("TimeSubdivision") || proc.equals("IncludedIn")) { markerSet.add(mkrLabel); markerSet.addAll(getDescendantsOf(mkrLabel)); //System.out.println("Adding... " + mkrLabel); } else { // only add the marker + sub markers if somewhere down the tree a // "Parse" relationship is encountered if (atLeastOneParseInTree(mkrLabel)) { //System.out.println("Parse found in tree: " + mkrLabel); markerSet.add(mkrLabel); markerSet.addAll(getDescendantsOf(mkrLabel)); } } } } //markerSet.addAll(toArray); //markerSet.addAll(fromArray); // HB, 15-9-04 if (markerSet.contains("\\" + interlinearRootMarker)) { markerSet.remove("\\" + interlinearRootMarker); } /* System.out.println("\nMarkers..."); Iterator hsIter = markerSet.iterator(); while (hsIter.hasNext()) { String mkrLabel = (String) hsIter.next(); System.out.println(mkrLabel); } */ return markerSet; } /** * Recursively get the children (of any 'procedure' type) of the * specified marker. * * @param mkrLabel the parent marker * @return a (flat) list of descendant markers */ private List getDescendantsOf(String mkrLabel) { List desc = new ArrayList(); if (fromArray.contains(mkrLabel) && !excludeFromImport(mkrLabel)) { Iterator keysIt = tofromHash.keySet().iterator(); String key = null; String val = null; while (keysIt.hasNext()) { key = (String) keysIt.next(); val = (String) tofromHash.get(key); if (val.equals(mkrLabel) && !excludeFromImport(key)) { desc.add(key); //key is the "toMkr" desc.addAll(getDescendantsOf(key)); } } } return desc; } /** * Check the marker's subtree to see if there is somewhere down the tree * a "Parse" or "TimeSubdivision" relationship. * * @param mkrLabel probe the descendants of this marker * @return true if a Parse relationship has been found, false otherwise */ private boolean atLeastOneParseInTree(String mkrLabel) { boolean parse = false; if (toArray.contains(mkrLabel)) { Iterator keysIt = tofromHash.keySet().iterator(); String key = null; String val = null; String proc = null; while (keysIt.hasNext()) { key = (String) keysIt.next(); val = (String) tofromHash.get(key); proc = (String) procedureTypeHash.get(key); if (val.equals(mkrLabel)) { if ((proc != null) && (proc.equals("Parse") || proc.equals("TimeSubdivision"))) { return true; } else { return atLeastOneParseInTree(key); } } } } return parse; } /** * When a marker is marked for exclusion recursively add the descendant markers * to the array of excluded tiers as well. * * @param parent the parent marker */ private void addDescendantsToExcludedTiers(String parent) { Iterator it = tofromHash.keySet().iterator(); String toKey; String fromVal; while (it.hasNext()) { toKey = (String) it.next(); fromVal = (String) tofromHash.get(toKey); if (fromVal.equals(parent)) { excludedTiers.add(toKey.substring(1)); addDescendantsToExcludedTiers(toKey); } } } /** * @return All shoebox tiers (without backslash) with language IPA */ public boolean isIPAtier(String name) { if (name.startsWith("\\")) { name = name.substring(1); } // System.out.println("isIPAtier("+name+") --> " + tiersWithIPA.contains(name)); return tiersWithIPA.contains(name); } /** * DOCUMENT ME! * * @param name DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean isUnicodeTier(String name) { if (allTiersUnicode) { return true; } if (name.startsWith("\\")) { name = name.substring(1); } // System.out.println("isIPAtier("+name+") --> " + tiersWithIPA.contains(name)); return tiersWithUnicode.contains(name); } /** * DOCUMENT ME! * * @param name DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean excludeFromImport(String name) { if (name.startsWith("\\")) { name = name.substring(1); } return excludedTiers.contains(name); } /** * Prints the contents of the arrays and hashtables, to get an idea of what * is inside. */ private void printStats() { System.out.println("Root: " + interlinearRootMarker); System.out.println("\nTo-From hash..."); Iterator keysIt = tofromHash.keySet().iterator(); while (keysIt.hasNext()) { String key = (String) keysIt.next(); String val = (String) tofromHash.get(key); System.out.println("Key-value: " + key + " - " + val); } // print procedure Hash System.out.println("\nProcedure hash..."); keysIt = procedureTypeHash.keySet().iterator(); while (keysIt.hasNext()) { String key = (String) keysIt.next(); String val = (String) procedureTypeHash.get(key); System.out.println("Key-value: " + key + " - " + val); } String rootMkr = "\\" + interlinearRootMarker; System.out.println("\nTo array..."); for (int i = 0; i < toArray.size(); i++) { String mkrLabel = (String) toArray.get(i); if (mkrLabel.equals(rootMkr)) { System.out.println(mkrLabel + " (root)"); } else { System.out.println(mkrLabel); } } System.out.println("\nFrom array..."); for (int i = 0; i < fromArray.size(); i++) { String mkrLabel = (String) fromArray.get(i); if (mkrLabel.equals(rootMkr)) { System.out.println(mkrLabel + " (root)"); } else { System.out.println(mkrLabel); } } System.out.println("\nExcluded array..."); for (int i = 0; i < excludedTiers.size(); i++) { String mkrLabel = (String) excludedTiers.get(i); if (mkrLabel.equals(rootMkr)) { System.out.println(mkrLabel + " (root)"); } else { System.out.println(mkrLabel); } } } /** * When true all markers are to be considered to be Unicode. * @return Returns whether all tiers/markers are Unicode. */ public boolean isAllTiersUnicode() { return allTiersUnicode; } /** * When true all markers will be considered to be Unicode. * @param allTiersUnicode true if all markers are to be handled as Unicode. */ public void setAllTiersUnicode(boolean allTiersUnicode) { this.allTiersUnicode = allTiersUnicode; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -