/** * Check if the Constituent is a start of a sentence * The size of the Constituent should be 1 */ public static String isSentenceStart (Constituent c){ Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); if (c.getStartSpan() == sentenceStart){ return "1"; } return "0"; }
@Override public List<Constituent> transform(Constituent input) { TreeView dependency = (TreeView) input.getTextAnnotation().getView(ViewNames.DEPENDENCY); return getGovernor(input, dependency); }
/** * Get the root constituent of the tree that covers a sentence */ public Constituent getTreeRoot(int sentenceId) { return this.getTreeRoot(this.getTextAnnotation().getSentence(sentenceId)); }
protected void addGoldView(TextAnnotation ta, List<String> labels) { TokenLabelView posView = new TokenLabelView(viewName, ta); List<Constituent> constituents = ta.getView(ViewNames.TOKENS).getConstituents(); for (int i = 0; i < constituents.size(); ++i) { Constituent constituent = (Constituent) constituents.get(i); posView.addTokenLabel(constituent.getStartSpan(), labels.get(i), 1.0D); } ta.addView(viewName, posView); } }
/** * Get the constituents which cover the input constituent {@code c}. * * @param c A constituent, not necessarily of this text annotation. * @return A list of constituents, which cover the same tokens as the input */ public List<Constituent> getConstituentsCovering(Constituent c) { return this.getConstituentsCoveringSpan(c.getStartSpan(), c.getEndSpan()); }
public void removeAllRelations() { List<Constituent> allCorefCons = this.getConstituents(); for (Constituent c : allCorefCons) { for (Relation r : c.getIncomingRelations()) this.removeRelation(r); for (Relation r : c.getOutgoingRelations()) this.removeRelation(r); c.removeAllIncomingRelatons(); c.removeAllOutgoingRelaton(); } }
/** * Makes a new constituent spanning {@code start} to {@code end} with the label * {@code constituentLabel} and score {@code constituentScore}. */ private Constituent createNewConstituent(int start, int end, String constituentLabel, double constituentScore) { return new Constituent(constituentLabel, constituentScore, this.getViewName(), this.getTextAnnotation(), start, end); }
public String getTokenAttribute(int tokenId, String key) { Constituent c = getConstituentAtToken(tokenId); if (c == null) return null; return c.getAttribute(key); }
@Override public Boolean transform(Constituent p) { boolean found = false; for (Relation r : c.getIncomingRelations()) { if (r.getSource() == p) { found = true; break; } } return found; } };
@Override public Boolean transform(Constituent c1) { boolean found = false; for (Relation r : c.getOutgoingRelations()) { if (r.getTarget() == c1) { found = true; break; } } return found; } };
@Override public int size() { initializeTokens(); return super.size(); }
@Override public String getToken(int position) { initializeTokens(); return super.getToken(position); }
@Override public View getView(String viewName) { checkViewAvailable(viewName); return super.getView(viewName); }
@Override public List<View> getTopKViews(String viewName) { checkViewAvailable(viewName); return super.getTopKViews(viewName); }
@Override public List<Constituent> transform(Constituent input) { TreeView dependency = (TreeView) input.getTextAnnotation().getView(ViewNames.DEPENDENCY); return getObject(input, dependency, "obj"); }
/** * Check if the Constituent is a start of a sentence * The size of the Constituent should be 1 */ public static String isSentenceStart (Constituent c){ Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); if (c.getStartSpan() == sentenceStart){ return "1"; } return "0"; }
public void removeAllRelations() { List<Constituent> allCorefCons = this.getConstituents(); for (Constituent c : allCorefCons) { for (Relation r : c.getIncomingRelations()) this.removeRelation(r); for (Relation r : c.getOutgoingRelations()) this.removeRelation(r); c.removeAllIncomingRelatons(); c.removeAllOutgoingRelaton(); } }
@Override public List<Constituent> transform(Constituent input) { TreeView dependency = (TreeView) input.getTextAnnotation().getView( ViewNames.DEPENDENCY_STANFORD); return getGovernor(input, dependency); }
/** * Check if the Constituent is a start of a sentence * The size of the Constituent should be 1 */ public static String isSentenceStart (Constituent c){ Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); if (c.getStartSpan() == sentenceStart){ return "1"; } return "0"; }
@Override public List<Constituent> transform(Constituent c) { TextAnnotation ta = c.getTextAnnotation(); TreeView dependency = (TreeView) ta.getView(ViewNames.DEPENDENCY); return getModifiers(c, dependency); }