use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.
the class FeatureManifestTest method testCreateFex.
@Test
public void testCreateFex() throws Exception {
FeatureManifest featureManifest = new FeatureManifest(file);
featureManifest.useCompressedName();
featureManifest.setVariable("*default-parser*", ViewNames.PARSE_STANFORD);
FeatureExtractor fex = featureManifest.createFex();
Constituent c = tas.get(0).getView(ViewNames.TOKENS).getConstituents().get(0);
assertEquals("My", c.getSurfaceForm());
Set<Feature> features = fex.getFeatures(c);
Iterator<Feature> iterator = features.iterator();
Feature feature = iterator.next();
assertEquals("f:#ctxt#:context1::#wd:mother-in-law", feature.getName());
}
use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.
the class CreateTestFeaturesResource method addFeatCollection.
private void addFeatCollection() throws EdisonException, IOException {
Map<Integer, String> map = new HashMap<>();
FeatureCollection featureCollection = new FeatureCollection("features");
featureCollection.addFeatureExtractor(WordFeatureExtractorFactory.conflatedPOS);
featureCollection.addFeatureExtractor(WordFeatureExtractorFactory.gerundMarker);
featureCollection.addFeatureExtractor(WordFeatureExtractorFactory.nominalizationMarker);
for (TextAnnotation ta : tas) {
for (int tokenId = 0; tokenId < ta.size(); tokenId++) {
Constituent c = new Constituent("", "", ta, tokenId, tokenId + 1);
Set<Feature> features = featureCollection.getFeatures(c);
if (features.size() > 0) {
String id = ta.getTokenizedText() + ":" + tokenId;
map.put(id.hashCode(), features.toString());
}
}
}
IOUtils.writeObject(map, FEATURE_COLLECTION_FILE);
}
use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.
the class WordBigrams method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent instance) throws EdisonException {
Set<Feature> features = new LinkedHashSet<Feature>();
View tokens = instance.getTextAnnotation().getView(ViewNames.TOKENS);
List<Constituent> list = tokens.getConstituentsCoveringSpan(instance.getStartSpan(), instance.getEndSpan());
Collections.sort(list, TextAnnotationUtilities.constituentStartComparator);
ITransformer<Constituent, String> surfaceFormTransformer = new ITransformer<Constituent, String>() {
private static final long serialVersionUID = 1L;
public String transform(Constituent input) {
return input.getSurfaceForm();
}
};
features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 1, surfaceFormTransformer));
features.addAll(FeatureNGramUtility.getNgramsOrdered(list, 2, surfaceFormTransformer));
return features;
}
use of edu.illinois.cs.cogcomp.edison.features.Feature 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.edison.features.Feature in project cogcomp-nlp by CogComp.
the class SenseInstance method cacheFeatureVector.
public void cacheFeatureVector(Set<Feature> features) {
Map<String, Float> featureMap = new HashMap<>();
for (Feature f : features) {
featureMap.put(f.getName(), f.getValue());
}
ModelInfo modelInfo = manager.getModelInfo();
Pair<int[], float[]> feats = modelInfo.getLexicon().getFeatureVector(featureMap);
this.cacheFeatureVector(new FeatureVector(feats.getFirst(), feats.getSecond()));
}
Aggregations