public void visitTree(Tree pt) { // pt.percolateHeads(chf); //pt.pennPrint(); Tree head = pt.headTerminal(chf); //System.out.println("======== " + head.label()); } });
/** * Returns the tree leaf that is the head of the tree. * * @param hf The headfinding algorithm to use * @return The head tree leaf if any, else {@code null} */ public Tree headTerminal(HeadFinder hf) { return headTerminal(hf, null); }
@Override public List<String> makeDependency(Tree head, Tree dep, Tree root) { List<String> result = new ArrayList<>(3); Tree headTerm = head.headTerminal(hf); Tree depTerm = dep.headTerminal(hf); result.add(headTerm.value()); result.add(depTerm.value()); return result; }
private Tree safeHead(Tree top) { Tree head = top.headTerminal(headFinder); if (head != null) return head; // if no head found return the right-most leaf List<Tree> leaves = top.getLeaves(); if ( ! leaves.isEmpty()) { return leaves.get(leaves.size() - 1); } // fallback: return top return top; }
@Override public List<String> makeDependency(Tree head, Tree dep, Tree root) { List<String> result = new ArrayList<>(3); Tree headTerm = head.headTerminal(hf); Tree depTerm = dep.headTerminal(hf); boolean headLeft = root.leftCharEdge(headTerm) < root.leftCharEdge(depTerm); result.add(headTerm.value()); result.add(depTerm.value()); if(headLeft) result.add(leftHeaded); else result.add(rightHeaded); return result; }
@Override public List<String> makeDependency(Tree head, Tree dep, Tree root) { List<String> result = new ArrayList<>(6); Tree headTerm = head.headTerminal(hf); Tree depTerm = dep.headTerminal(hf); result.add(headTerm.value()); result.add(depTerm.value()); result.add(head.parent(root).value()); result.add(head.value()); result.add(dep.value()); return result; }
protected int getHeadIndex(Tree t) { // The trees passed in do not have the CoordinationTransformer // applied, but that just means the SemanticHeadFinder results are // slightly worse. Tree ht = t.headTerminal(headFinder); if(ht==null) return -1; // temporary: a key which is matched to nothing CoreLabel l = (CoreLabel) ht.label(); return l.get(CoreAnnotations.IndexAnnotation.class); } private String treeToKey(Tree t) {
protected static int getHeadIndex(Tree t, HeadFinder headFinder) { // The trees passed in do not have the CoordinationTransformer // applied, but that just means the SemanticHeadFinder results are // slightly worse. Tree ht = t.headTerminal(headFinder); if(ht==null) return -1; // temporary: a key which is matched to nothing CoreLabel l = (CoreLabel) ht.label(); return l.get(CoreAnnotations.IndexAnnotation.class); }
private void addFoundPair(Tree np1, Tree np2, Tree t, Set<Pair<Integer, Integer>> foundPairs) { Tree head1 = np1.headTerminal(headFinder); Tree head2 = np2.headTerminal(headFinder); int h1 = ((CoreMap) head1.label()).get(CoreAnnotations.IndexAnnotation.class) - 1; int h2 = ((CoreMap) head2.label()).get(CoreAnnotations.IndexAnnotation.class) - 1; Pair<Integer, Integer> p = new Pair<>(h1, h2); foundPairs.add(p); }
@Override public List<String> makeDependency(Tree head, Tree dep, Tree root) { List<String> result = new ArrayList<>(6); Tree headTerm = head.headTerminal(hf); Tree depTerm = dep.headTerminal(hf); boolean headLeft = root.leftCharEdge(headTerm) < root.leftCharEdge(depTerm); result.add(headTerm.value()); result.add(depTerm.value()); result.add(head.parent(root).value()); result.add(head.value()); result.add(dep.value()); if(headLeft) result.add(leftHeaded); else result.add(rightHeaded); return result; }
/** * 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; }
Tree hwt = node.headTerminal(hf); Tree dwt = child.headTerminal(hf); if (dwt == null) { throw new IllegalStateException("mapDependencies: HeadFinder failed!");
Tree head = top.headTerminal(headFinder);
Tree head = top.headTerminal(headFinder);
Tree t = headTree; while ((t = t.parent(m.contextParseTree)) != null) { if (t.headTerminal(headFinder) == headTree && t.value().equals("NP")) { m.mentionSubTree = t; } else if(m.mentionSubTree != null){
/** * Return a set of Label-Label dependencies, represented as * Dependency objects, for the Tree. The Labels are the ones of the leaf * nodes of the tree, without mucking with them. The head of the sentence is a * dependent of a synthetic "root" label. * * @param f Dependencies are excluded for which the Dependency is not * accepted by the Filter * @param hf The HeadFinder to use to identify the head of constituents. * The code assumes * that it can use {@code headPreTerminal(hf)} to find a * tag and word to make a CoreLabel. * @param rootName Name of the root node. * @return Set of dependencies (each a {@code Dependency} between two * {@code CoreLabel}s, which each contain a tag(), word(), * and value(), the last two of which are identical). */ public Set<Dependency<Label, Label, Object>> mapDependencies(Predicate<Dependency<Label, Label, Object>> f, HeadFinder hf, String rootName) { Set<Dependency<Label, Label, Object>> deps = mapDependencies(f, hf); if(rootName != null) { Label hl = headTerminal(hf).label(); CoreLabel rl = new CoreLabel(); rl.set(CoreAnnotations.TextAnnotation.class, rootName); rl.set(CoreAnnotations.IndexAnnotation.class, 0); deps.add(new NamedDependency(rl, hl, rootName)); } return deps; }
String head = null; if (mentionTree != null) { head = mentionTree.headTerminal(headFinder).nodeString(); } else if (mention.first.equals(mention.second)) { head = word;
Tree argRoot = tree.joinNode(leaves.get(entity.getExtentTokenStart()), leaves.get(entity.getExtentTokenEnd())); Tree headWordNode = argRoot.headTerminal(headFinder); headWordNode = argRoot.headTerminal(headFinder); headWordIndex = getIndexByObjectEquality(leaves, headWordNode); headWordNode = argTree.headTerminal(headFinder); headWordIndex = getIndexByObjectEquality(argTree.getLeaves(), headWordNode)
final Tree head = node.headTerminal(hf); final Tree headOfDaughter = daughter.headTerminal(hf);
return tf.newLeaf(new Word(t.label().value())); String word = t.headTerminal(hf).value(); if (t.isPreTerminal()) { nonTerms.incrementCount(t.label().value());