/** * Return the ancestor tree node {@code height} nodes up from the current node. * * @param height How many nodes up to go. A parameter of 0 means return * this node, 1 means to return the parent node and so on. * @param root The root node that this Tree is embedded under * @return The ancestor at height {@code height}. It returns null * if it does not exist or the tree implementation does not keep track * of parents */ public Tree ancestor(int height, Tree root) { if (height < 0) { throw new IllegalArgumentException("ancestor: height cannot be negative"); } if (height == 0) { return this; } Tree par = parent(root); if (par == null) { return null; } return par.ancestor(height - 1, root); }
/** Divides a sentence into clauses and sort the antecedents for pronoun matching */ private static List<Mention> sortMentionsForPronoun(List<Mention> l, Mention m1) { List<Mention> sorted = new ArrayList<>(); Tree tree = m1.contextParseTree; Tree current = m1.mentionSubTree; if(tree==null || current==null) return l; while(true){ current = current.ancestor(1, tree); if(current.label().value().startsWith("S")){ for(Mention m : l){ if(!sorted.contains(m) && current.dominates(m.mentionSubTree)) sorted.add(m); } } if(current.ancestor(1, tree)==null) break; } if(l.size()!=sorted.size()) { sorted=l; } else if(!l.equals(sorted)){ for(int i=0; i<l.size(); i++){ Mention ml = l.get(i); Mention msorted = sorted.get(i); } } else { } return sorted; }
/** Divides a sentence into clauses and sort the antecedents for pronoun matching */ private static List<Mention> sortMentionsByClause(List<Mention> l, Mention m1) { List<Mention> sorted = new ArrayList<>(); Tree tree = m1.contextParseTree; Tree current = m1.mentionSubTree; if(tree==null || current==null) return l; while(true){ current = current.ancestor(1, tree); String curLabel = current.label().value(); if("TOP".equals(curLabel) || curLabel.startsWith("S") || curLabel.equals("NP")){ // if(current.label().value().startsWith("S")){ for(Mention m : l){ if(!sorted.contains(m) && current.dominates(m.mentionSubTree)) sorted.add(m); } } if(current.ancestor(1, tree)==null) break; } return sorted; } }
private int headEmbeddingLevel(Tree tree, int headIndex) { int embeddingLevel = 0; try { Tree subtree = tree.getLeaves().get(headIndex); while (subtree != null) { String label = ((CoreLabel) subtree.label()).get(CoreAnnotations.ValueAnnotation.class); subtree = subtree.ancestor(1, tree); if (label.equals("NP")) { embeddingLevel++; } } } catch (Exception e) { return -1; } return embeddingLevel; }
public String lowestNPIncludesHead (){ String ret = ""; Tree head = this.contextParseTree.getLeaves().get(this.headIndex); Tree lowestNP = head; String s; while(true) { if(lowestNP==null) return ret; s = ((CoreLabel) lowestNP.label()).get(CoreAnnotations.ValueAnnotation.class); if(s.equals("NP") || s.equals("ROOT")) break; lowestNP = lowestNP.ancestor(1, this.contextParseTree); } if (s.equals("ROOT")) lowestNP = head; for (Tree t : lowestNP.getLeaves()){ if (!ret.equals("")) ret = ret + " "; ret = ret + ((CoreLabel) t.label()).get(CoreAnnotations.TextAnnotation.class); } if(!this.spanToString().contains(ret)) return this.sentenceWords.get(this.headIndex).get(CoreAnnotations.TextAnnotation.class); return ret; }
public String lowestNPIncludesHead (){ String ret = ""; Tree head = this.contextParseTree.getLeaves().get(this.headIndex); Tree lowestNP = head; String s; while(true) { if(lowestNP==null) return ret; s = ((CoreLabel) lowestNP.label()).get(CoreAnnotations.ValueAnnotation.class); if(s.equals("NP") || s.equals("ROOT")) break; lowestNP = lowestNP.ancestor(1, this.contextParseTree); } if (s.equals("ROOT")) lowestNP = head; for (Tree t : lowestNP.getLeaves()){ if (!ret.equals("")) ret = ret + " "; ret = ret + ((CoreLabel) t.label()).get(CoreAnnotations.TextAnnotation.class); } if(!this.spanToString().contains(ret)) return this.sentenceWords.get(this.headIndex).get(CoreAnnotations.TextAnnotation.class); return ret; }
Tree grandma = t.ancestor(1, tree); String grandmaValue = ((CoreLabel) grandma.label()).value();
current = current.ancestor(1, tree); if(current.label().value().startsWith("S")) { clauseCount++; if(current.label().value().equals("ROOT") || current.ancestor(1, tree)==null) break; sb = new StringBuilder(); Tree mTree = m.contextParseTree; Tree mHead = mTree.getLeaves().get(m.headIndex).ancestor(1, mTree); for (Tree node : mTree.pathNodeToNode(mHead, mTree)) { sb.append(node.value()).append("-"); Tree aHead = aTree.getLeaves().get(candidate.headIndex).ancestor(1, aTree); for(Tree node : aTree.pathNodeToNode(aHead, aTree)) { sb.append(node.value()).append("-");
String syntaxPath = ""; Tree tree = m.contextParseTree; Tree head = tree.getLeaves().get(m.headIndex).ancestor(1, tree); depth = 0; for (Tree node : tree.pathNodeToNode(head, tree)) {
/** * Return the ancestor tree node {@code height} nodes up from the current node. * * @param height How many nodes up to go. A parameter of 0 means return * this node, 1 means to return the parent node and so on. * @param root The root node that this Tree is embedded under * @return The ancestor at height {@code height}. It returns null * if it does not exist or the tree implementation does not keep track * of parents */ public Tree ancestor(int height, Tree root) { if (height < 0) { throw new IllegalArgumentException("ancestor: height cannot be negative"); } if (height == 0) { return this; } Tree par = parent(root); if (par == null) { return null; } return par.ancestor(height - 1, root); }
/** * Return the ancestor tree node {@code height} nodes up from the current node. * * @param height How many nodes up to go. A parameter of 0 means return * this node, 1 means to return the parent node and so on. * @param root The root node that this Tree is embedded under * @return The ancestor at height {@code height}. It returns null * if it does not exist or the tree implementation does not keep track * of parents */ public Tree ancestor(int height, Tree root) { if (height < 0) { throw new IllegalArgumentException("ancestor: height cannot be negative"); } if (height == 0) { return this; } Tree par = parent(root); if (par == null) { return null; } return par.ancestor(height - 1, root); }
/** Divides a sentence into clauses and sort the antecedents for pronoun matching */ private static List<Mention> sortMentionsByClause(List<Mention> l, Mention m1) { List<Mention> sorted = new ArrayList<>(); Tree tree = m1.contextParseTree; Tree current = m1.mentionSubTree; if(tree==null || current==null) return l; while(true){ current = current.ancestor(1, tree); String curLabel = current.label().value(); if("TOP".equals(curLabel) || curLabel.startsWith("S") || curLabel.equals("NP")){ // if(current.label().value().startsWith("S")){ for(Mention m : l){ if(!sorted.contains(m) && current.dominates(m.mentionSubTree)) sorted.add(m); } } if(current.ancestor(1, tree)==null) break; } return sorted; } }
/** * Return the ancestor tree node <code>height</code> nodes up from the current node. * * @param height How many nodes up to go. A parameter of 0 means return * this node, 1 means to return the parent node and so on. * @param root The root node that this Tree is embedded under * @return The ancestor at height <code>height</code>. It returns null * if it does not exist or the tree implementation does not keep track * of parents */ public Tree ancestor(int height, Tree root) { if (height < 0) { throw new IllegalArgumentException("ancestor: height cannot be negative"); } if (height == 0) { return this; } Tree par = parent(root); if (par == null) { return null; } return par.ancestor(height - 1, root); }
/** Divides a sentence into clauses and sort the antecedents for pronoun matching */ private static List<Mention> sortMentionsForPronoun(List<Mention> l, Mention m1) { List<Mention> sorted = new ArrayList<>(); Tree tree = m1.contextParseTree; Tree current = m1.mentionSubTree; if(tree==null || current==null) return l; while(true){ current = current.ancestor(1, tree); if(current.label().value().startsWith("S")){ for(Mention m : l){ if(!sorted.contains(m) && current.dominates(m.mentionSubTree)) sorted.add(m); } } if(current.ancestor(1, tree)==null) break; } if(l.size()!=sorted.size()) { sorted=l; } else if(!l.equals(sorted)){ for(int i=0; i<l.size(); i++){ Mention ml = l.get(i); Mention msorted = sorted.get(i); } } else { } return sorted; }
private int headEmbeddingLevel(Tree tree, int headIndex) { int embeddingLevel = 0; try { Tree subtree = tree.getLeaves().get(headIndex); while (subtree != null) { String label = ((CoreLabel) subtree.label()).get(CoreAnnotations.ValueAnnotation.class); subtree = subtree.ancestor(1, tree); if (label.equals("NP")) { embeddingLevel++; } } } catch (Exception e) { return -1; } return embeddingLevel; }
public String lowestNPIncludesHead (){ String ret = ""; Tree head = this.contextParseTree.getLeaves().get(this.headIndex); Tree lowestNP = head; String s; while(true) { if(lowestNP==null) return ret; s = ((CoreLabel) lowestNP.label()).get(CoreAnnotations.ValueAnnotation.class); if(s.equals("NP") || s.equals("ROOT")) break; lowestNP = lowestNP.ancestor(1, this.contextParseTree); } if (s.equals("ROOT")) lowestNP = head; for (Tree t : lowestNP.getLeaves()){ if (!ret.equals("")) ret = ret + " "; ret = ret + ((CoreLabel) t.label()).get(CoreAnnotations.TextAnnotation.class); } if(!this.spanToString().contains(ret)) return this.sentenceWords.get(this.headIndex).get(CoreAnnotations.TextAnnotation.class); return ret; }
public String lowestNPIncludesHead (){ String ret = ""; Tree head = this.contextParseTree.getLeaves().get(this.headIndex); Tree lowestNP = head; String s; while(true) { if(lowestNP==null) return ret; s = ((CoreLabel) lowestNP.label()).get(ValueAnnotation.class); if(s.equals("NP") || s.equals("ROOT")) break; lowestNP = lowestNP.ancestor(1, this.contextParseTree); } if (s.equals("ROOT")) lowestNP = head; for (Tree t : lowestNP.getLeaves()){ if (!ret.equals("")) ret = ret + " "; ret = ret + ((CoreLabel) t.label()).get(TextAnnotation.class); } if(!this.spanToString().contains(ret)) return this.sentenceWords.get(this.headIndex).get(TextAnnotation.class); return ret; }
public String lowestNPIncludesHead (){ String ret = ""; Tree head = this.contextParseTree.getLeaves().get(this.headIndex); Tree lowestNP = head; String s; while(true) { if(lowestNP==null) return ret; s = ((CoreLabel) lowestNP.label()).get(CoreAnnotations.ValueAnnotation.class); if(s.equals("NP") || s.equals("ROOT")) break; lowestNP = lowestNP.ancestor(1, this.contextParseTree); } if (s.equals("ROOT")) lowestNP = head; for (Tree t : lowestNP.getLeaves()){ if (!ret.equals("")) ret = ret + " "; ret = ret + ((CoreLabel) t.label()).get(CoreAnnotations.TextAnnotation.class); } if(!this.spanToString().contains(ret)) return this.sentenceWords.get(this.headIndex).get(CoreAnnotations.TextAnnotation.class); return ret; }
public String lowestNPIncludesHead (){ String ret = ""; Tree head = this.contextParseTree.getLeaves().get(this.headIndex); Tree lowestNP = head; String s; while(true) { if(lowestNP==null) return ret; s = ((CoreLabel) lowestNP.label()).get(CoreAnnotations.ValueAnnotation.class); if(s.equals("NP") || s.equals("ROOT")) break; lowestNP = lowestNP.ancestor(1, this.contextParseTree); } if (s.equals("ROOT")) lowestNP = head; for (Tree t : lowestNP.getLeaves()){ if (!ret.equals("")) ret = ret + " "; ret = ret + ((CoreLabel) t.label()).get(CoreAnnotations.TextAnnotation.class); } if(!this.spanToString().contains(ret)) return this.sentenceWords.get(this.headIndex).get(CoreAnnotations.TextAnnotation.class); return ret; }