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