Search in sources :

Example 26 with AnnotatorException

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

the class NERAnnotatorTest method testResults.

/**
     * See if we get the right entities back. TODO: MS removed @Test annotation as this test
     * currently fails, but benchmark performance is good
     */
public void testResults() {
    TextAnnotation ta = tab.createTextAnnotation(TEST_INPUT);
    View view = null;
    try {
        view = getView(ta);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    for (Constituent c : view.getConstituents()) {
        assertTrue("No entity named \"" + c.toString() + "\"", entities.contains(c.toString()));
    }
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) 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)

Example 27 with AnnotatorException

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

the class NerOntonotesTest method testOntonotesNer.

@Test
public void testOntonotesNer() {
    TextAnnotationBuilder tab = new TokenizerTextAnnotationBuilder(new StatefulTokenizer());
    Properties props = new Properties();
    NERAnnotator nerOntonotes = NerAnnotatorManager.buildNerAnnotator(new ResourceManager(props), ViewNames.NER_ONTONOTES);
    TextAnnotation taOnto = tab.createTextAnnotation("", "", TEST_INPUT);
    try {
        nerOntonotes.getView(taOnto);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    View v = taOnto.getView(nerOntonotes.getViewName());
    assertEquals(v.getConstituents().size(), 4);
}
Also used : TextAnnotationBuilder(edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder) TokenizerTextAnnotationBuilder(edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder) TokenizerTextAnnotationBuilder(edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder) StatefulTokenizer(edu.illinois.cs.cogcomp.nlp.tokenizer.StatefulTokenizer) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) Properties(java.util.Properties) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Test(org.junit.Test)

Example 28 with AnnotatorException

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

the class SentencePipelineTest method testSentencePipeline.

@Test
public void testSentencePipeline() {
    String[] viewsToAdd = new String[] {};
    TextAnnotation ta = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, false, 3);
    String[] viewsToAnnotate = { ViewNames.POS, ViewNames.NER_CONLL, ViewNames.PARSE_STANFORD };
    Set<String> viewSet = new HashSet<>();
    for (String viewName : viewsToAnnotate) viewSet.add(viewName);
    try {
        sentenceProcessor.addViewsAndCache(ta, viewSet, false);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertTrue(ta.hasView(ViewNames.POS));
    assertEquals(29, ta.getView(ViewNames.POS).getConstituents().size());
    assertTrue(ta.hasView(ViewNames.NER_CONLL));
    assertEquals(1, ta.getView(ViewNames.NER_CONLL).getConstituents().size());
    assertTrue(ta.hasView(ViewNames.PARSE_STANFORD));
    assertEquals(84, ta.getView(ViewNames.PARSE_STANFORD).getConstituents().size());
    TextAnnotation normalTa = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, false, 3);
    try {
        normalProcessor.addViewsAndCache(normalTa, viewSet, false);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertTrue(normalTa.hasView(ViewNames.POS));
    assertEquals(29, normalTa.getView(ViewNames.POS).getConstituents().size());
    assertTrue(ta.hasView(ViewNames.NER_CONLL));
    assertEquals(1, ta.getView(ViewNames.NER_CONLL).getConstituents().size());
    assertTrue(ta.hasView(ViewNames.PARSE_STANFORD));
    assertEquals(84, ta.getView(ViewNames.PARSE_STANFORD).getConstituents().size());
    List<Constituent> sentPos = ta.getView(ViewNames.POS).getConstituents();
    List<Constituent> normalPos = normalTa.getView(ViewNames.POS).getConstituents();
    for (int i = 0; i < sentPos.size(); ++i) assertEquals(normalPos.get(i), sentPos.get(i));
    assertTrue(IOUtils.exists(CACHE_DIR_SENTENCE));
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 29 with AnnotatorException

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

the class ViewConstructorPipelineTest method testPosPipeline.

/**
     * NOTE: this test cannot be run as part of test suite as it tries to
     *   open a default cache already used elsewhere by other tests, which will
     *   not be closed properly. This test is useful to verify that the particular
     *   factory method works, but must be run separately.
     */
//    @Test
public void testPosPipeline() {
    String input = null;
    try {
        input = LineIO.slurp(textFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertFalse(input.length() == 0);
    AnnotatorService as = null;
    try {
        as = PipelineFactory.buildPipeline(ViewNames.POS);
    } catch (IOException | AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        as.createAnnotatedTextAnnotation("test", "test", input);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : AnnotatorService(edu.illinois.cs.cogcomp.annotation.AnnotatorService) FileNotFoundException(java.io.FileNotFoundException) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) IOException(java.io.IOException)

Example 30 with AnnotatorException

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

the class POSAnnotator method addView.

/**
     * annotates TextAnnotation with POS view and adds it to the TextAnnotation.
     *
     * @param record TextAnnotation to annotate
     */
@Override
public void addView(TextAnnotation record) throws AnnotatorException {
    if (!record.hasView(tokensfield) && !record.hasView(sentencesfield)) {
        throw new AnnotatorException("Record must be tokenized and sentence split first");
    }
    long startTime = System.currentTimeMillis();
    List<Token> input = LBJavaUtils.recordToLBJTokens(record);
    List<Constituent> tokens = record.getView(ViewNames.TOKENS).getConstituents();
    TokenLabelView posView = new TokenLabelView(ViewNames.POS, getAnnotatorName(), record, 1.0);
    int tcounter = 0;
    for (Token lbjtoken : input) {
        tagger.discreteValue(lbjtoken);
        Constituent token = tokens.get(tcounter);
        Constituent label = new Constituent(tagger.discreteValue(lbjtoken), ViewNames.POS, record, token.getStartSpan(), token.getEndSpan());
        posView.addConstituent(label);
        tcounter++;
    }
    long endTime = System.currentTimeMillis();
    logger.debug("Tagged input in {}ms", endTime - startTime);
    record.addView(ViewNames.POS, posView);
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) Token(edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token)

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