@Test public void testSetDepTreeWithDuplicateTokens() { TreeView treeView = new TreeView("test", depTA); treeView.addDependencyTree(depTreeSent0, 0, new Constituent("", "test", depTA, 5, 6)); treeView.addDependencyTree(depTreeSent1, 10, new Constituent("", "test", depTA, 15, 16)); List<Constituent> c = treeView.getConstituentsCoveringSpan(17, 18); assertEquals(1, c.size()); assertEquals("Academy", c.get(0).getSurfaceForm()); }
protected void addDependencyTree(Tree<Pair<String, Integer>> depTree, int sentStart, Constituent parent) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.error(parent.getTextAnnotation().toString()); logger.error(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentStart, relationLabel); this.addConstituent(childConstituent, true); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTree(child, sentStart, childConstituent); } }
TreeView extends View { protected void addDependencyTree(Tree<Pair<String, Integer>> depTree, int sentStart, Constituent parent) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.error(parent.getTextAnnotation().toString()); logger.error(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentStart, relationLabel); this.addConstituent(childConstituent, true); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTree(child, sentStart, childConstituent); } } }
TreeView extends View { protected void addDependencyTree(Tree<Pair<String, Integer>> depTree, int sentStart, Constituent parent) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.error(parent.getTextAnnotation().toString()); logger.error(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentStart, relationLabel); this.addConstituent(childConstituent, true); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTree(child, sentStart, childConstituent); } } TreeView(String viewName, TextAnnotation text);  TreeView(String viewName, String viewGenerator, TextAnnotation text, double score); }
TreeView extends View { protected void addDependencyTree(Tree<Pair<String, Integer>> depTree, int sentStart, Constituent parent) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.error(parent.getTextAnnotation().toString()); logger.error(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentStart, relationLabel); this.addConstituent(childConstituent, true); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTree(child, sentStart, childConstituent); } } TreeView(String viewName, TextAnnotation text);  TreeView(String viewName, String viewGenerator, TextAnnotation text, double score); static boolean isRoot(Constituent c); static boolean isLeaf(Constituent c); static Constituent getParent(Constituent constituent); Constituent getRootConstituent(int sentenceId); Constituent getRootConstituent(Sentence sentence); Tree<String> getTree(int sentenceId); Constituent getTreeRoot(int sentenceId); Constituent getTreeRoot(Sentence s); @Override String toString(); void setParseTree(int sentenceId, Tree<String> tree); void setDependencyTree(int sentenceId, Tree<Pair<String, Integer>> depTree); void setDependencyTree(int sentenceId, Tree<Pair<String, Integer>> depTree,
            double treeScore); void setScoredParseTree(int sentenceId, Tree<String> tree, Tree<Double> scores); Tree<Constituent> getConstituentTree(int sentenceId); @SuppressWarnings({"unchecked", "serial"}) Constituent getParsePhrase(Constituent c); }
TreeView extends View { protected void addDependencyTree(Tree<Pair<String, Integer>> depTree, int sentStart, Constituent parent) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.error(parent.getTextAnnotation().toString()); logger.error(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentStart, relationLabel); this.addConstituent(childConstituent, true); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTree(child, sentStart, childConstituent); } } TreeView(String viewName, TextAnnotation text);  TreeView(String viewName, String viewGenerator, TextAnnotation text, double score); static boolean isRoot(Constituent c); static boolean isLeaf(Constituent c); static Constituent getParent(Constituent constituent); Constituent getRootConstituent(int sentenceId); Constituent getRootConstituent(Sentence sentence); Tree<String> getTree(int sentenceId); Constituent getTreeRoot(int sentenceId); Constituent getTreeRoot(Sentence s); @Override String toString(); void setParseTree(int sentenceId, Tree<String> tree); void setDependencyTree(int sentenceId, Tree<Pair<String, Integer>> depTree); void setDependencyTree(int sentenceId, Tree<Pair<String, Integer>> depTree,
            double treeScore); void setScoredParseTree(int sentenceId, Tree<String> tree, Tree<Double> scores); Tree<Constituent> getConstituentTree(int sentenceId); @SuppressWarnings({"unchecked", "serial"}) Constituent getParsePhrase(Constituent c);  }