Search in sources :

Example 36 with Feature

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());
}
Also used : FeatureExtractor(edu.illinois.cs.cogcomp.edison.features.FeatureExtractor) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 37 with Feature

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);
}
Also used : HashMap(java.util.HashMap) FeatureCollection(edu.illinois.cs.cogcomp.edison.features.FeatureCollection) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 38 with Feature

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ITransformer(edu.illinois.cs.cogcomp.core.transformers.ITransformer) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 39 with Feature

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;
}
Also used : TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 40 with Feature

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()));
}
Also used : FeatureVector(edu.illinois.cs.cogcomp.sl.util.FeatureVector) ModelInfo(edu.illinois.cs.cogcomp.verbsense.core.ModelInfo) Feature(edu.illinois.cs.cogcomp.edison.features.Feature)

Aggregations

Feature (edu.illinois.cs.cogcomp.edison.features.Feature)71 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)48 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)44 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)41 LinkedHashSet (java.util.LinkedHashSet)24 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)22 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)17 Test (org.junit.Test)13 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)12 HashSet (java.util.HashSet)11 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)10 ArrayList (java.util.ArrayList)9 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)8 RealFeature (edu.illinois.cs.cogcomp.edison.features.RealFeature)8 Set (java.util.Set)6 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)5 POSBaseLineCounter (edu.illinois.cs.cogcomp.edison.utilities.POSBaseLineCounter)5 POSMikheevCounter (edu.illinois.cs.cogcomp.edison.utilities.POSMikheevCounter)5 ModelInfo (edu.illinois.cs.cogcomp.verbsense.core.ModelInfo)3 List (java.util.List)3