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; }
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; }
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; }
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; }
/** * Get the root constituent of the tree that covers a sentence */ public Constituent getTreeRoot(Sentence s) { Constituent root = null; Constituent sentenceConstituent = s.getSentenceConstituent(); IQueryable<Constituent> queryable = this.where(Queries.containedInConstituent(sentenceConstituent)); for (Constituent c : queryable) { if (c.getIncomingRelations().size() == 0) { root = c; break; } } return root; }
/** * Get the root constituent of the tree that covers a sentence */ public Constituent getTreeRoot(Sentence s) { Constituent root = null; Constituent sentenceConstituent = s.getSentenceConstituent(); IQueryable<Constituent> queryable = this.where(Queries.containedInConstituent(sentenceConstituent)); for (Constituent c : queryable) { if (c.getIncomingRelations().size() == 0) { root = c; break; } } return root; }
@SuppressWarnings({"unchecked", "serial"}) private Constituent getParsePhraseSingeWordHack(Constituent c, Constituent phrase) { List<Constituent> candidates; if (phrase == null || !Queries.containsConstituent(phrase).transform(c)) { // a hack that deals with cases when a single word constituent is // not found in the parse tree because it is not a phrase. if (c.getStartSpan() == c.getEndSpan() - 1) { candidates = (List<Constituent>) this.where(Queries.sameSpanAsConstituent(c).and( new Predicate<Constituent>() { @Override public Boolean transform(Constituent input) { return input.getOutgoingRelations().size() > 0; } })); phrase = candidates.get(0); } } return phrase; }
@SuppressWarnings({"unchecked", "serial"}) private Constituent getParsePhraseSingeWordHack(Constituent c, Constituent phrase) { List<Constituent> candidates; if (phrase == null || !Queries.containsConstituent(phrase).transform(c)) { // a hack that deals with cases when a single word constituent is // not found in the parse tree because it is not a phrase. if (c.getStartSpan() == c.getEndSpan() - 1) { candidates = (List<Constituent>) this.where(Queries.sameSpanAsConstituent(c).and( new Predicate<Constituent>() { @Override public Boolean transform(Constituent input) { return input.getOutgoingRelations().size() > 0; } })); phrase = candidates.get(0); } } return phrase; }
(List<Constituent>) this.where(predicate).orderBy( TextAnnotationUtilities.constituentLengthComparator);
(List<Constituent>) this.where(predicate).orderBy( TextAnnotationUtilities.constituentLengthComparator);
@Override public Boolean transform(Pair<Constituent, SpanLabelView> input) { if (!types.contains(input.getFirst().getLabel())) return true; Constituent c = input.getFirst(); TextAnnotation ta = c.getTextAnnotation(); TreeView parse; if (ta.hasView(ViewNames.PARSE_CHARNIAK)) parse = (TreeView) ta.getView(ViewNames.PARSE_CHARNIAK); else if (ta.hasView(ViewNames.PARSE_BERKELEY)) parse = (TreeView) ta.getView(ViewNames.PARSE_BERKELEY); else if (ta.hasView(ViewNames.PARSE_STANFORD)) parse = (TreeView) ta.getView(ViewNames.PARSE_STANFORD); else return true; boolean foundNP = false; for (Constituent parseConstituent : parse.where(Queries .sameSpanAsConstituent(c))) { if (ParseTreeProperties.isNonTerminalNoun(parseConstituent.getLabel())) { foundNP = true; break; } } // do not include return foundNP; } };
@Override public Boolean transform(Pair<Constituent, SpanLabelView> input) { if (!types.contains(input.getFirst().getLabel())) return true; Constituent c = input.getFirst(); TextAnnotation ta = c.getTextAnnotation(); TreeView parse; if (ta.hasView(ViewNames.PARSE_CHARNIAK)) parse = (TreeView) ta.getView(ViewNames.PARSE_CHARNIAK); else if (ta.hasView(ViewNames.PARSE_BERKELEY)) parse = (TreeView) ta.getView(ViewNames.PARSE_BERKELEY); else if (ta.hasView(ViewNames.PARSE_STANFORD)) parse = (TreeView) ta.getView(ViewNames.PARSE_STANFORD); else return true; boolean foundNP = false; for (Constituent parseConstituent : parse.where(Queries .sameSpanAsConstituent(c))) { if (ParseTreeProperties.isNonTerminalNoun(parseConstituent.getLabel())) { foundNP = true; break; } } // do not include return foundNP; } };