Search in sources :

Example 11 with AnnotatorException

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

the class MainServer method annotateText.

private static String annotateText(AnnotatorService finalPipeline, String text, String views, Logger logger) throws AnnotatorException {
    if (views == null || text == null) {
        return "The parameters 'text' and/or 'views' are not specified. Here is a sample input:  \n ?text=\"This is a sample sentence. I'm happy.\"&views=POS,NER";
    } else {
        logger.info("------------------------------");
        logger.info("Text: " + text);
        logger.info("Views to add: " + views);
        String[] viewsInArray = views.split(",");
        logger.info("Adding the basic annotations . . . ");
        TextAnnotation ta = finalPipeline.createBasicTextAnnotation("", "", text);
        for (String vuName : viewsInArray) {
            logger.info("Adding the view: ->" + vuName.trim() + "<-");
            try {
                finalPipeline.addView(ta, vuName.trim());
            } catch (Exception e) {
                e.printStackTrace();
            }
            printMemoryDetails(logger);
        }
        logger.info("Done adding the views. Deserializing the view now.");
        String output = SerializationHelper.serializeToJson(ta);
        logger.info("Done. Sending the result back. ");
        return output;
    }
}
Also used : TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) IOException(java.io.IOException) HelpScreenException(net.sourceforge.argparse4j.internal.HelpScreenException) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException)

Example 12 with AnnotatorException

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

the class CachingPipelineTest method stanfordFailTest.

@Test
public void stanfordFailTest() {
    String inputFile = "src/test/resources/stanfordFailExample.txt";
    String text = null;
    try {
        text = LineIO.slurp(inputFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    TextAnnotation basicTextAnnotation = null;
    try {
        basicTextAnnotation = processor.createBasicTextAnnotation("test", "test", text);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        processor.addView(basicTextAnnotation, ViewNames.DEPENDENCY_STANFORD);
    } catch (RuntimeException | AnnotatorException e) {
        e.printStackTrace();
        System.out.println("Expected exception from stanford.");
    }
    System.out.println(basicTextAnnotation.toString());
}
Also used : FileNotFoundException(java.io.FileNotFoundException) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)

Example 13 with AnnotatorException

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

the class TestDiff method testAnnotatorDiff.

@Test
public void testAnnotatorDiff() {
    POSAnnotator annotator = new POSAnnotator();
    TextAnnotation record = BasicTextAnnotationBuilder.createTextAnnotationFromTokens(refTokens);
    try {
        annotator.getView(record);
    } catch (AnnotatorException e) {
        fail("AnnotatorException thrown!\n" + e.getMessage());
    }
    TokenLabelView view = (TokenLabelView) record.getView(ViewNames.POS);
    if (refTags.size() != view.getNumberOfConstituents()) {
        fail("Number of tokens tagged in annotator does not match actual number of tokens!");
    }
    int correctCounter = 0;
    for (int i = 0; i < refTags.size(); i++) {
        if (view.getLabel(i).equals(refTags.get(i))) {
            correctCounter++;
        }
    }
    double result = ((double) correctCounter) / refTags.size();
    if (result < thresholdAcc) {
        fail("Tagger performance is insufficient: " + "\nProduced: " + result + "\nExpected: " + thresholdAcc);
    }
}
Also used : POSAnnotator(edu.illinois.cs.cogcomp.pos.POSAnnotator) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) TokenLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Test(org.junit.Test)

Example 14 with AnnotatorException

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

the class SentencePipelineTest method testFailingPosFile.

@Test
public void testFailingPosFile() {
    String text = null;
    try {
        text = LineIO.slurp(POS_FILE);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    TextAnnotation ta = null;
    try {
        ta = sentenceProcessor.createAnnotatedTextAnnotation("testPos", "tesPos", text);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    Constituent s = ta.getView(ViewNames.SENTENCE).getConstituents().get(3);
    List<Constituent> posConstituentsInThirdSent = ta.getView(ViewNames.POS).getConstituentsOverlappingCharSpan(s.getStartCharOffset(), s.getEndCharOffset());
    List<Constituent> toksInThirdSent = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(s.getStartCharOffset(), s.getEndCharOffset());
    assertTrue(posConstituentsInThirdSent.size() > 0);
    assertEquals(toksInThirdSent.size(), posConstituentsInThirdSent.size());
}
Also used : FileNotFoundException(java.io.FileNotFoundException) 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 15 with AnnotatorException

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

the class ViewConstructorPipelineTest method main.

public static void main(String[] args) {
    String input = null;
    try {
        input = LineIO.slurp(textFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    System.out.println("input from " + textFile + " is " + input.length() + " characters long.");
    AnnotatorService as = null;
    try {
        as = PipelineFactory.buildPipeline(ViewNames.POS);
    } catch (IOException | AnnotatorException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    TextAnnotation ta = null;
    try {
        ta = as.createAnnotatedTextAnnotation("test", "test", input);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    System.out.println("found " + ta.getView(ViewNames.POS).getConstituents() + " POS constituents.");
}
Also used : AnnotatorService(edu.illinois.cs.cogcomp.annotation.AnnotatorService) FileNotFoundException(java.io.FileNotFoundException) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) IOException(java.io.IOException) 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