public String getTokenAttribute(int tokenId, String key) { Constituent c = getConstituentAtToken(tokenId); if (c == null) return null; return c.getAttribute(key); }
public String getTokenAttribute(int tokenId, String key) { Constituent c = getConstituentAtToken(tokenId); if (c == null) return null; return c.getAttribute(key); }
public void addTokenAttribute(int tokenId, String attributeKey, String attributeValue) throws Exception { Constituent c = getConstituentAtToken(tokenId); if (c == null) throw new Exception("Trying to add attribute to non-existent constituent at token " + tokenId); c.addAttribute(attributeKey, attributeValue); }
public void addTokenAttribute(int tokenId, String attributeKey, String attributeValue) throws Exception { Constituent c = getConstituentAtToken(tokenId); if (c == null) throw new Exception("Trying to add attribute to non-existent constituent at token " + tokenId); c.addAttribute(attributeKey, attributeValue); }
String token = ta.getToken(tokenId).toLowerCase(); TokenLabelView lemmaView = (TokenLabelView) ta.getView(ViewNames.LEMMA); String lemma = lemmaView.getConstituentAtToken(tokenId).getLabel(); boolean predicate = false; if (have && lemmaView.getConstituentAtToken(tokenId+1).getLabel().equals("be")) { predicate = false;
@Override public Option<String> getLemma(TextAnnotation ta, int tokenId) { String pos = POSUtils.getPOS(ta, tokenId); boolean isNoun = POSUtils.isPOSNoun(pos); if (!isNoun) { return Option.empty(); } else { Option<String> opt; String token = ta.getToken(tokenId).toLowerCase(); if (pluralLemmas.contains(token)) { opt = testTokenVariations(token); } else { TokenLabelView lemmaView = (TokenLabelView) ta.getView(ViewNames.LEMMA); String lemma = lemmaView.getConstituentAtToken(tokenId).getLabel(); opt = testTokenVariations(lemma); if (!opt.isPresent() && !lemma.matches("-*")) { opt = testWithDelim(lemma, '-'); } if (!opt.isPresent()) { opt = testWithDelim(lemma, ' '); } } return opt; } }
/** * Aligns a {@link Labeling} to a {@link TokenLabelView}. * * @return A TokenLabelView */ public static TokenLabelView alignLabelingToTokenLabelView(String viewName, TextAnnotation ta, Labeling labeling) { List<Span> labels = labeling.getLabels(); double score = labeling.getScore(); String generator = labeling.getSource(); TokenLabelView view = new TokenLabelView(viewName, generator, ta, score); for (Span span : labels) { int tokenId = ta.getTokenIdFromCharacterOffset(span.getStart()); int endTokenId = ta.getTokenIdFromCharacterOffset(span.getEnding()); if (tokenId == endTokenId) endTokenId++; for (int i = tokenId; i < endTokenId; i++) { view.addTokenLabel(i, span.getLabel(), span.getScore()); if (span.isSetAttributes() && span.getAttributes().size() > 0) { Constituent c = view.getConstituentAtToken(i); copyAttributesToConstituent(span, c); } } } return view; }
/** * Aligns a {@link edu.illinois.cs.cogcomp.thrift.base.Labeling} to a * {@link edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView}. * * <b>NOTE:</b> must correct for one-past-the-end labeling when calling * {@link TextAnnotation#getTokenIdFromCharacterOffset(int)}. * * @return A TokenLabelView */ public static TokenLabelView alignLabelingToTokenLabelView(String viewName, TextAnnotation ta, Labeling labeling) { List<Span> labels = labeling.getLabels(); double score = labeling.getScore(); String generator = labeling.getSource(); TokenLabelView view = new TokenLabelView(viewName, generator, ta, score); for (Span span : labels) { int tokenId = ta.getTokenIdFromCharacterOffset(span.getStart()); int endTokenId = ta.getTokenIdFromCharacterOffset(span.getEnding() - 1); if (tokenId == endTokenId) endTokenId++; for (int i = tokenId; i < endTokenId; i++) { view.addTokenLabel(i, span.getLabel(), span.getScore()); if (span.isSetAttributes() && span.getAttributes().size() > 0) { Constituent c = view.getConstituentAtToken(i); copyAttributesToConstituent(span, c); } } } return view; }
/** * Aligns a {@link edu.illinois.cs.cogcomp.thrift.base.Labeling} to a * {@link edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView}. * * <b>NOTE:</b> must correct for one-past-the-end labeling when calling * {@link TextAnnotation#getTokenIdFromCharacterOffset(int)}. * * @return A TokenLabelView */ public static TokenLabelView alignLabelingToTokenLabelView(String viewName, TextAnnotation ta, Labeling labeling) { List<Span> labels = labeling.getLabels(); double score = labeling.getScore(); String generator = labeling.getSource(); TokenLabelView view = new TokenLabelView(viewName, generator, ta, score); for (Span span : labels) { int tokenId = ta.getTokenIdFromCharacterOffset(span.getStart()); int endTokenId = ta.getTokenIdFromCharacterOffset(span.getEnding() - 1); if (tokenId == endTokenId) endTokenId++; for (int i = tokenId; i < endTokenId; i++) { view.addTokenLabel(i, span.getLabel(), span.getScore()); if (span.isSetAttributes() && span.getAttributes().size() > 0) { Constituent c = view.getConstituentAtToken(i); copyAttributesToConstituent(span, c); } } } return view; }