Search in sources :

Example 51 with Constituent

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

the class TestPOSContext method test.

public final void test() throws Exception {
    logger.info("POSContext Feature Extractor");
    String[] viewsToAdd = { ViewNames.POS, ViewNames.LEMMA, ViewNames.SHALLOW_PARSE, ViewNames.PARSE_GOLD, ViewNames.SRL_VERB, ViewNames.PARSE_STANFORD, ViewNames.NER_CONLL };
    TextAnnotation ta = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, true, 3);
    int i = 0;
    ta.addView(ClauseViewGenerator.STANFORD);
    ta.addView(PseudoParse.STANFORD);
    logger.info("This textannotation annotates the text: \n" + ta.getText());
    View TOKENS = ta.getView("TOKENS");
    List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(10, 13);
    FeatureManifest featureManifest;
    FeatureExtractor fex;
    String fileName = Constant.prefix + "/Nom/Classifier/pos-context.fex";
    featureManifest = new FeatureManifest(new FileInputStream(fileName));
    FeatureManifest.setFeatureExtractor("hyphen-argument-feature", FeatureGenerators.hyphenTagFeature);
    FeatureManifest.setTransformer("parse-left-sibling", FeatureGenerators.getParseLeftSibling(ViewNames.PARSE_STANFORD));
    FeatureManifest.setTransformer("parse-right-sibling", FeatureGenerators.getParseRightSibling(ViewNames.PARSE_STANFORD));
    FeatureManifest.setFeatureExtractor("pp-features", FeatureGenerators.ppFeatures(ViewNames.PARSE_STANFORD));
    FeatureManifest.setFeatureExtractor("projected-path", new ProjectedPath(ViewNames.PARSE_STANFORD));
    featureManifest.useCompressedName();
    featureManifest.setVariable("*default-parser*", ViewNames.PARSE_STANFORD);
    fex = featureManifest.createFex();
    POSContextWindowTwo pc = new POSContextWindowTwo();
    for (Constituent test : testlist) {
        assertTrue(SRLFeaturesComparator.isEqual(test, fex, pc));
    }
}
Also used : FeatureExtractor(edu.illinois.cs.cogcomp.edison.features.FeatureExtractor) FeatureManifest(edu.illinois.cs.cogcomp.edison.features.manifest.FeatureManifest) ProjectedPath(edu.illinois.cs.cogcomp.edison.features.lrec.ProjectedPath) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) FileInputStream(java.io.FileInputStream)

Example 52 with Constituent

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

the class TestParseSibling method test.

public final void test() throws Exception {
    logger.info("ParseSibling Feature Extractor");
    String[] viewsToAdd = { ViewNames.POS, ViewNames.LEMMA, ViewNames.SHALLOW_PARSE, ViewNames.PARSE_GOLD, ViewNames.SRL_VERB, ViewNames.PARSE_STANFORD, ViewNames.NER_CONLL };
    TextAnnotation ta = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, true, 3);
    int i = 0;
    ta.addView(ClauseViewGenerator.STANFORD);
    ta.addView(PseudoParse.STANFORD);
    logger.info("This textannotation annotates the text: \n" + ta.getText());
    View TOKENS = ta.getView("TOKENS");
    List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(10, 13);
    testlist.addAll(TOKENS.getConstituentsCoveringSpan(26, 27));
    FeatureManifest featureManifest;
    FeatureExtractor fex;
    String fileName = Constant.prefix + "/Verb/Classifier/parse-sibling.fex";
    featureManifest = new FeatureManifest(new FileInputStream(fileName));
    FeatureManifest.setFeatureExtractor("hyphen-argument-feature", FeatureGenerators.hyphenTagFeature);
    FeatureManifest.setTransformer("parse-left-sibling", FeatureGenerators.getParseLeftSibling(ViewNames.PARSE_STANFORD));
    FeatureManifest.setTransformer("parse-right-sibling", FeatureGenerators.getParseRightSibling(ViewNames.PARSE_STANFORD));
    FeatureManifest.setFeatureExtractor("pp-features", FeatureGenerators.ppFeatures(ViewNames.PARSE_STANFORD));
    FeatureManifest.setFeatureExtractor("projected-path", new ProjectedPath(ViewNames.PARSE_STANFORD));
    featureManifest.useCompressedName();
    featureManifest.setVariable("*default-parser*", ViewNames.PARSE_STANFORD);
    fex = featureManifest.createFex();
    ParseSibling ps = new ParseSibling();
    for (Constituent test : testlist) {
        assertTrue(SRLFeaturesComparator.isEqual(test, fex, ps));
    }
}
Also used : ParseSibling(edu.illinois.cs.cogcomp.edison.features.lrec.srl.generic.ParseSibling) FeatureExtractor(edu.illinois.cs.cogcomp.edison.features.FeatureExtractor) FeatureManifest(edu.illinois.cs.cogcomp.edison.features.manifest.FeatureManifest) ProjectedPath(edu.illinois.cs.cogcomp.edison.features.lrec.ProjectedPath) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) FileInputStream(java.io.FileInputStream)

Example 53 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent 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 54 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent 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)

Example 55 with Constituent

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

the class TestContextFeatureExtractor method testGetFeaturesIndexWithoutConstituent.

@Test
public void testGetFeaturesIndexWithoutConstituent() throws EdisonException {
    ContextFeatureExtractor fex = new ContextFeatureExtractor(2, true, true);
    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", "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", "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)

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