Search in sources :

Example 41 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 42 with Constituent

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

the class SimpleGazetteerAnnotatorTest method testMultiThreading.

/**
 * Test method for
 * {@link edu.illinois.cs.cogcomp.edison.annotators.SimpleGazetteerAnnotator#addView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)}
 * .
 *
 * @throws URISyntaxException
 * @throws IOException
 * @throws AnnotatorException
 */
@Test
public void testMultiThreading() throws IOException, URISyntaxException, AnnotatorException {
    final SimpleGazetteerAnnotator sga = new SimpleGazetteerAnnotator(defaultRm);
    class TestThread extends Thread {

        Throwable throwable;

        public void run() {
            long start = System.currentTimeMillis();
            while (true) {
                final TextAnnotation ta = tab.createTextAnnotation("I hail from the university of illinois at champaign urbana.");
                try {
                    sga.addView(ta);
                } catch (AnnotatorException e) {
                    throwable = e;
                    return;
                }
                SpanLabelView view = (SpanLabelView) ta.getView(ViewNames.TREE_GAZETTEER);
                List<Constituent> entities = view.getConstituents();
                Constituent c1 = entities.get(0);
                try {
                    assertEquals(c1.toString(), "university of illinois");
                    Constituent c2 = entities.get(1);
                    assertEquals(c2.toString(), "university of illinois at champaign urbana");
                    Constituent c3 = entities.get(2);
                    assertEquals(c3.toString(), "illinois");
                    Constituent c4 = entities.get(3);
                    assertEquals(c4.toString(), "champaign");
                    Constituent c5 = entities.get(4);
                    assertEquals(c5.toString(), "urbana");
                    assertEquals(c1.getLabel(), "organizations(IC)");
                    assertEquals(c2.getLabel(), "organizations(IC)");
                    assertEquals(c3.getLabel(), "places(IC)");
                    assertEquals(c4.getLabel(), "places(IC)");
                    assertEquals(c5.getLabel(), "places(IC)");
                    if ((System.currentTimeMillis() - start) > 10000l) {
                        // run for one minute.
                        throwable = null;
                        return;
                    }
                } catch (AssertionError ae) {
                    throwable = ae;
                    ae.printStackTrace();
                    return;
                }
            }
        }
    }
    final int numthreads = 20;
    TestThread[] threads = new TestThread[numthreads];
    for (int i = 0; i < numthreads; i++) {
        threads[i] = new TestThread();
        threads[i].start();
    }
    logger.info("Begin multithreaded test.");
    for (int i = 0; i < numthreads; i++) {
        while (true) try {
            threads[i].join();
            assertEquals("Exception during multithreading test : " + threads[i].throwable, threads[i].throwable, null);
            break;
        } catch (InterruptedException e) {
            continue;
        }
    }
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 43 with Constituent

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

the class TestLabelOneBefore method test.

public final void test() throws Exception {
    logger.info("LabelOneBefore 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());
    POSBaseLineCounter posBaseLine = new POSBaseLineCounter("posBaseLine");
    posBaseLine.buildTable(TestPosHelper.corpus);
    POSMikheevCounter posMikheev = new POSMikheevCounter("posMikheev");
    posMikheev.buildTable(TestPosHelper.corpus);
    LabelOneBefore l1bPOS = new LabelOneBefore("l1bPOS");
    LabelOneBefore l1bPOSBaseLine = new LabelOneBefore("l1bPOSBaseLine", posBaseLine);
    LabelOneBefore l1bPOSMikheev = new LabelOneBefore("l1bPOSMikheev", posMikheev);
    // Test when using POS View
    ArrayList<Set<Feature>> featslist = new ArrayList<>();
    for (Constituent test : testlist) featslist.add(l1bPOS.getFeatures(test));
    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) featslist.add(l1bPOSBaseLine.getFeatures(test));
    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) featslist.add(l1bPOSMikheev.getFeatures(test));
    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) ArrayList(java.util.ArrayList) LabelOneBefore(edu.illinois.cs.cogcomp.edison.features.lrec.LabelOneBefore) 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) POSBaseLineCounter(edu.illinois.cs.cogcomp.edison.utilities.POSBaseLineCounter) POSMikheevCounter(edu.illinois.cs.cogcomp.edison.utilities.POSMikheevCounter)

Example 44 with Constituent

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

the class ClausIEAnnotator method addView.

@Override
protected void addView(TextAnnotation ta) throws AnnotatorException {
    assert ta.hasView(ViewNames.SENTENCE) : "Sentences view didn't find . . . ";
    List<Constituent> sentences = ta.getView(ViewNames.SENTENCE).getConstituents();
    View vu = new View(viewName, "ClausIEAnnotator", ta, 1.0);
    assert sentences.size() == ta.getNumberOfSentences();
    for (Constituent sent : sentences) {
        String[] clausieResults = ClausieSplitter.split(sent.getSurfaceForm());
        Constituent sentenceCons = new Constituent("sent-" + sent.getSentenceId(), viewName, ta, sent.getStartSpan(), sent.getEndSpan());
        int propId = 0;
        for (String clausieSent : clausieResults) {
            sentenceCons.addAttribute("clauseIe:" + propId, clausieSent);
            propId++;
        }
        vu.addConstituent(sentenceCons);
    }
    ta.addView(viewName, vu);
}
Also used : View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 45 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)

Aggregations

Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)227 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)121 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)66 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)44 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)37 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)28 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)25 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)22 LinkedHashSet (java.util.LinkedHashSet)22 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)21 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)20 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)18 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)18 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 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)14 HashSet (java.util.HashSet)13