Improved readability of errors during sentence building in processing pipeline
@@ -148,6 +148,7 @@ public class SentenceBuilder {
* @return the Sentence resulting from the transformations on the original string
*/
public Sentence build() {
+ try {
/*List of the highest priority transformation that do not overlap
* and can therefore be all used to generate tokens*/
List<Transformation> tokenizableTransformations = this.getTokenizableTransformations();
@@ -158,13 +159,16 @@ public class SentenceBuilder {
List<Tag> tags = tokenSet.tags;
/*build the Sentence based on the words and tags lists */
- Sentence sentence = new Sentence(words.toArray(new Word[words.size()]), tags.toArray(new Tag[tags.size()]));
+ Sentence sentence = new Sentence(words.toArray(new Word[0]), tags.toArray(new Tag[0]));
/*set sentence annotations*/
if (!annotations.isEmpty())
sentence.addAnnotations(annotations);
return sentence;
+ } catch (RuntimeException e) {
+ throw new RuntimeException("Failed to build sentence for string: " + originalString, e);
+ }
}
@@ -181,7 +185,6 @@ public class SentenceBuilder {
* sorted by their start position on the original string
*/
private List<Transformation> getTokenizableTransformations() {
-
/*Create a bitset with as many bits as the positions in originalString
* the bitset is employed to remember, for each position in the original string,
* whether the corresponding character has been altered by a transformation or not*/
@@ -225,13 +228,7 @@ public class SentenceBuilder {
/*the tokenizable transformations list is sorted by increasing start position*/
- Collections.sort(tokenizableTransformations,
- new Comparator<Transformation>() {
- @Override
- public int compare(Transformation o1, Transformation o2) {
- return o1.start - o2.start;
- }
- });
+ tokenizableTransformations.sort(Comparator.comparingInt(o -> o.start));
return tokenizableTransformations;
}
