Skip to content

Commit

Permalink
Merge pull request #1361 from dkpro/feature/1358-Improve-error-messag…
Browse files Browse the repository at this point in the history
…es-in-TSV3

#1358 - Improve error messages in TSV3
  • Loading branch information
reckart committed May 4, 2019
2 parents 9911dba + e9eb9ed commit 7097287
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 7097287

Please sign in to comment.