public String getPOSToLeft(int distance) { TokenLabelView posView; if (GOLD) posView = (TokenLabelView) s.goldTa.getView(ViewNames.POS); else posView = (TokenLabelView) s.ta.getView(ViewNames.POS); String pos = posView.getLabel(commaPosition - distance); if (pos.equals("DT") && distance == 1 && getWordToRight(distance).equalsIgnoreCase("the")) return "DT-the"; else return pos; }
public Constituent getChunkToLeftOfComma(int distance) { // We don't have gold SHALLOW_PARSE SpanLabelView chunkView = (SpanLabelView) s.ta.getView(ViewNames.SHALLOW_PARSE); List<Constituent> chunksToLeft = chunkView.getSpanLabels(0, commaPosition + 1); Collections.sort(chunksToLeft, TextAnnotationUtilities.constituentStartComparator); Constituent chunk; if (distance <= 0 || distance > chunksToLeft.size()) chunk = null; else chunk = chunksToLeft.get(distance - 1); return chunk; }
public Constituent getPhraseToLeftOfComma(int distance) { TreeView parseView; if (GOLD) parseView = (TreeView) s.goldTa.getView(ViewNames.PARSE_GOLD); else parseView = (TreeView) s.ta.getView(CONSTITUENT_PARSER); Constituent comma = getCommaConstituentFromTree(parseView); return getSiblingToLeft(distance, comma, parseView); }
public static List<String> getPosConjLemma(TextAnnotation s) { List<Constituent> lemma = s.getView(ViewNames.LEMMA).getConstituents(); List<Constituent> pos = s.getView(ViewNames.LEMMA).getConstituents(); ArrayList output = new ArrayList(); for(int i = 0; i < lemma.size(); i++) { output.add(lemma.get(i) + "-" + pos.get(i)); } return output; }
@Override public List<Constituent> transform(Constituent c) { TextAnnotation ta = c.getTextAnnotation(); TreeView dependency = (TreeView) ta.getView(ViewNames.DEPENDENCY); return Collections.singletonList(getHead(c, dependency)); }
@Override public List<Constituent> transform(Constituent c) { TextAnnotation ta = c.getTextAnnotation(); TreeView dependency = (TreeView) ta.getView(ViewNames.DEPENDENCY_STANFORD); return Collections.singletonList(getHead(c, dependency)); }
@Override public List<Constituent> transform(Constituent input) { TreeView dependency = (TreeView) input.getTextAnnotation().getView(ViewNames.DEPENDENCY); return getGovernor(input, dependency); }
@Override public List<Constituent> transform(Constituent input) { TreeView dependency = (TreeView) input.getTextAnnotation().getView(ViewNames.DEPENDENCY); return getObject(input, dependency, "obj"); }
/** * Add the view named by getViewName() to the TextAnnotation argument, and return the View * * @param ta * @return the newly created View. * @throws AnnotatorException */ public final View getView(TextAnnotation ta, ResourceManager runtimeAttributes) throws AnnotatorException { lazyAddView(ta, runtimeAttributes); return ta.getView(viewName); }
@Override public List<Constituent> transform(Constituent c) { TextAnnotation ta = c.getTextAnnotation(); TreeView dependency = (TreeView) ta.getView(ViewNames.DEPENDENCY); return Collections.singletonList(getHead(c, dependency)); }
@Override public List<Constituent> transform(Constituent input) { TreeView dependency = (TreeView) input.getTextAnnotation().getView( ViewNames.DEPENDENCY_STANFORD); return getGovernor(input, dependency); }
public Constituent getPhraseToRightOfParent(int distance) { TreeView parseView; if (GOLD) parseView = (TreeView) s.goldTa.getView(ViewNames.PARSE_GOLD); else parseView = (TreeView) s.ta.getView(CONSTITUENT_PARSER); Constituent comma = getCommaConstituentFromTree(parseView); Constituent parent = TreeView.getParent(comma); return getSiblingToRight(distance, parent, parseView); }
public static String printTextAnnotation(TextAnnotation ta ) throws IOException { StringBuilder bldr = new StringBuilder(); bldr.append( "TextAnnotation for text: " ); bldr.append( ta.getText() ); for ( String vName: ta.getAvailableViews() ) { bldr.append(printView( ta.getView( vName ))); } return bldr.toString(); }
public static String[] getStringPatternsDiscrete(TextAnnotation s) { List<Constituent> posCons = s.getView(ViewNames.POS).getConstituents(); List<Constituent> lemmaCons = s.getView(ViewNames.LEMMA).getConstituents(); boolean what = lemmaCons.get(0).getSurfaceForm().toLowerCase().contains("what"); String whatNounNoun = ""; if(what && posCons.size() >= 2) { whatNounNoun = lemmaCons.get(1).getLabel() + "-" + lemmaCons.get(2).getLabel(); } return new String[]{ whatNounNoun }; }
public static boolean[] getStringPatternsBoolean(TextAnnotation s) { List<Constituent> list = s.getView(ViewNames.POS).getConstituents(); boolean cb = list.get(1).getLabel().contains("NN"); boolean what = list.get(0).getSurfaceForm().toLowerCase().contains("what"); boolean where = list.get(0).getSurfaceForm().toLowerCase().contains("where"); boolean when = list.get(0).getSurfaceForm().toLowerCase().contains("when"); String secondWordCapitalization = list.get(1).getSurfaceForm(); boolean whereOrWhenAndCapitapized = (where || when) && isCapitalized(secondWordCapitalization.substring(0, 1)); boolean containsBodyOrPart = s.text.contains(" body") || s.text.contains(" part "); boolean whatNationality = s.text.toLowerCase().contains("what") && s.text.contains("nationality"); return new boolean[]{ cb && what, whereOrWhenAndCapitapized, containsBodyOrPart}; }
static public void printTextAnnotation(PrintStream out, TextAnnotation ta) { out.println("TextAnnotation with id: " + ta.getId()); String rawText = ta.getText(); out.println("Raw Text: " + rawText); out.println(getLineFill()); out.println("TextAnnotation Views:"); for (String name : ta.getAvailableViews()) { out.println("View Name: " + name); out.println(ta.getView(name).toString()); out.println(getLineFill()); } }
public static List<String> getFeaturesFromTextAnnotation(final FeatureExtractor fex, TextAnnotation s) { List<Constituent> cons = s.getView(ViewNames.TOKENS).getConstituents(); List<String> features = new ArrayList<>(); for(Constituent c : cons) { try { features.addAll(getFeatureSet(fex, c)); } catch (EdisonException e) { e.printStackTrace(); } } return features; }
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); } }
@Override public Set<Feature> getFeatures(Constituent c) throws EdisonException { SpanLabelView chunks = (SpanLabelView) c.getTextAnnotation().getView(viewName); List<Constituent> list = SpanLabelsHelper.getConstituentsInBetween(chunks, c.getStartSpan(), c.getEndSpan()); Collections.sort(list, TextAnnotationUtilities.constituentStartComparator); return FeatureNGramUtility.getLabelNgramsUnordered(list, ngramLength); }
public static void addHeadAttributes(Constituent head, Gazetteers gazetteers, BrownClusters brownClusters, WordNetManager wordnet){ View tokenView = head.getTextAnnotation().getView(ViewNames.TOKENS); for (int i = head.getStartSpan(); i < head.getEndSpan(); i++) { head.addAttribute("GAZ" + i, ((FlatGazetteers) gazetteers).annotateConstituent(tokenView.getConstituentsCoveringToken(i).get(0), false)); head.addAttribute("BC" + i, brownClusters.getPrefixesCombined(tokenView.getConstituentsCoveringToken(i).get(0).toString())); } head.addAttribute("GAZ", ((FlatGazetteers) gazetteers).annotatePhrase(head)); }