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; }
public static String printView(View view) throws IOException { StringBuilder bldr = new StringBuilder(); bldr.append( "View '" ); bldr.append( view.getViewName() ); bldr.append( "':\n" ); for ( Constituent c: view.getConstituents() ) { bldr.append( printConstituent( c ) ); } bldr.append( OUTPUT_SEPARATOR ); return bldr.toString(); }
public static String printView(View view) throws IOException { StringBuilder bldr = new StringBuilder(); bldr.append( "View '" ); bldr.append( view.getViewName() ); bldr.append( "':\n" ); for ( Constituent c: view.getConstituents() ) { bldr.append( printConstituent( c ) ); } bldr.append( OUTPUT_SEPARATOR ); return bldr.toString(); }
private static void printCharSpans(View view, String file) throws FileNotFoundException { PrintStream out = new PrintStream(file); for (Constituent c : view.getConstituents()) out.println(c.getStartCharOffset() + "," + c.getEndCharOffset()); out.close(); } }
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}; }
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 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; }
private void addView(TextAnnotation ta, List<String> labels) { TokenLabelView labelView = new TokenLabelView(viewName, ta); List constituents = ta.getView(ViewNames.TOKENS).getConstituents(); assert constituents.size() == labels.size(); for (int i = 0; i < constituents.size(); ++i) { Constituent constituent = (Constituent) constituents.get(i); labelView.addTokenLabel(constituent.getStartSpan(), labels.get(i), 1.0D); } ta.addView(viewName, labelView); }
public static boolean[] getOverlapWithSets(TextAnnotation s) { boolean mountainOverlap = false; boolean profOverlap = false; boolean foodOverlap = false; for(Constituent c: s.getView(ViewNames.LEMMA).getConstituents()) { if(mountainOverlap && profOverlap && foodOverlap) break; if(!profOverlap && occupations.contains(c.getLabel())) profOverlap = true; if(!foodOverlap && food.contains(c.getLabel())) foodOverlap = true; if(!mountainOverlap && mountain.contains(c.getLabel())) mountainOverlap = true; } return new boolean[] { mountainOverlap, profOverlap, foodOverlap }; }
private static IntPair[] getCharacterOffsets(View view) { List<Constituent> constituents = view.getConstituents(); IntPair[] offsets = new IntPair[constituents.size()]; int index = 0; for (Constituent c : constituents) offsets[index++] = new IntPair(c.getStartCharOffset(), c.getEndCharOffset()); return offsets; } }
private static IntPair[] getCharacterOffsets(View view) { List<Constituent> constituents = view.getConstituents(); IntPair[] offsets = new IntPair[constituents.size()]; int index = 0; for (Constituent c : constituents) offsets[index++] = new IntPair(c.getStartCharOffset(), c.getEndCharOffset()); return offsets; } }
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); } }
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); } }
protected Constituent getExactMatch(View view, Constituent c) { for (Constituent viewConst : view.getConstituents()) { if (viewConst.getSpan().equals(c.getSpan())) return viewConst; } return null; }
protected Constituent getExactMatch(View view, Constituent c) { for (Constituent viewConst : view.getConstituents()) { if (viewConst.getSpan().equals(c.getSpan())) return viewConst; } return null; }
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(); } }
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(); } }
/** Helper methods to handle Protobuf implementation */ private static void writeTokenOffsets(TextAnnotation ta, TextAnnotationProto.Builder taBuilder) { for (Constituent c : ta.getView(ViewNames.TOKENS).getConstituents()) { TokenOffsetsProto.Builder tokenOffsetBuilder = TokenOffsetsProto.newBuilder(); tokenOffsetBuilder.setForm(c.getSurfaceForm()); tokenOffsetBuilder.setStartCharOffset(c.getStartCharOffset()); tokenOffsetBuilder.setEndCharOffset(c.getEndCharOffset()); taBuilder.addTokenOffsets(tokenOffsetBuilder); } }
/** Helper methods to handle Protobuf implementation */ private static void writeTokenOffsets(TextAnnotation ta, TextAnnotationProto.Builder taBuilder) { for (Constituent c : ta.getView(ViewNames.TOKENS).getConstituents()) { TokenOffsetsProto.Builder tokenOffsetBuilder = TokenOffsetsProto.newBuilder(); tokenOffsetBuilder.setForm(c.getSurfaceForm()); tokenOffsetBuilder.setStartCharOffset(c.getStartCharOffset()); tokenOffsetBuilder.setEndCharOffset(c.getEndCharOffset()); taBuilder.addTokenOffsets(tokenOffsetBuilder); } }