protected Tree transformTreeHelper(Tree t) { if (t.isLeaf()) { Tree leaf = tf.newLeaf(t.label()); leaf.setScore(t.score()); return leaf; } List<Tree> newChildren = new ArrayList<>(); for (int childNum = 0, numKids = t.numChildren(); childNum < numKids; childNum++) { Tree child = t.getChild(childNum); Tree newChild = transformTreeHelper(child); if ((!newChild.isLeaf()) && newChild.label().value().indexOf('@') >= 0) { newChildren.addAll(newChild.getChildrenAsList()); } else { newChildren.add(newChild); } } Tree node = tf.newTreeNode(t.label(), newChildren); node.setScore(t.score()); return node; }
@Override void advance() { if (searchStack.isEmpty()) { next = null; } else { next = searchStack.pop(); if (pathMatchesNode(next)) { for (int i = next.numChildren() - 1; i >= 0; i--) { searchStack.push(next.getChild(i)); } } } } };
int childStart = 0; for (int c = 0, numCh = testTree.numChildren(); c < numCh; c++) { Tree child = testTree.getChild(c); boolean isExtra = true; int childEnd = childStart + child.yield().size();
@Override public void initialize() { searchStack = new Stack<>(); for (int i = t.numChildren() - 1; i >= 0; i--) { searchStack.push(t.getChild(i)); } if (!searchStack.isEmpty()) { advance(); } }
private static void localTreeString(Tree t, StringBuilder sb, int level) { sb.append('\n'); for (int i = 0; i < level; i++) { sb.append(" "); } sb.append('(').append(t.label()); if (level == 0 || isSynthetic(t.label().value())) { // if it is synthetic, recurse for (int c = 0; c < t.numChildren(); c++) { localTreeString(t.getChild(c), sb, level + 1); } } sb.append(')'); }
@Override void initialize() { if (t != matcher.getRoot()) { next = matcher.getParent(t); if (childNum > 0 && (next.numChildren() < childNum || next .getChild(childNum - 1) != t) || childNum < 0 && (next.numChildren() < -childNum || next.getChild(next .numChildren() + childNum) != t)) { next = null; } } } };
private static void taggedLeafLabels(Tree t, List<CoreLabel> l) { if (t.isPreTerminal()) { CoreLabel fl = (CoreLabel)t.getChild(0).label(); fl.set(CoreAnnotations.TagLabelAnnotation.class, t.label()); l.add(fl); } else { for (Tree kid : t.children()) { taggedLeafLabels(kid, l); } } }
/** * Get the right sibling of the given node, or some node which is * the right sibling of an ancestor of the given node. * * If no such node can be found, this method returns {@code null}. */ private Tree getRightSiblingOrRightAncestor(Tree t, Tree root) { Tree parent = t.parent(root); if (parent == null) return null; int idxWithinParent = parent.objectIndexOf(t); if (idxWithinParent < parent.numChildren() - 1) // Easy case: just return the immediate right sibling return parent.getChild(idxWithinParent + 1); return getRightSiblingOrRightAncestor(parent, root); }
WidthResult subWR = widthResult(tree.getChild(i), fM); if (i == 0) { nodeCenter += (sub + subWR.nodeCenter) / 2.0;
/** Doesn't accept nodes that are A over A nodes (perhaps due to * empty removal or are EDITED nodes). * * Also removes all w nodes. */ public boolean test(Tree t) { if(t.value() != null && t.value().equals("w")) return false; if (t.isLeaf() || t.isPreTerminal()) return true; return ! (t.label() != null && t.label().value() != null && t.label().value().equals(t.getChild(0).label().value())); } }
/** Doesn't accept nodes that are A over A nodes (perhaps due to * empty removal or are EDITED nodes). */ @SuppressWarnings("SimplifiableIfStatement") @Override public boolean test(Tree t) { if (t.isLeaf() || t.isPreTerminal()) { return true; } // The special switchboard non-terminals clause if ("EDITED".equals(t.label().value()) || "CODE".equals(t.label().value())) { return false; } if (t.numChildren() != 1) { return true; } return ! (t.label() != null && t.label().value() != null && t.label().value().equals(t.getChild(0).label().value())); }
List<Tree> newChildren = new ArrayList<>(2); // check done if (t.numChildren() <= leftProcessed + rightProcessed + 2) { Tree leftChild = t.getChild(leftProcessed); newChildren.add(leftChild); if (t.numChildren() == leftProcessed + rightProcessed + 1) { Tree rightChild = t.getChild(leftProcessed + 1); newChildren.add(rightChild); String labelStr = t.label().value(); Tree leftChild = t.getChild(leftProcessed); Tree rightChild = insideBinarizeLocalTree(t, headNum, head, leftProcessed + 1, rightProcessed); newChildren.add(leftChild); Tree rightChild = t.getChild(t.numChildren() - rightProcessed - 1); newChildren.add(leftChild); newChildren.add(rightChild);
if (t.numChildren() == 3 && t.firstChild().label().value().equals("NN") && t.getChild(1).label().value().equals("$.")) { log.info("Correcting treebank error: giving phrase label DL to " + t); t.label().setValue("DL");
String leftLabel = tree.getChild(0).label().value(); String rightLabel = tree.getChild(1).label().value(); if (!binaryBetas.contains(label, leftLabel, rightLabel)) { double[][][] map = new double[1][1][1]; String childLabel = tree.getChild(0).label().value(); if (!unaryBetas.contains(label, childLabel)) { double[][] map = new double[1][1];
List<Tree> children = new ArrayList<>(numKids); for (int cNum = 0; cNum < numKids; cNum++) { Tree child = tree.getChild(cNum); Tree newChild = transformTree(child);
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; } }
List<Tree> children = new ArrayList<>(numKids); for (int cNum = 0; cNum < numKids; cNum++) { Tree child = tree.getChild(cNum); Tree newChild = transformTree(child); children.add(newChild);
leftString = leftString + "..."; String labelStr = '@' + topCat + "| " + leftString + '[' + t.getChild(headLoc).label().value() + ']' + rightString; // the head in brackets String word = ((HasWord) t.label()).word(); String tag = ((HasTag) t.label()).tag();