/** * Get the parse tree of the <code>sentenceId</code>th sentence from the text annotation. This * code assumes that the view called {@code parseViewName} exists in the text annotation. * * @param parseViewName The name of the parse view * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ public static Tree<String> getParseTree(String parseViewName, TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); }
/** * Get the parse tree of the <code>sentenceId</code>th sentence from the text annotation. This * code assumes that the view called {@code parseViewName} exists in the text annotation. * * @param parseViewName The name of the parse view * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ public static Tree<String> getParseTree(String parseViewName, TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); }
/** * Get the parse tree of the <code>sentenceId</code>th sentence from the text annotation. This * code assumes that the view called {@code parseViewName} exists in the text annotation. * * @param parseViewName The name of the parse view * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ public static Tree<String> getParseTree(String parseViewName, TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); }
/** * Get the Charniak parse tree of the <code>sentenceId</code>th sentence from the text * annotation. This code assumes that the view called ViewNames.PARSE_CHARNIAK exists in the * text annotation. * * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ @Deprecated public static Tree<String> getParseTree(TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(ViewNames.PARSE_CHARNIAK))).getTree(sentenceId); }
/** * Get the parse tree of the <code>sentenceId</code>th sentence from the text annotation. This * code assumes that the view called {@code parseViewName} exists in the text annotation. * * @param parseViewName The name of the parse view * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ public static Tree<String> getParseTree(String parseViewName, TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); }
/** * Get the Charniak parse tree of the <code>sentenceId</code>th sentence from the text * annotation. This code assumes that the view called ViewNames.PARSE_CHARNIAK exists in the * text annotation. * * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ @Deprecated public static Tree<String> getParseTree(TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(ViewNames.PARSE_CHARNIAK))).getTree(sentenceId); }
/** * Get the Charniak parse tree of the <code>sentenceId</code>th sentence from the text * annotation. This code assumes that the view called ViewNames.PARSE_CHARNIAK exists in the * text annotation. * * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ @Deprecated public static Tree<String> getParseTree(TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(ViewNames.PARSE_CHARNIAK))).getTree(sentenceId); }
/** * Get the Charniak parse tree of the <code>sentenceId</code>th sentence from the text * annotation. This code assumes that the view called ViewNames.PARSE_CHARNIAK exists in the * text annotation. * * @param ta The text annotation object * @param sentenceId The sentence whose parse tree is required * @return The parse tree of the {@code sentenceId}th sentence */ @Deprecated public static Tree<String> getParseTree(TextAnnotation ta, int sentenceId) { return ((TreeView) (ta.getView(ViewNames.PARSE_CHARNIAK))).getTree(sentenceId); }
@Override public String toString() { if (trees == null) makeTrees(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.getTextAnnotation().getNumberOfSentences(); i++) { if (this.trees.get(i) != null) sb.append(this.getTree(i).toString()).append("\n"); } return sb.toString(); }
@Override public String toString() { if (trees == null) makeTrees(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.getTextAnnotation().getNumberOfSentences(); i++) { if (this.trees.get(i) != null) sb.append(this.getTree(i).toString()).append("\n"); } return sb.toString(); }
/** * Get the constituents comprising the sentence at the provided index organized into a * tree. * @param sentenceId the id of the sentence. * @return a tree comprised of constituents. */ public Tree<Constituent> getConstituentTree(int sentenceId) { if (sentenceId >= this.trees.size()) return null; // first get the parse tree containing for each label the token offsets as a pair. Tree<String> sentence = getTree(sentenceId); // now get the span labeled tree Tree<Pair<String, IntPair>> labeledSpans = ParseUtils.getSpanLabeledTree(sentence); // the offset are relative to the beginning of the tree adjust to the start of text. // the root constituent will contain the starting location. Constituent c = this.getRootConstituent(sentenceId); int offset = c.getStartSpan(); // now adjust each of the tree pairs to the constituents offset. adjustTree(labeledSpans, offset); return getConstituentSubTree(labeledSpans); }
/** * Get the constituents comprising the sentence at the provided index organized into a * tree. * @param sentenceId the id of the sentence. * @return a tree comprised of constituents. */ public Tree<Constituent> getConstituentTree(int sentenceId) { if (sentenceId >= this.trees.size()) return null; // first get the parse tree containing for each label the token offsets as a pair. Tree<String> sentence = getTree(sentenceId); // now get the span labeled tree Tree<Pair<String, IntPair>> labeledSpans = ParseUtils.getSpanLabeledTree(sentence); // the offset are relative to the beginning of the tree adjust to the start of text. // the root constituent will contain the starting location. Constituent c = this.getRootConstituent(sentenceId); int offset = c.getStartSpan(); // now adjust each of the tree pairs to the constituents offset. adjustTree(labeledSpans, offset); return getConstituentSubTree(labeledSpans); }
if (parseTreeView.getTree(i) != null) {
if (parseTreeView.getTree(i) != null) {
@Override public void addView(TextAnnotation ta) { TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0); int tokenId = 0; for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) { Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); parseTree = ParseUtils.snipNullNodes(parseTree); parseTree = ParseUtils.stripFunctionTags(parseTree); if (parseTree.getYield().size() != ta.getSentence(sentenceId).size()) { Sentence s = ta.getSentence(sentenceId); System.err.println(":"+s+":"); List<Tree<String>> tree = parseTree.getYield(); System.err.println("-"+tree+"-"); throw new IllegalStateException("Parse tree size != ta.size()"); } for (Tree<String> y : parseTree.getYield()) { posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0); } } ta.addView(getViewName(), posView); // return posView; }
@Override public void addView(TextAnnotation ta) { TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0); int tokenId = 0; for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) { Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); parseTree = ParseUtils.snipNullNodes(parseTree); parseTree = ParseUtils.stripFunctionTags(parseTree); if (parseTree.getYield().size() != ta.getSentence(sentenceId).size()) { Sentence s = ta.getSentence(sentenceId); System.err.println(":"+s+":"); List<Tree<String>> tree = parseTree.getYield(); System.err.println("-"+tree+"-"); throw new IllegalStateException("Parse tree size != ta.size()"); } for (Tree<String> y : parseTree.getYield()) { posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0); } } ta.addView(getViewName(), posView); // return posView; }
@Override public void addView(TextAnnotation ta) { TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0); int tokenId = 0; for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) { Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); parseTree = ParseUtils.snipNullNodes(parseTree); parseTree = ParseUtils.stripFunctionTags(parseTree); if (parseTree.getYield().size() != ta.getSentence(sentenceId).size()) throw new IllegalStateException("Parse tree size != ta.size()"); for (Tree<String> y : parseTree.getYield()) { posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0); } } ta.addView(getViewName(), posView); }
@Override public void addView(TextAnnotation ta) { TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0); int tokenId = 0; for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) { Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId); parseTree = ParseUtils.snipNullNodes(parseTree); parseTree = ParseUtils.stripFunctionTags(parseTree); if (parseTree.getYield().size() != ta.getSentence(sentenceId).size()) throw new IllegalStateException("Parse tree size != ta.size()"); for (Tree<String> y : parseTree.getYield()) { posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0); } } ta.addView(getViewName(), posView); }