use of edu.illinois.cs.cogcomp.edison.features.Feature 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.edison.features.Feature in project cogcomp-nlp by CogComp.
the class LabeledDepFeatureGenerator method featureVectorBufferFromFeature.
private FeatureVectorBuffer featureVectorBufferFromFeature(Set<Feature> features) {
Map<String, Float> featureMap = new HashMap<>();
for (Feature f : features) {
if (lm.containFeature(f.getName()))
featureMap.put(f.getName(), f.getValue());
}
SparseFeatureVector sfv = (SparseFeatureVector) lm.convertToFeatureVector(featureMap);
return new FeatureVectorBuffer(sfv);
}
use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.
the class LabeledDepFeatureGenerator method SuffixConj.
private Set<Feature> SuffixConj(int head, int dep, DepInst sent, String deprel) {
String header = "Suffix: ";
String suffixhead = sent.strLemmas[head].substring(Math.max(sent.strLemmas[head].length() - 3, 0)) + " ";
String suffixdep = sent.strLemmas[dep].substring(Math.max(sent.strLemmas[dep].length() - 3, 0)) + " ";
String poshead = sent.strPos[head] + " ";
String posdep = sent.strPos[dep] + " ";
String arcdir = "Arc-dir: " + (head < dep) + " ";
Set<Feature> feats = new HashSet<>();
feats.add(new DiscreteFeature(header + suffixhead + posdep + arcdir + deprel));
feats.add(new DiscreteFeature(header + poshead + suffixdep + arcdir + deprel));
feats.add(new DiscreteFeature(header + suffixhead + suffixdep + arcdir + deprel));
return feats;
}
use of edu.illinois.cs.cogcomp.edison.features.Feature 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;
}
use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.
the class ParsePhraseTypeOnly 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<>();
if (phrase != null)
features.add(DiscreteFeature.create(phrase.getLabel()));
return features;
}
Aggregations