private void addParseView(List<String> parses, TextAnnotation ta) { // PARSE View TreeView parseView = new TreeView(ViewNames.PARSE_CHARNIAK, "GoldStandard", ta, 1.0); for (int j = 0; j < parses.size(); j++) { Tree<String> parseTree = TreeParserFactory.getStringTreeParser().parse(parses.get(j)); parseView.setParseTree(j, parseTree); } ta.addView(ViewNames.PARSE_CHARNIAK, parseView); }
TreeView depTreeView = new TreeView(dependencyViewName, viewGenerator, input, 1d); if (parseTreeView.getTree(i) != null) { Constituent parseTreeRoot = parseTreeView.getRootConstituent(i); Tree<Pair<String, Integer>> labeledDependencyTree = depParser.getLabeledDependencyTree(parseTreeRoot); depTreeView.setDependencyTree(i, labeledDependencyTree); int nConstituents = depTreeView.getNumberOfConstituents(); if (nConstituents != size) { for (Constituent c : depTreeView.getConstituents()) { set.remove(c.getStartSpan());
@Override public List<Constituent> transform(Constituent c) { TextAnnotation ta = c.getTextAnnotation(); TreeView tree = (TreeView) ta.getView(ViewNames.PARSE_CHARNIAK); try { Constituent phrase = tree.getParsePhrase(c); int head = CollinsHeadFinder.getInstance().getHeadWordPosition(phrase); Constituent c1 = new Constituent("", "", ta, head, head + 1); return Collections.singletonList(addPointerToSource(c, c1)); } catch (Exception e) { throw new RuntimeException(e); } }
public Constituent getCommaConstituentFromTree(TreeView parseView) { Constituent comma = null; for (Constituent c : parseView.getConstituents()) { if (c.isConsituentInRange(commaPosition, commaPosition + 1)) { try { comma = parseView.getParsePhrase(c); } catch (Exception e) { e.printStackTrace(); System.exit(1); } break; } } return comma; }
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 alignForestToParseTreeView(String viewName, TextAnnotation ta, Forest parseForest) { final List<edu.illinois.cs.cogcomp.thrift.base.Tree> trees = parseForest.getTrees(); final String parseSource = parseForest.getSource(); final TreeView parseView = new TreeView(viewName, parseSource, ta, 0d); int sentenceId = 0; for (final edu.illinois.cs.cogcomp.thrift.base.Tree tree : trees) { Tree<String> parseTree; if (tree.isSetScore()) { final Pair<Tree<String>, Tree<Double>> treeInfo = getParseTreeScores(parseForest.getRawText(), tree); parseTree = treeInfo.getFirst(); final Tree<Double> score = treeInfo.getSecond(); parseView.setScoredParseTree(sentenceId, parseTree, score); } else { parseTree = getParseTree(ta.getText(), tree); parseView.setParseTree(sentenceId, parseTree); } sentenceId++; } return parseView; }
predicate = parse.getParsePhrase(pred); arg = parse.getParsePhrase(c); } catch (Exception e) { throw new EdisonException(e); Constituent vp = TreeView.getParent(predicate); if (!TreeView.isRoot(vp)) { Constituent vpParent = TreeView.getParent(vp);
public Constituent getSiblingToRight(int distance, Constituent c, TreeView parseView) { Constituent rightSibling = c; IQueryable<Constituent> siblings = parseView.where(Queries.isSiblingOf(c)); while (distance-- > 0) { Iterator<Constituent> rightSiblingIt = siblings.where(Queries.adjacentToAfter(rightSibling)).iterator(); if (rightSiblingIt.hasNext()) rightSibling = rightSiblingIt.next(); else return null; } return rightSibling; }
/** * 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); }
Constituent arg = pseudoParseView.getParsePhrase(c); Constituent pred = pseudoParseView.getParsePhrase(p); Constituent argParent = TreeView.getParent(arg); Constituent predParent = TreeView.getParent(pred); if (argParent == ca && predParent == ca) clauseRelativePosition = "S";
@Override public List<Constituent> transform(Constituent c) { TextAnnotation ta = c.getTextAnnotation(); int tokenPosition = c.getStartSpan(); TreeView dependency = (TreeView) ta.getView(ViewNames.DEPENDENCY); Constituent prepositionDepConstituent = dependency.getConstituentsCoveringToken(tokenPosition).get(0); List<Relation> incomingRelations = prepositionDepConstituent.getIncomingRelations(); List<Constituent> list = new ArrayList<>(); if (incomingRelations != null && incomingRelations.size() > 0) { Constituent parent = incomingRelations.get(0).getSource(); for (Relation out : parent.getOutgoingRelations()) { if (out == incomingRelations.get(0)) continue; String label = out.getRelationName(); if (label.contains("prep")) { Constituent ppNode = out.getTarget(); list.add(addPointerToSource(c, ppNode)); // get the first child of the pp and add this List<Relation> ppOut = ppNode.getOutgoingRelations(); if (ppOut != null && ppOut.size() != 0) { Constituent child = ppOut.get(0).getTarget(); list.add(addPointerToSource(c, child)); } } } } return list; }
(List<Constituent>) this.where(predicate).orderBy( TextAnnotationUtilities.constituentLengthComparator); List<Constituent> spans = findSmallestSpan(candidates); phrase = getParsePhraseSingeWordHack(c, phrase);
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; }
final String parseSource = parseForest.getSource(); final TreeView parseView = new TreeView(viewName, parseSource, ta, 0d); parseView.setScoredParseTree(sentenceId, parseTree, score); parseView.setParseTree(sentenceId, parseTree);
public Constituent getSiblingToLeft(int distance, Constituent c, TreeView parseView) { Constituent leftSibling = c; IQueryable<Constituent> siblings = parseView.where(Queries.isSiblingOf(c)); while (distance-- > 0) { Iterator<Constituent> leftSiblingIt = siblings.where(Queries.adjacentToBefore(leftSibling)).iterator(); if (leftSiblingIt.hasNext()) leftSibling = leftSiblingIt.next(); else return null; } return leftSibling; }
/** * 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); }
public Constituent getCommaConstituentFromTree(TreeView parseView) { Constituent comma = null; for (Constituent c : parseView.getConstituents()) { if (c.isConsituentInRange(commaPosition, commaPosition + 1)) { try { comma = parseView.getParsePhrase(c); } catch (Exception e) { e.printStackTrace(); System.exit(1); } break; } } return comma; }
@Override public List<Constituent> transform(Constituent c) { TextAnnotation ta = c.getTextAnnotation(); int tokenPosition = c.getStartSpan(); TreeView dependency = (TreeView) ta.getView(ViewNames.DEPENDENCY); Constituent prepositionDepConstituent = dependency.getConstituentsCoveringToken(tokenPosition).get(0); List<Relation> incomingRelations = prepositionDepConstituent.getIncomingRelations(); List<Constituent> list = new ArrayList<>(); if (incomingRelations != null && incomingRelations.size() > 0) { Constituent parent = incomingRelations.get(0).getSource(); for (Relation out : parent.getOutgoingRelations()) { if (out == incomingRelations.get(0)) continue; String label = out.getRelationName(); if (label.contains("prep")) { Constituent ppNode = out.getTarget(); list.add(addPointerToSource(c, ppNode)); // get the first child of the pp and add this List<Relation> ppOut = ppNode.getOutgoingRelations(); if (ppOut != null && ppOut.size() != 0) { Constituent child = ppOut.get(0).getTarget(); list.add(addPointerToSource(c, child)); } } } } return list; }