Search in sources :

Example 96 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class TestContextFeatureExtractor method testGetFeaturesIndexWithConstituent.

@Test
public void testGetFeaturesIndexWithConstituent() throws EdisonException {
    ContextFeatureExtractor fex = new ContextFeatureExtractor(2, true, false);
    fex.addFeatureExtractor(new WordFeatureExtractor() {

        @Override
        public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
            String s = WordHelpers.getWord(ta, wordPosition).toLowerCase();
            Set<Feature> ss = new HashSet<>();
            ss.add(DiscreteFeature.create(s));
            return ss;
        }
    });
    TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString("This is a test for the feature extractor .");
    Constituent c1 = new Constituent("", "", ta, 2, 3);
    Set<String> c1fs = new HashSet<>();
    c1fs.addAll(Arrays.asList("context-2:#word#:this", "context-1:#word#:is", "context*:#word#:a", "context1:#word#:test", "context2:#word#:for"));
    Set<Feature> c1f = FeatureUtilities.getFeatures(c1fs);
    Set<Feature> features = fex.getFeatures(c1);
    c1f.removeAll(features);
    assertEquals(0, c1f.size());
    Constituent c2 = new Constituent("", "", ta, 2, 4);
    Set<String> c2fs = new HashSet<>();
    c2fs.addAll(Arrays.asList("context-2:#word#:this", "context-1:#word#:is", "context*:#word#:a", "context*:#word#:test", "context1:#word#:for", "context2:#word#:the"));
    Set<Feature> c2f = FeatureUtilities.getFeatures(c2fs);
    c2f.removeAll(fex.getFeatures(c2));
    assertEquals(0, c2f.size());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 97 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class TestChunkFeatures method testFex.

private void testFex(FeatureExtractor fex, boolean printBoth, String... viewNames) throws EdisonException {
    for (TextAnnotation ta : tas) {
        for (String viewName : viewNames) if (ta.hasView(viewName))
            logger.info(ta.getView(viewName).toString());
        if (!ta.hasView(ViewNames.SRL_VERB))
            continue;
        PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
        for (Constituent predicate : pav.getPredicates()) {
            Constituent p = predicate.cloneForNewView("dummy");
            for (Relation argument : pav.getArguments(predicate)) {
                Constituent c = argument.getTarget().cloneForNewView("dummy");
                Relation r = new Relation("", p, c, 1);
                logger.info((printBoth ? r : c) + "\t" + fex.getFeatures(c));
            }
        }
    }
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 98 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class TestVerbClassFeatures method test.

@Test
public final void test() throws Exception {
    TextAnnotation ta = tas.get(tas.size() - 1);
    PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
    for (Constituent predicate : pav.getPredicates()) {
        Constituent p = predicate.cloneForNewView("dummy");
        String response = p + "\t" + LevinVerbClassFeature.instance.getFeatures(p);
        assertTrue(correctResponses.contains(response));
    }
}
Also used : TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 99 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class TestWordFeatureFactory method testFeatureCollection.

@Test
public final void testFeatureCollection() throws Exception {
    FeatureCollection f = new FeatureCollection("features");
    f.addFeatureExtractor(WordFeatureExtractorFactory.conflatedPOS);
    f.addFeatureExtractor(WordFeatureExtractorFactory.gerundMarker);
    f.addFeatureExtractor(WordFeatureExtractorFactory.nominalizationMarker);
    logger.info("\tTesting feature collection");
    Map<Integer, String> map = IOUtils.readObjectAsResource(TestWordFeatureFactory.class, "feature.collection.test");
    for (TextAnnotation ta : tas) {
        for (int tokenId = 0; tokenId < ta.size(); tokenId++) {
            Constituent c = new Constituent("", "", ta, tokenId, tokenId + 1);
            Set<Feature> features = f.getFeatures(c);
            if (features.size() > 0) {
                String id = ta.getTokenizedText() + ":" + tokenId;
                assertEquals(map.get(id.hashCode()), features.toString());
            }
        }
    }
}
Also used : 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) Test(org.junit.Test)

Example 100 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class TextStatistics method consume.

@Override
protected void consume(TextAnnotation ta) {
    for (Constituent c : constituentGenerator.transform(ta)) {
        try {
            Set<Feature> feats = fex.getFeatures(c);
            for (Feature feat : feats) {
                count(feat);
            }
            constituentCounter.incrementAndGet();
        } catch (EdisonException e) {
            e.printStackTrace();
        }
    }
    textCounter.incrementAndGet();
}
Also used : Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)176 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)95 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)51 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)44 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)29 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)25 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)24 LinkedHashSet (java.util.LinkedHashSet)22 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)20 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)20 FeatureExtractor (edu.illinois.cs.cogcomp.edison.features.FeatureExtractor)17 ProjectedPath (edu.illinois.cs.cogcomp.edison.features.lrec.ProjectedPath)16 FeatureManifest (edu.illinois.cs.cogcomp.edison.features.manifest.FeatureManifest)16 FileInputStream (java.io.FileInputStream)16 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)14 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)13 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)12 HashSet (java.util.HashSet)12 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)11