Search in sources :

Example 31 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class TestPOSMikheevFeatureExtractor method test.

@Test
public final void test() throws Exception {
    POSMikheevFeatureExtractor posMikheev = new POSMikheevFeatureExtractor("posMikheev", "test_corpus", TestPosHelper.corpus);
    logger.info("POSMikheev Feature Extractor");
    logger.info("Only print the features with known tags");
    // Using the first TA and a constituent between span of 30-40 as a test
    int i = 0;
    for (TextAnnotation ta : tas) {
        ArrayList<String> outFeatures = new ArrayList<>();
        View TOKENS = ta.getView("TOKENS");
        for (Constituent TOKEN : TOKENS) {
            Set<Feature> feats = posMikheev.getFeatures(TOKEN);
            if (feats.isEmpty()) {
                logger.info("Feats list is returning NULL.");
            }
            for (Feature f : feats) if (!f.getName().contains("UNKNOWN")) {
                outFeatures.add(f.getName());
            }
        }
        if (!outFeatures.isEmpty()) {
            logger.info("-------------------------------------------------------");
            logger.info("Text Annotation: " + i);
            logger.info("Text Features: ");
            for (String out : outFeatures) logger.info(out);
            logger.info("-------------------------------------------------------");
        }
        i++;
    }
    logger.info("GOT FEATURES YES!");
}
Also used : ArrayList(java.util.ArrayList) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 32 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class TestPOSWindowTwo method test.

@Test
public final void test() throws EdisonException {
    log.debug("POSWindowTwo Feature Extractor");
    // Using the first TA and a constituent between span of 30-40 as a test
    TextAnnotation ta = tas.get(2);
    View TOKENS = ta.getView("TOKENS");
    List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20);
    for (Constituent c : testlist) {
        log.debug(c.getSurfaceForm());
    }
    Constituent test = testlist.get(1);
    log.debug("The constituent we are extracting features from in this test is: " + test.getSurfaceForm());
    POSWindowTwo POSW = new POSWindowTwo("POSWindowTwo");
    log.debug("Startspan is " + test.getStartSpan() + " and Endspan is " + test.getEndSpan());
    Set<Feature> feats = POSW.getFeatures(test);
    String[] expected_outputs = { "POSWindowTwo:0(DT)", "POSWindowTwo:1(VBZ)", "POSWindowTwo:2(DT)", "POSWindowTwo:3(NN)" };
    if (feats == null) {
        log.debug("Feats are returning NULL.");
    }
    log.debug("Printing Set of Features");
    for (Feature f : feats) {
        assert (ArrayUtils.contains(expected_outputs, f.getName()));
    }
// System.exit(0);
}
Also used : TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 33 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class TestPosWordConjunctionSizeTwoWindowSizeTwo method test.

@Test
public final void test() throws EdisonException {
    // / Using the 3rd constituent as a test
    List<Constituent> testList = ta.getView("TOKENS").getConstituents();
    Constituent test = testList.get(3);
    PosWordConjunctionSizeTwoWindowSizeTwo fex = new PosWordConjunctionSizeTwoWindowSizeTwo("PosWordConj2Win2");
    Set<Feature> feats = fex.getFeatures(test);
    String[] expected_outputs = { "PosWordConjunctionSizeTwoWindowSizeTwo:-2_1(NN-construction)", "PosWordConjunctionSizeTwoWindowSizeTwo:-1_1(IN-of)", "PosWordConjunctionSizeTwoWindowSizeTwo:0_1(DT-the)", "PosWordConjunctionSizeTwoWindowSizeTwo:1_1(NNP-John)", "PosWordConjunctionSizeTwoWindowSizeTwo:2_1(NNP-Smith)", "PosWordConjunctionSizeTwoWindowSizeTwo:-2_2(NN-construction_IN-of)", "PosWordConjunctionSizeTwoWindowSizeTwo:-1_2(IN-of_DT-the)", "PosWordConjunctionSizeTwoWindowSizeTwo:0_2(DT-the_NNP-John)", "PosWordConjunctionSizeTwoWindowSizeTwo:1_2(NNP-John_NNP-Smith)", "PosWordConjunctionSizeTwoWindowSizeTwo:2_2(NNP-Smith)" };
    if (feats == null)
        fail("Feats are returning NULL.");
    for (Feature f : feats) {
        assertTrue(ArrayUtils.contains(expected_outputs, f.getName()));
    }
}
Also used : Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 34 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class TestClauseFeatureExtractor method testFex.

private void testFex(FeatureExtractor fex) throws Exception {
    for (TextAnnotation ta : tas) {
        if (!ta.hasView(ViewNames.PARSE_CHARNIAK))
            continue;
        ta.addView(ClauseViewGenerator.CHARNIAK);
        ta.addView(PseudoParse.CHARNIAK);
        PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
        for (Constituent predicate : pav.getPredicates()) {
            Constituent p = predicate.cloneForNewView("dummy");
            for (Relation arg : pav.getArguments(predicate)) {
                Constituent c = arg.getTarget().cloneForNewView("dummy");
                new Relation("", p, c, 1.0);
                Set<Feature> features = fex.getFeatures(c);
                logger.info(c + "\t" + features);
            }
        }
    }
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 35 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class TestSyntacticFrame method testFex.

private void testFex(FeatureExtractor fex) throws Exception {
    for (TextAnnotation ta : tas) {
        if (!ta.hasView(ViewNames.PARSE_CHARNIAK))
            continue;
        PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
        for (Constituent predicate : pav.getPredicates()) {
            Constituent p = predicate.cloneForNewView("dummy");
            for (Relation arg : pav.getArguments(predicate)) {
                Constituent c = arg.getTarget().cloneForNewView("dummy");
                new Relation("", p, c, 1.0);
                Set<Feature> features = fex.getFeatures(c);
                logger.info(c + "\t" + features);
                assertEquals(3, features.size());
            }
        }
    }
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

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