Search in sources :

Example 21 with EdisonException

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

the class FeatureManifest method trigrams.

private FeatureExtractor trigrams(Tree<String> tree, Map<String, FeatureExtractor> cf) throws EdisonException {
    String uniqueLabel = uniquify(tree);
    if (cf.containsKey(uniqueLabel))
        return cf.get(uniqueLabel);
    if (tree.getNumberOfChildren() != 1) {
        throw new EdisonException("trigrams takes exactly one argument\n" + tree);
    }
    FeatureExtractor fex = NgramFeatureExtractor.trigrams(getWordFex(createFex(tree.getChild(0), cf)));
    CachedFeatureCollection cfx = new CachedFeatureCollection("", fex);
    cf.put(uniquify(tree), cfx);
    return cfx;
}
Also used : WordNetFeatureExtractor(edu.illinois.cs.cogcomp.edison.features.factory.WordNetFeatureExtractor) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException)

Example 22 with EdisonException

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

the class TestParseFeatures method testFex.

private void testFex(FeatureExtractor fex, boolean printBoth, Set<String> validResponses) throws EdisonException {
    TextAnnotation ta = tas.get(annotatedTAIndex);
    if (!ta.hasView(ViewNames.SRL_VERB))
        throw new EdisonException("SRL_VERB view is missing");
    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);
            String response = (printBoth ? r : c) + "\t" + fex.getFeatures(c);
            assertTrue("Response should be one of the valid responses", validResponses.contains(response));
        }
    }
}
Also used : EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException)

Example 23 with EdisonException

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

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

the class LBJavaFeatureExtractor method classify.

@Override
public FeatureVector classify(Object o) {
    // Make sure the object is a Constituent
    if (!(o instanceof Constituent))
        throw new IllegalArgumentException("Instance must be of type Constituent");
    Constituent instance = (Constituent) o;
    FeatureVector featureVector;
    try {
        featureVector = FeatureUtilities.getLBJFeatures(getFeatures(instance));
    } catch (EdisonException e) {
        throw new RuntimeException(e);
    }
    return featureVector;
}
Also used : FeatureVector(edu.illinois.cs.cogcomp.lbjava.classify.FeatureVector) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 25 with EdisonException

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

the class TestLabelOneAfter method test.

public final void test() {
    logger.info("LabelOneAfter 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");
    logger.info("GOT TOKENS FROM TEXTAnn");
    List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20);
    for (Constituent c : testlist) {
        logger.info(c.getSurfaceForm());
    }
    logger.info("Testlist size is " + testlist.size());
    // Constituent test = testlist.get(1);
    // logger.info("The constituent we are extracting features from
    // in this test is: " + test.getSurfaceForm());
    // String fileName =
    // "C:\\Users\\Jason\\Desktop\\UIUC 2015 Fall\\Cogcomp\\pos-translation\\pos";
    POSBaseLineCounter posBaseLine = new POSBaseLineCounter("posBaseLine");
    try {
        posBaseLine.buildTable(TestPosHelper.corpus);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    POSMikheevCounter posMikheev = new POSMikheevCounter("posMikheev");
    try {
        posMikheev.buildTable(TestPosHelper.corpus);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    LabelOneAfter l1aPOS = new LabelOneAfter("l1aPOS");
    LabelOneAfter l1aPOSBaseLine = new LabelOneAfter("l1aPOSBaseLine", posBaseLine);
    LabelOneAfter l1aPOSMikheev = new LabelOneAfter("l1aPOSMikheev", posMikheev);
    // Test when using POS View
    ArrayList<Set<Feature>> featslist = new ArrayList<>();
    for (Constituent test : testlist) try {
        featslist.add(l1aPOS.getFeatures(test));
    } catch (EdisonException e) {
        fail(e.getMessage());
    }
    if (featslist.isEmpty()) {
        logger.info("Feats list is returning NULL.");
    }
    logger.info("\n" + "Test when using POS View");
    logger.info("Printing list of Feature set");
    for (Set<Feature> feats : featslist) {
        for (Feature f : feats) logger.info(f.getName());
    }
    // Test when using POS baseline Counting
    featslist.clear();
    for (Constituent test : testlist) try {
        featslist.add(l1aPOSBaseLine.getFeatures(test));
    } catch (EdisonException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    if (featslist.isEmpty()) {
        logger.info("Feats list is returning NULL.");
    }
    logger.info("\n" + "Test when using POS baseline Counting");
    logger.info("Printing list of Feature set");
    for (Set<Feature> feats : featslist) {
        for (Feature f : feats) logger.info(f.getName());
    }
    // Test when using POS Mikheev Counting
    featslist.clear();
    for (Constituent test : testlist) try {
        featslist.add(l1aPOSMikheev.getFeatures(test));
    } catch (EdisonException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    if (featslist.isEmpty()) {
        logger.info("Feats list is returning NULL.");
    }
    logger.info("\n" + "Test when using POS Mikheev Counting");
    logger.info("Printing list of Feature set");
    for (Set<Feature> feats : featslist) {
        for (Feature f : feats) logger.info(f.getName());
    }
    logger.info("GOT FEATURES YES!");
}
Also used : Set(java.util.Set) LabelOneAfter(edu.illinois.cs.cogcomp.edison.features.lrec.LabelOneAfter) ArrayList(java.util.ArrayList) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) POSBaseLineCounter(edu.illinois.cs.cogcomp.edison.utilities.POSBaseLineCounter) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) POSMikheevCounter(edu.illinois.cs.cogcomp.edison.utilities.POSMikheevCounter)

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