Search in sources :

Example 6 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.

the class ClauseViewGeneratorTest method testClauseViewGenerator.

//    public void setUp() throws Exception {
//        super.setUp();
//    }
@Test
public final void testClauseViewGenerator() {
    String text = "Freeport-McMoRan Inc. said it will convert its Freeport-McMoRan Energy Partners Ltd. " + "partnership into a publicly traded company through the exchange of units of the partnership " + "for common shares .";
    TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString(text);
    Tree<String> tree = TreeParserFactory.getStringTreeParser().parse("(S1 (S (NP-SBJ (NNP Freeport-McMoRan)               (NNP Inc.))       (VP (VBD said)" + "           (SBAR (-NONE- 0)                 (S (NP-SBJ (PRP it))                    " + "(VP (MD will)                        (VP (VB convert)                            " + "(NP (PRP$ its)                                (NNP Freeport-McMoRan) " + "                               (NNP Energy)                                (NNPS Partners)" + "                                (NNP Ltd.)                                (NN partnership)) " + "                           (PP-CLR (IN into)                                    (NP (DT a)" + "                                        (ADJP (RB publicly)" + "                                              (VBN traded))" + "                                        (NN company))) " + "                           (PP-MNR (IN through) " + "                                   (NP (NP (DT the)    " + "                                        (NN exchange))    " + "                                    (PP (IN of)            " + "                                (NP (NP (NNS units))           " + "                                     (PP (IN of)                   " + "                                 (NP (DT the)                           " + "                             (NN partnership)))))                            " + "            (PP (IN for)                                            (NP (JJ common) " + "                                               (NNS shares))))))))))       (. .)))");
    TreeView parse = new TreeView("", ta);
    parse.setParseTree(0, tree);
    ta.addView(ViewNames.PARSE_GOLD, parse);
    ClauseViewGenerator clg = new ClauseViewGenerator(ViewNames.PARSE_GOLD, "clauses");
    try {
        ta.addView(clg);
    } catch (AnnotatorException e) {
        fail(e.getMessage());
    }
    logger.info(ta.getView("clauses").toString());
}
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 7 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException 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 8 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException 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 9 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.

the class PathLSTMHandler method addView.

@Override
public void addView(TextAnnotation ta) throws AnnotatorException {
    // Check if all required views are present
    try {
        View srlView = getSRL(ta);
        ta.addView(getViewName(), srlView);
    } catch (Exception e) {
        e.printStackTrace();
        throw new AnnotatorException(e.getMessage());
    }
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) DatastoreException(org.cogcomp.DatastoreException) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) IOException(java.io.IOException)

Example 10 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.

the class RunPipeline method RunPipelineWithCorpusReader.

public void RunPipelineWithCorpusReader(AnnotationReader reader) {
    Iterator<TextAnnotation> iter = reader.iterator();
    boolean replaceExistingViews = false;
    while (iter.hasNext()) {
        TextAnnotation ta = iter.next();
        try {
            ta = pipeline.annotateTextAnnotation(ta, replaceExistingViews);
        } catch (AnnotatorException e) {
            e.printStackTrace();
            logger.error("failed to preprocess ta with id '" + ta.getId() + "'.");
        }
        logger.debug("processed file (assumed this is TextAnnotation docid): '" + ta.getId() + "'");
    }
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)

Aggregations

AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)39 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)28 Test (org.junit.Test)14 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)11 IOException (java.io.IOException)8 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)7 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)6 FileNotFoundException (java.io.FileNotFoundException)6 ResourceManager (edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager)4 TextAnnotationBuilder (edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder)3 Tree (edu.illinois.cs.cogcomp.core.datastructures.trees.Tree)3 StatefulTokenizer (edu.illinois.cs.cogcomp.nlp.tokenizer.StatefulTokenizer)3 TokenizerTextAnnotationBuilder (edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder)3 Properties (java.util.Properties)3 AnnotatorService (edu.illinois.cs.cogcomp.annotation.AnnotatorService)2 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)2 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)2 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)2 Token (edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token)2