@Override boolean satisfies(Tree t1, Tree t2, Tree root, final TregexMatcher matcher) { if (matcher.getHeadFinder() != null) { return matcher.getHeadFinder().determineHead(t2) == t1; } else { return hf.determineHead(t2) == t1; } }
public Tree determineHead(Tree t, Tree parent){ Tree result = determineBinaryHead(t); if (result == null && fallbackHF != null) { result = fallbackHF.determineHead(t, parent); } if (result != null) { return result; } throw new IllegalStateException("BinaryHeadFinder: unexpected tree: " + t); }
/** * Determine which daughter of the current parse tree is the head. * It assumes that the daughters already have had their heads * determined. Another method has to do the tree walking. * * @param t The parse tree to examine the daughters of * @return The parse tree that is the head. The convention has been * that this returns <code>null</code> if no head is found. * But maybe it should throw an exception? */ public Tree determineHead(Tree t) { Tree result = determineBinaryHead(t); if (result == null && fallbackHF != null) { result = fallbackHF.determineHead(t); } if (result != null) { return result; } throw new IllegalStateException("BinaryHeadFinder: unexpected tree: " + t); }
@Override public void advance() { if (next.isLeaf()) { next = null; } else { if (matcher.getHeadFinder() != null) { next = matcher.getHeadFinder().determineHead(next); } else { next = heads.hf.determineHead(next); } } } };
@Override void initialize() { if (!t.isLeaf()) { if (matcher.getHeadFinder() != null) { next = matcher.getHeadFinder().determineHead(t); } else { next = immediatelyHeads.hf.determineHead(t); } } } };
@Override public void advance() { HeadFinder headFinder = matcher.getHeadFinder(); if (headFinder == null) headFinder = hf; Tree last = next; next = matcher.getParent(next); if (next != null && headFinder.determineHead(next) != last) { next = null; } } };
/** * returns the maximal projection of <code>head</code> in * <code>root</code> given a {@link HeadFinder} */ public static Tree maximalProjection(Tree head, Tree root, HeadFinder hf) { Tree projection = head; if (projection == root) { return root; } Tree parent = projection.parent(root); while (hf.determineHead(parent) == projection) { projection = parent; if (projection == root) { return root; } parent = projection.parent(root); } return projection; }
private static <E> void dependencyObjectifyHelper(Tree t, Tree root, HeadFinder hf, Collection<E> c, DependencyTyper<E> typer) { if (t.isLeaf() || t.isPreTerminal()) { return; } Tree headDtr = hf.determineHead(t); for (Tree child : t.children()) { dependencyObjectifyHelper(child, root, hf, c, typer); if (child != headDtr) { c.add(typer.makeDependency(headDtr, child, root)); } } }
@Override void initialize() { if (t != matcher.getRoot()) { next = matcher.getParent(t); HeadFinder headFinder = matcher.getHeadFinder() == null ? hf : matcher.getHeadFinder(); if (headFinder.determineHead(next) != t) { next = null; } } } };
/** * Returns the tree leaf that is the head of the tree. * * @param hf The head-finding algorithm to use * @param parent The parent of this tree * @return The head tree leaf if any, else {@code null} */ public Tree headTerminal(HeadFinder hf, Tree parent) { if (isLeaf()) { return this; } Tree head = hf.determineHead(this, parent); if (head != null) { return head.headTerminal(hf, parent); } log.info("Head is null: " + this); return null; }
public String apply(TregexMatcher matcher) { Tree matchedTree = matcher.getMatch(); Tree head = headFinder.determineHead(matchedTree); if (!head.isPrePreTerminal()) return ""; Tree lexicalHead = head.firstChild().firstChild(); String headValue = lexicalHead.value(); if (headValue != null) { if (lowerCase) headValue = headValue.toLowerCase(); return '[' + headValue + ']'; } else { return ""; } }
/** * Returns the preterminal tree that is the head of the tree. * See {@link #isPreTerminal()} for * the definition of a preterminal node. Beware that some tree nodes may * have no preterminal head. * * @param hf The headfinding algorithm to use * @return The head preterminal tree, if any, else {@code null} * @throws IllegalArgumentException if called on a leaf node */ public Tree headPreTerminal(HeadFinder hf) { if (isPreTerminal()) { return this; } else if (isLeaf()) { throw new IllegalArgumentException("Called headPreTerminal on a leaf: " + this); } else { Tree head = hf.determineHead(this); if (head != null) { return head.headPreTerminal(hf); } log.info("Head preterminal is null: " + this); return null; } }
Label headLabel = hf.determineHead(t).label(); int leftSistersBuffer = 0; //measures the length of sisters in words when reading for (int i = 0; i < children.size();i++){
public static Tree applyToProjections(TreeVisitor v, Tree head, Tree root, HeadFinder hf) { Tree projection = head; Tree parent = projection.parent(root); if (parent == null && projection != root) { return null; } v.visitTree(projection); if (projection == root) { return root; } while (hf.determineHead(parent) == projection) { projection = parent; v.visitTree(projection); if (projection == root) { return root; } parent = projection.parent(root); } return projection; }
private Tree markHeadNodes(Tree t, Tree head) { if (t.isLeaf()) { return t; // don't worry about head-marking leaves } Label newLabel; if (t == head) { newLabel = headMark(t.label()); } else { newLabel = t.label(); } Tree newHead = hf.determineHead(t); return t.treeFactory().newTreeNode(newLabel, Arrays.asList(headMarkChildren(t, newHead))); }
@Override boolean satisfies(Tree t1, Tree t2, Tree root, final TregexMatcher matcher) { if (t2.isLeaf()) { return false; } else if (t2.isPreTerminal()) { return (t2.firstChild() == t1); } else { HeadFinder headFinder = matcher.getHeadFinder(); if (headFinder == null) headFinder = this.hf; Tree head = headFinder.determineHead(t2); if (head == t1) { return true; } else { return satisfies(t1, head, root, matcher); } } }
@Override protected void tallyInternalNode(Tree lt, double weight) { Tree[] children = lt.children(); Tree headChild = hf.determineHead(lt); if (children.length == 1) { return;
cat = cat + "^S"; if (englishTrain.splitTRJJ && cat.startsWith("JJ") && (parentStr.startsWith("PP") || parentStr.startsWith("ADJP")) && headFinder().determineHead(parent) == t) { if (englishTrain.splitJJCOMP && cat.startsWith("JJ") && (parentStr.startsWith("PP") || parentStr.startsWith("ADJP")) && headFinder().determineHead(parent) == t) { Tree[] kids = parent.children(); int i = 0;
Tree ht = headFinder.determineHead(tree);
Tree ht; do { ht = headFinder.determineHead(oldT); } while (!ht.isPreTerminal()); if (lab.startsWith("PP")) { ht = headFinder.determineHead(t); ht = headFinder.determineHead(ht); if (NPTmpPattern.matcher(lab).matches()) { Tree ht; ht = headFinder.determineHead(t); if (ht.isPreTerminal()) { Tree oldT = t; do { ht = headFinder.determineHead(oldT); oldT = ht; } while (!ht.isPreTerminal()); Tree ht; do { ht = headFinder.determineHead(oldT); Tree oldT = t; do { Tree ht = headFinder.determineHead(oldT);