use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class Contains method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent instance) throws EdisonException {
Set<Feature> features = new LinkedHashSet<Feature>();
TextAnnotation ta = instance.getTextAnnotation();
View view = ta.getView(viewName);
List<Constituent> lsc = view.getConstituentsCovering(instance);
if (lsc.size() == 0) {
features.add(N);
return features;
}
boolean contains = false;
for (Constituent c : lsc) if (contained.contains(c.getTokenizedSurfaceForm()) || contained.contains(c.getLabel())) {
contains = true;
break;
}
if (contains)
features.add(Y);
else
features.add(N);
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class SpanFeaturesUnordered method getFeatures.
@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);
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class SubcategorizationFrame method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
Set<Feature> features = new LinkedHashSet<>();
TreeView view = (TreeView) c.getTextAnnotation().getView(parseViewName);
Constituent phrase;
try {
phrase = view.getParsePhrase(c);
} catch (Exception e) {
throw new EdisonException(e);
}
List<Relation> incomingRelations = phrase.getIncomingRelations();
if (incomingRelations == null) {
features.add(DiscreteFeature.create("root"));
} else {
Constituent parent = incomingRelations.get(0).getSource();
StringBuilder subcat = new StringBuilder();
subcat.append(parent.getLabel()).append(">");
for (Relation r : parent.getOutgoingRelations()) {
if (r.getTarget() == phrase) {
subcat.append("(").append(r.getTarget().getLabel()).append(")");
} else {
subcat.append(r.getTarget().getLabel());
}
}
features.add(DiscreteFeature.create(subcat.toString()));
}
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class CandidateBoundaryTransformer method transform.
@Override
public List<Constituent> transform(Constituent input) {
TextAnnotation ta = input.getTextAnnotation();
Constituent ce = new Constituent("", "", ta, input.getEndSpan() - 1, input.getEndSpan());
Constituent cs = new Constituent("", "", ta, input.getStartSpan(), input.getStartSpan() + 1);
new Relation("", cs, ce, 0);
return Collections.singletonList(ce);
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class BrownClusterFeatureExtractor method getWordFeatures.
@Override
public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
lazyLoadClusters(brownClustersFile);
if (!ta.hasView(viewGenerator.getViewName())) {
synchronized (BrownClusterFeatureExtractor.class) {
View view = null;
try {
view = viewGenerator.getView(ta);
} catch (AnnotatorException e) {
e.printStackTrace();
throw new EdisonException(e.getMessage());
}
ta.addView(viewGenerator.getViewName(), view);
}
}
SpanLabelView view = (SpanLabelView) ta.getView(viewGenerator.getViewName());
String word = ta.getToken(wordPosition);
// What follows has a subtle bug: view.getLabel only gets the first
// label for the word. A word can have multiple brown clusters though!
// This has been fixed below.
// String cluster = view.getLabel(wordPosition);
//
// return getBrownClusters(word, cluster);
Set<Feature> features = new LinkedHashSet<>();
for (Constituent c : view.getConstituentsCoveringToken(wordPosition)) {
String cluster = c.getLabel();
features.addAll(getBrownClusters(word, cluster));
}
return features;
}
Aggregations