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;
}
}
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());
}
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);
}
}
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());
}
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.");
}
Aggregations