use of org.elasticsearch.service.opennlp.models.TextAnnotation in project elasticsearch-opennlp-plugin by spinscale.
the class SimpleNlpTest method testThatMultipleFindersWork.
@Test
public void testThatMultipleFindersWork() throws Exception {
loadFinders();
Map<String, Set<String>> namedEntities = Maps.newHashMap();
for (int si = 0; si < sentences.length; si++) {
List<TextAnnotation> allTextAnnotations = new ArrayList<TextAnnotation>();
String[] tokens = tokenizer.tokenize(sentences[si]);
for (int fi = 0; fi < finders.length; fi++) {
Span[] spans = finders[fi].find(tokens);
double[] probs = finders[fi].probs(spans);
for (int ni = 0; ni < spans.length; ni++) {
allTextAnnotations.add(new TextAnnotation(names[fi], spans[ni], probs[ni]));
}
}
removeConflicts(allTextAnnotations);
convertTextAnnotationsToNamedEntities(tokens, allTextAnnotations, namedEntities);
}
assertThat(namedEntities.get("person"), hasSize(3));
assertThat(namedEntities.get("person"), containsInAnyOrder("Nancy Reagan", "Reagan", "Joanne Drake"));
assertThat(namedEntities.get("location"), hasSize(3));
assertThat(namedEntities.get("location"), containsInAnyOrder("Los Angeles", "Santa Monica", "California"));
assertThat(namedEntities.get("date"), hasSize(1));
assertThat(namedEntities.get("date"), containsInAnyOrder("Sunday"));
}
Aggregations