use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class FeatureUtilities method getFeaturesFromTextAnnotation.
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;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class ParseHeadWordFeatureExtractor method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
TextAnnotation ta = c.getTextAnnotation();
TreeView tree = (TreeView) ta.getView(parseViewName);
Constituent phrase;
try {
phrase = tree.getParsePhrase(c);
} catch (Exception e) {
throw new EdisonException(e);
}
Set<Feature> features = new LinkedHashSet<>();
int head = CollinsHeadFinder.getInstance().getHeadWordPosition(phrase);
Constituent c1 = new Constituent("", "", ta, head, head + 1);
features.addAll(fex.getFeatures(c1));
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class ContextFeatureExtractor method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
TextAnnotation ta = c.getTextAnnotation();
int start = c.getStartSpan() - contextSize;
int end = c.getEndSpan() + contextSize;
if (start < 0)
start = 0;
if (end >= ta.size())
end = ta.size();
Set<Feature> features = new LinkedHashSet<>();
for (int i = start; i < end; i++) {
if (ignoreConstituent)
if (c.getStartSpan() <= i && i < c.getEndSpan())
continue;
for (FeatureExtractor f : this.generators) {
Constituent neighbor = new Constituent("TMP", "TMP", ta, i, i + 1);
Set<Feature> feats = f.getFeatures(neighbor);
for (Feature feat : feats) {
String preamble = "context";
if (specifyIndex) {
String index = "*";
if (i < c.getStartSpan())
index = (i - c.getStartSpan()) + "";
else if (i >= c.getEndSpan())
index = (i - c.getEndSpan() + 1) + "";
preamble += index;
}
preamble += ":";
features.add(feat.prefixWith(preamble + f.getName()));
}
}
}
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class DependencyModifierFeatureExtractor method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
List<Constituent> parents = dependencyHeadIdentifier.transform(c);
Set<Feature> features = new LinkedHashSet<>();
if (parents.size() == 0) {
Constituent parent = parents.get(0);
for (Relation out : parent.getOutgoingRelations()) {
String label = out.getRelationName();
if (label.contains("det") || label.contains("mod") || label.contains("number")) {
features.addAll(FeatureUtilities.prefix(label, baseFex.getFeatures(out.getTarget())));
}
}
}
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.
the class FeatureCollection method getFeatures.
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
boolean hasName = this.getName().length() > 0;
Set<Feature> features = new LinkedHashSet<>();
if (this.inputTransformer == FeatureInputTransformer.identity) {
getFeatures(hasName, features, c);
} else {
List<Constituent> input = inputTransformer.transform(c);
if (input == null || input.size() == 0) {
features.add(NULL_INPUT);
} else {
for (Constituent in : input) {
getFeatures(hasName, features, in);
}
}
features = FeatureUtilities.prefix(this.inputTransformer.name(), features);
}
return features;
}
Aggregations