/** * Set the dependency tree of hte {@code sentenceId}<sup>th</sup> sentence. Each node in the * dependency tree specifies both the token and its position <b>with respect to the start of the * sentence</b>, not the entire TextAnnotation. * <p> * <b>Note</b>: The same TreeView cannot contain both the parse tree and the dependency tree and * will throw an exception if an attempt is made to set the dependency tree of a view that has a * phrase-structure tree. */ public void setDependencyTree(int sentenceId, Tree<Pair<String, Integer>> depTree) { this.setDependencyTree(sentenceId, depTree, 0.0d); }
/** * Set the dependency tree of hte {@code sentenceId}<sup>th</sup> sentence. Each node in the * dependency tree specifies both the token and its position <b>with respect to the start of the * sentence</b>, not the entire TextAnnotation. * <p> * <b>Note</b>: The same TreeView cannot contain both the parse tree and the dependency tree and * will throw an exception if an attempt is made to set the dependency tree of a view that has a * phrase-structure tree. */ public void setDependencyTree(int sentenceId, Tree<Pair<String, Integer>> depTree) { this.setDependencyTree(sentenceId, depTree, 0.0d); }
depTreeView.setDependencyTree(i, labeledDependencyTree);
depTreeView.setDependencyTree(i, labeledDependencyTree);
public static TreeView alignForestToDependencyView(String viewName, TextAnnotation ta, Forest dep) { TreeView view = new TreeView(viewName, dep.getSource(), ta, 0.0d); for (edu.illinois.cs.cogcomp.thrift.base.Tree tree : dep.getTrees()) { int topId = tree.getTop(); List<Node> nodes = tree.getNodes(); int topTokenStart = nodes.get(topId).getSpan().getStart(); int topTokenId = ta.getTokenIdFromCharacterOffset(topTokenStart); int sentenceId = ta.getSentenceId(topTokenId); Tree<Pair<String, Integer>> dependencyTree = makeDependencyTree(ta, tree); double score = tree.getScore(); view.setDependencyTree(sentenceId, dependencyTree, score); } return view; }
public static TreeView alignForestToDependencyView(String viewName, TextAnnotation ta, Forest dep) { TreeView view = new TreeView(viewName, dep.getSource(), ta, 0.0d); for (edu.illinois.cs.cogcomp.thrift.base.Tree tree : dep.getTrees()) { int topId = tree.getTop(); List<Node> nodes = tree.getNodes(); int topTokenStart = nodes.get(topId).getSpan().getStart(); int topTokenId = ta.getTokenIdFromCharacterOffset(topTokenStart); int sentenceId = ta.getSentenceId(topTokenId); Tree<Pair<String, Integer>> dependencyTree = makeDependencyTree(ta, tree); double score = tree.getScore(); view.setDependencyTree(sentenceId, dependencyTree, score); } return view; }
public static TreeView alignForestToDependencyView(String viewName, TextAnnotation ta, Forest dep) { TreeView view = new TreeView(viewName, dep.getSource(), ta, 0.0d); for (edu.illinois.cs.cogcomp.thrift.base.Tree tree : dep.getTrees()) { int topId = tree.getTop(); List<Node> nodes = tree.getNodes(); int topTokenStart = nodes.get(topId).getSpan().getStart(); int topTokenId = ta.getTokenIdFromCharacterOffset(topTokenStart); int sentenceId = ta.getSentenceId(topTokenId); Tree<Pair<String, Integer>> dependencyTree = makeDependencyTree(ta, tree); double score = tree.getScore(); view.setDependencyTree(sentenceId, dependencyTree, score); } return view; }
Tree<Pair<String, Integer>> tree = new Tree<>(nodePair); populateChildren(depGraph, root, tree, textAnnotation, sentenceId); treeView.setDependencyTree(sentenceId, tree);
Tree<Pair<String, Integer>> tree = new Tree<>(nodePair); populateChildren(depGraph, root, tree, textAnnotation, sentenceId); treeView.setDependencyTree(sentenceId, tree);
@Override public void addView(TextAnnotation ta) throws AnnotatorException { for (String reqView : requiredViews) if (!ta.hasView(reqView)) throw new AnnotatorException("TextAnnotation must have view: " + reqView); DepInst sent = new DepInst(ta); DepStruct deptree; try { deptree = (DepStruct) model.infSolver.getBestStructure(model.wv, sent); } catch (Exception e) { throw new AnnotatorException("Sentence cannot be parsed"); } TreeView treeView = new TreeView(ViewNames.DEPENDENCY, ta); int rootPos = findRoot(deptree); // All the node positions are -1 to account for the extra <root> node added Pair<String, Integer> nodePair = new Pair<>(sent.forms[rootPos], rootPos - 1); Tree<Pair<String, Integer>> tree = new Tree<>(nodePair); populateChildren(tree, deptree, sent, rootPos); treeView.setDependencyTree(0, tree); ta.addView(ViewNames.DEPENDENCY, treeView); }
@Override public void addView(TextAnnotation ta) throws AnnotatorException { for (String reqView : requiredViews) if (!ta.hasView(reqView)) throw new AnnotatorException("TextAnnotation must have view: " + reqView); DepInst sent = new DepInst(ta); DepStruct deptree; try { deptree = (DepStruct) model.infSolver.getBestStructure(model.wv, sent); } catch (Exception e) { throw new AnnotatorException("Sentence cannot be parsed"); } TreeView treeView = new TreeView(ViewNames.DEPENDENCY, ta); int rootPos = findRoot(deptree); // All the node positions are -1 to account for the extra <root> node added Pair<String, Integer> nodePair = new Pair<>(sent.forms[rootPos], rootPos - 1); Tree<Pair<String, Integer>> tree = new Tree<>(nodePair); populateChildren(tree, deptree, sent, rootPos); treeView.setDependencyTree(0, tree); ta.addView(ViewNames.DEPENDENCY, treeView); }