@Override public String transform(Constituent input) { return input.getLabel(); } };
@Override public String transform(Constituent input) { return input.getLabel(); } };
public List<String> getLabelsCoveringToken(int tokenId) { List<String> output = new ArrayList<>(); if (tokenId < 0 || tokenId >= this.tokensToConstituents.length) return output; if (this.tokensToConstituents[tokenId] == null) return output; for (int i = 0; i < this.tokensToConstituents[tokenId].size(); i++) { Constituent c = (Constituent) this.tokensToConstituents[tokenId].get(i); output.add(c.getLabel()); } return output; }
public List<String> getLabelsCoveringToken(int tokenId) { List<String> output = new ArrayList<>(); if (tokenId < 0 || tokenId >= this.tokensToConstituents.length) return output; if (this.tokensToConstituents[tokenId] == null) return output; for (int i = 0; i < this.tokensToConstituents[tokenId].size(); i++) { Constituent c = (Constituent) this.tokensToConstituents[tokenId].get(i); output.add(c.getLabel()); } return output; }
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 }; }
@Override public Set<Feature> getFeatures(Constituent c) throws EdisonException { return new LinkedHashSet<Feature>(Collections.singletonList(DiscreteFeature .create(c.getLabel()))); } });
@Override public String toString() { List<Constituent> constituents = new ArrayList<>(this.getConstituents()); Collections.sort(constituents, TextAnnotationUtilities.constituentStartComparator); StringBuilder sb = new StringBuilder(); for (Constituent c : constituents) sb.append("[").append(c.getLabel()).append(" ").append(c.getTokenizedSurfaceForm()) .append(" ] "); return sb.toString(); } }
@Override public String toString() { List<Constituent> constituents = new ArrayList<>(this.getConstituents()); Collections.sort(constituents, TextAnnotationUtilities.constituentStartComparator); StringBuilder sb = new StringBuilder(); for (Constituent c : constituents) sb.append("[").append(c.getLabel()).append(" ").append(c.getTokenizedSurfaceForm()) .append(" ] "); return sb.toString(); } }
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 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 }; }
private void addFeatures(Set<Feature> features, View view, Predicate<Constituent> condition, Counter<String> counter, String name) { for (Constituent chunk : view.where(condition)) { String label = name + "-" + chunk.getLabel(); features.add(DiscreteFeature.create("e:" + label)); counter.incrementCount("n:" + label); } }
private void addFeatures(Set<Feature> features, View view, Predicate<Constituent> condition, Counter<String> counter, String name) { for (Constituent chunk : view.where(condition)) { String label = name + "-" + chunk.getLabel(); features.add(DiscreteFeature.create("e:" + label)); counter.incrementCount("n:" + label); } }
public static String getFirstLabel(TextAnnotation s, String label) { List<Constituent> list = s.getView(ViewNames.SHALLOW_PARSE).getConstituents(); String nounPhrase = ""; for(Constituent c : list) { if(c.getLabel().contains(label)) { nounPhrase = c.getSurfaceForm(); } } return nounPhrase; }
public static Constituent getPredictedMentionHead(Constituent c){ return new Constituent(c.getLabel(), "HEAD", c.getTextAnnotation(), Integer.parseInt(c.getAttribute("EntityHeadStartSpan")), Integer.parseInt(c.getAttribute("EntityHeadEndSpan"))); }
public static Constituent getPredictedMentionHead(Constituent c){ return new Constituent(c.getLabel(), "HEAD", c.getTextAnnotation(), Integer.parseInt(c.getAttribute("EntityHeadStartSpan")), Integer.parseInt(c.getAttribute("EntityHeadEndSpan"))); }
public static Constituent getPredictedMentionHead(Constituent c){ return new Constituent(c.getLabel(), "HEAD", c.getTextAnnotation(), Integer.parseInt(c.getAttribute("EntityHeadStartSpan")), Integer.parseInt(c.getAttribute("EntityHeadEndSpan"))); }
@Override public Boolean transform(Pair<Constituent, SpanLabelView> input) { if (!input.getFirst().getLabel().equals(CLOTHES)) return true; TextAnnotation ta = input.getFirst().getTextAnnotation(); int last = input.getFirst().getEndSpan() - 1; return !ta.hasView(ViewNames.POS) || POSUtils.isPOSNoun(WordHelpers.getPOS(ta, last)); } });