/** * Create a new <code>TaggedWord</code>. * * @param word This word is passed to the supertype constructor * @param tag The <code>value()</code> of this label is set as the * tag of this Label */ public TaggedWord(Label word, Label tag) { super(word); this.tag = tag.value(); }
private static Label headMark(Label l) { Label l1 = l.labelFactory().newLabel(l); l1.setValue(l1.value() + headMark); return l1; }
@Override public void setFromString(String labelStr) { Label lab = label(); if (lab != null) { lab.setFromString(labelStr); } }
@Override public Label transformNonterminalLabel(Tree tree) { if (tree.label() == null) { return null; } return tree.label().labelFactory().newLabel(tlp.basicCategory(tree.label().value())); }
public Tree transformTree(Tree tree) { Tree treeCopy = tree.deepCopy(); for (Tree subtree : treeCopy) { if (subtree.depth() < 1) { continue; } String categoryLabel = subtree.label().toString(); Label label = subtree.label(); label.setFromString(categoryLabel+"-t2"); } return treeCopy; } }
/** * Returns a factory that makes labels of the same type as this one. * May return {@code null} if no appropriate factory is known. * * @return the LabelFactory for this kind of label */ @Override public LabelFactory labelFactory() { Label lab = label(); if (lab == null) { return null; } return lab.labelFactory(); }
/** * Set the value for the label (if one is stored). * * @param value The value for the label */ public void setValue(String value) { Label lab = label(); if (lab != null) { lab.setValue(value); } }
private static boolean hasC(List<? extends Label> tags) { for (Label tag : tags) { if (tag.toString().startsWith("CC")) { return true; } } return false; }
/** * Looks for new names, destructively strips them out. * Destructively unescapes escaped chars, including "=", as well. */ private void initializeNamesNodesMaps(Tree t) { for (Tree node : t.subTreeList()) { Matcher m = namePattern.matcher(node.label().value()); if (m.find()) { namesToNodes.put(m.group(2), node); nodesToNames.put(node, m.group(2)); node.label().setValue(m.group(1)); } node.label().setValue(unescape(node.label().value())); } }
private void insertNPinPP(Tree t) { if (tlp.basicCategory(t.label().value()).equals("PP")) { Tree[] kids = t.children(); int i = 0; int j = kids.length - 1; while (i < j && prepositionTags.contains(tlp.basicCategory(kids[i].label().value()))) { i++; } // i now indexes first dtr of new NP while (i < j && postpositionTags.contains(tlp.basicCategory(kids[j].label().value()))) { j--; } // j now indexes last dtr of new NP if (i > j) { log.info("##### Warning -- no NP material here!"); return; // there is no NP material! } int npKidsLength = j - i + 1; Tree[] npKids = new Tree[npKidsLength]; System.arraycopy(kids, i, npKids, 0, npKidsLength); Tree np = t.treeFactory().newTreeNode(t.label().labelFactory().newLabel("NP"), Arrays.asList(npKids)); Tree[] newPPkids = new Tree[kids.length - npKidsLength + 1]; System.arraycopy(kids, 0, newPPkids, 0, i + 1); newPPkids[i] = np; System.arraycopy(kids, j + 1, newPPkids, i + 1, kids.length - j - 1); t.setChildren(newPPkids); System.out.println("#### inserted NP in PP"); t.pennPrint(); } }
public Tree transformTree(Tree tree) { Tree treeCopy = tree.deepCopy(); for (Tree subtree : treeCopy) { if (subtree.depth() < 2) { continue; } String categoryLabel = subtree.label().toString(); Label label = subtree.label(); label.setFromString(categoryLabel+"-t1"); } return treeCopy; } }
/** * Makes a deep copy of not only the Tree structure but of the labels as well. * The new tree will have nodes made by the given TreeFactory. * Each Label is copied using the labelFactory() returned * by the corresponding node's label. * It assumes that your labels give non-null labelFactory. * (Added by Aria Haghighi.) * * @param tf The TreeFactory used to make all nodes in the copied * tree structure * @return A Tree that is a deep copy of the tree structure and * Labels of the original tree. */ public Tree deepCopy(TreeFactory tf) { return deepCopy(tf, label().labelFactory()); }
@Override public void setValue(String value) { Label lab = label(); if (lab != null) { lab.setValue(value); } }
private static boolean hasI(List<? extends Label> tags) { for (Label tag : tags) { if (tag.toString().startsWith("I")) { return true; } } return false; }
/** * Create a new {@code WordTag} from a Label. The value of * the Label corresponds to the word of the WordTag. * * @param word The {@code value()} of this label is set as the * word of the {@code WordTag} * @param tag The {@code value()} of this label is set as the * tag of the {@code WordTag} */ public WordTag(Label word, Label tag) { this(word.value(), tag.value()); }
@Override public Tree evaluate(Tree tree, TregexMatcher tregex) { int newIndex = coindexer.generateIndex(); for(TsurgeonMatcher child : childMatcher) { Tree node = child.evaluate(tree, tregex); node.label().setValue(node.label().value() + coindexationIntroductionString + newIndex); } return tree; } }
public Tree transformTree(Tree t) { if (t.isLeaf()) { return t.treeFactory().newLeaf(t.label()); } Tree[] children = t.children(); Tree[] transformedChildren = new Tree[children.length]; for (int childIndex = 0; childIndex < children.length; childIndex++) { Tree child = children[childIndex]; transformedChildren[childIndex] = transformTree(child); } Label label = t.label(); if (!label.value().startsWith("&")) { return t.treeFactory().newTreeNode(label, Arrays.asList(transformedChildren)); } String[] nodeStrings = label.value().split("&"); int i = nodeStrings.length - 1; label = t.label().labelFactory().newLabel(nodeStrings[i]); Tree result = t.treeFactory().newTreeNode(label, Arrays.asList(transformedChildren)); while (i > 1) { i--; label = t.label().labelFactory().newLabel(nodeStrings[i]); result = t.treeFactory().newTreeNode(label, Collections.singletonList(result)); } return result; } }
private static int markStrahler(Tree t) { if (t.isLeaf()) { // don't annotate the words at leaves! return 1; } else { String cat = t.label().value(); int maxStrahler = -1; int maxMultiplicity = 0; for (int i = 0; i < t.numChildren(); i++) { int strahler = markStrahler(t.getChild(i)); if (strahler > maxStrahler) { maxStrahler = strahler; maxMultiplicity = 1; } else if (strahler == maxStrahler) { maxMultiplicity++; } } if (maxMultiplicity > 1) { maxStrahler++; // this is the one case where it grows } cat = cat + '~' + maxStrahler; Label label = t.label().labelFactory().newLabel(t.label()); label.setValue(cat); t.setLabel(label); return maxStrahler; } }
public Tree transformTree(Tree tree) { Tree treeCopy = tree.deepCopy(); for (Tree subtree : treeCopy) { if (subtree.depth() < 2) { continue; } String categoryLabel = subtree.label().toString(); Label label = subtree.label(); label.setFromString(categoryLabel+"-t3"); } return treeCopy; } }