Skip to content

Commit

Permalink
Fixed incorrect indexes in annotateEntities().
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed Jun 26, 2020
1 parent 38d02f1 commit 910a0ff
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -306,8 +306,16 @@ public List<EntityAnnotation> annotateEntities(EntityFormatConfiguration config)
try {
List<EntityAnnotation> annotationList = getAnnotations(segment.toString(), config);

entities.addAll(annotationList);
config.getWriter().write(insertSpans(annotationList, segment.toString(), config));

// These annotations have indexes relative to the start of the segment, not the start
// of the document. We correct that by adding the beginning index of the segment.
annotationList.stream().map(ann -> new EntityAnnotation(
ann.getToken(),
ann.getStart() + segment.getBegin(),
ann.getEnd() + segment.getBegin()
)).forEach(ann -> entities.add(ann));

} catch (IOException e) {
config.getWriter().write(segment.toString());
logger.warning(e.getMessage());
Expand Down

0 comments on commit 910a0ff

Please sign in to comment.