Search in sources :

Example 26 with EdisonException

use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.

the class TestContextFeatureExtractor method testGetFeaturesNoIndexWithConstituent.

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

        @Override
        public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
            String s = WordHelpers.getWord(ta, wordPosition).toLowerCase();
            Set<String> ss = new HashSet<>();
            ss.add(s);
            return FeatureUtilities.getFeatures(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:#word#:this", "context:#word#:is", "context:#word#:a", "context:#word#:test", "context:#word#:for"));
    Set<Feature> c1f = FeatureUtilities.getFeatures(c1fs);
    c1f.removeAll(fex.getFeatures(c1));
    assertEquals(0, c1f.size());
    Constituent c2 = new Constituent("", "", ta, 2, 4);
    Set<String> c2fs = new HashSet<>();
    c2fs.addAll(Arrays.asList("context:#word#:this", "context:#word#:is", "context:#word#:a", "context:#word#:test", "context:#word#:for", "context:#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 27 with EdisonException

use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.

the class TestContextFeatureExtractor method testGetFeaturesNoIndexWithoutConstituent.

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

        @Override
        public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
            String s = WordHelpers.getWord(ta, wordPosition).toLowerCase();
            Set<String> ss = new HashSet<>();
            ss.add(s);
            return FeatureUtilities.getFeatures(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:#word#:this", "context:#word#:is", "context:#word#:test", "context:#word#:for"));
    Set<Feature> c1f = FeatureUtilities.getFeatures(c1fs);
    c1f.removeAll(fex.getFeatures(c1));
    assertEquals(0, c1f.size());
    Constituent c2 = new Constituent("", "", ta, 2, 4);
    Set<String> c2fs = new HashSet<>();
    c2fs.addAll(Arrays.asList("context:#word#:this", "context:#word#:is", "context:#word#:for", "context:#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 28 with EdisonException

use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException 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 29 with EdisonException

use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.

the class TestParseFeatures method testSampleAnnotation.

//    protected void setUp() throws Exception {
//        super.setUp();
//    }
@Test
public final void testSampleAnnotation() throws Exception {
    TextAnnotation ta = tas.get(annotatedTAIndex);
    if (!ta.toString().equals(annotatedString)) {
        logger.info("Text Annotation string: \n" + ta.toString());
        logger.info("Reference String: \n" + annotatedString);
        throw new Exception("The text in the Text Annotation doesn't match the Reference String");
    }
    if (!ta.hasView(ViewNames.SRL_VERB))
        throw new EdisonException("SRL_VERB view is missing");
}
Also used : EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) Test(org.junit.Test)

Example 30 with EdisonException

use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.

the class FeatureManifest method processConjunction.

private FeatureExtractor processConjunction(Tree<String> tree, Map<String, FeatureExtractor> cf) throws EdisonException {
    String uniqueLabel = uniquify(tree);
    if (cf.containsKey(uniqueLabel))
        return cf.get(uniqueLabel);
    if (tree.getNumberOfChildren() == 0) {
        throw new EdisonException("Invalid conjunction " + tree);
    }
    FeatureExtractor fex = createFex(tree.getChild(0), cf);
    for (int i = 1; i < tree.getNumberOfChildren(); i++) {
        fex = FeatureUtilities.conjoin(fex, createFex(tree.getChild(i), cf));
    }
    CachedFeatureCollection f = new CachedFeatureCollection("", fex);
    cf.put(uniqueLabel, f);
    return f;
}
Also used : WordNetFeatureExtractor(edu.illinois.cs.cogcomp.edison.features.factory.WordNetFeatureExtractor) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException)

Aggregations

EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)41 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)22 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)22 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)17 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)15 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)13 LinkedHashSet (java.util.LinkedHashSet)12 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)8 WordNetFeatureExtractor (edu.illinois.cs.cogcomp.edison.features.factory.WordNetFeatureExtractor)8 HashSet (java.util.HashSet)7 Test (org.junit.Test)6 Set (java.util.Set)5 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)4 ArrayList (java.util.ArrayList)4 RealFeature (edu.illinois.cs.cogcomp.edison.features.RealFeature)3 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)1 BrownClusterFeatureExtractor (edu.illinois.cs.cogcomp.edison.features.factory.BrownClusterFeatureExtractor)1