Search in sources :

Example 66 with TextAnnotation

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

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

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

the class TestHeadFinderDependencyHelper method testHeadFinderDependencyHelper.

@Test
public final void testHeadFinderDependencyHelper() {
    String s = "There is no recovery period -- it 's go , go , go .";
    String treeString = "(S1 (S (S (NP (EX There))    (VP (AUX is)        (NP (DT no)            (NN recovery) " + "           (NN period))))    (: --)    (S (NP (PRP it))       (VP (AUX 's)           (S (VP (VB go)  " + "   (, ,)     (VB go)     (, ,)     (VB go)))))    (. .)))";
    TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString(s);
    TreeView parse = new TreeView(ViewNames.PARSE_CHARNIAK, "", ta, 1.0);
    parse.setParseTree(0, TreeParserFactory.getStringTreeParser().parse(treeString));
    ta.addView(ViewNames.PARSE_CHARNIAK, parse);
    logger.info(ta.getView(ViewNames.PARSE_CHARNIAK).toString());
    HeadFinderDependencyViewGenerator dep = new HeadFinderDependencyViewGenerator(ViewNames.PARSE_CHARNIAK);
    TreeView depTree = null;
    try {
        depTree = (TreeView) dep.getView(ta);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    logger.info(depTree.toString());
    assertEquals(depTree.getNumberOfConstituents(), ta.size());
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) TreeView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Test(org.junit.Test)

Example 69 with TextAnnotation

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

Example 70 with TextAnnotation

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

the class TestNGramFeatures method testBigrams.

private void testBigrams(WordFeatureExtractor f) throws EdisonException {
    final NgramFeatureExtractor bigrams = NgramFeatureExtractor.bigrams(f);
    for (final TextAnnotation ta : tas) {
        for (int i = 0; i < ta.size(); i++) {
            final Set<Feature> b = bigrams.getWordFeatures(ta, i);
            Set<Feature> wordFeatures0 = f.getWordFeatures(ta, i - 1);
            Set<Feature> wordFeatures1 = f.getWordFeatures(ta, i);
            assertEquals(wordFeatures0.size() * wordFeatures1.size(), b.size());
            for (Feature w0 : wordFeatures0) {
                for (Feature w1 : wordFeatures1) {
                    assertEquals(true, b.contains(w0.conjoinWith(w1)));
                }
            }
        }
    }
}
Also used : TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)

Aggregations

TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)218 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)95 Test (org.junit.Test)65 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)49 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)48 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)29 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)28 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)25 ArrayList (java.util.ArrayList)23 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)22 LinkedHashSet (java.util.LinkedHashSet)21 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)16 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)16 FeatureExtractor (edu.illinois.cs.cogcomp.edison.features.FeatureExtractor)16 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 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)14 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)12 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)11