Skip to content

Commit

Permalink
#1358 - Improve error messages in TSV3
Browse files Browse the repository at this point in the history
- Improve error messages in TSV3 when an annotation cannot be persisted because it starts before the first token or ends beyond the last token.
  • Loading branch information
reckart committed May 3, 2019
1 parent aabcb2c commit 56437e9
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
Expand Down Expand Up @@ -133,8 +134,24 @@ public static TsvDocument of(TsvSchema aSchema, JCas aJCas)
end = targetFS.getEnd();
}

TsvToken beginToken = tokenBeginIndex.floorEntry(begin).getValue();
TsvToken endToken = tokenEndIndex.ceilingEntry(end).getValue();
Entry<Integer, TsvToken> beginTokenEntry = tokenBeginIndex.floorEntry(begin);
if (beginTokenEntry == null) {
throw new IllegalStateException(
"Unable to find begin token starting at or before " + begin
+ " (first token starts at "
+ tokenBeginIndex.pollFirstEntry().getKey()
+ ") for annotation: " + annotation);
}

Entry<Integer, TsvToken> endTokenEntry = tokenEndIndex.ceilingEntry(end);
if (endTokenEntry == null) {
throw new IllegalStateException("Unable to find end token ending at or after "
+ end + " (last token ends at " + tokenEndIndex.pollLastEntry().getKey()
+ ") for annotation: " + annotation);
}

TsvToken beginToken = beginTokenEntry.getValue();
TsvToken endToken = endTokenEntry.getValue();

// For zero-width annotations, the begin token must match the end token.
// Zero-width annotations between two directly adjacent tokens are always
Expand Down

0 comments on commit 56437e9

Please sign in to comment.