Avoid IndexOutOfBoundsException if dictionary entry has blank at end

This commit is contained in:
Dominique Eifländer 2021-01-07 16:20:51 +01:00
parent caf20e4776
commit e23ed69e04

View File

@ -29,15 +29,17 @@ public class EntitySearchUtils {
for (String value : values) { for (String value : values) {
if (value.trim().length() <= 2) { String cleanValue = value.trim();
if (cleanValue.length() <= 2) {
continue; continue;
} }
int startIndex; int startIndex;
int stopIndex = 0; int stopIndex = 0;
do { do {
startIndex = inputString.indexOf(value, stopIndex); startIndex = inputString.indexOf(cleanValue, stopIndex);
stopIndex = startIndex + value.length(); stopIndex = startIndex + cleanValue.length();
if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(inputString.charAt(startIndex - 1)) || isSeparator(inputString if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(inputString.charAt(startIndex - 1)) || isSeparator(inputString
.charAt(startIndex - 1))) && (stopIndex == inputString.length() || isSeparator(inputString.charAt(stopIndex)))) { .charAt(startIndex - 1))) && (stopIndex == inputString.length() || isSeparator(inputString.charAt(stopIndex)))) {
@ -70,7 +72,7 @@ public class EntitySearchUtils {
.sorted(Comparator.comparing(Entity::getStart)) .sorted(Comparator.comparing(Entity::getStart))
.collect(Collectors.toList()); .collect(Collectors.toList());
Entity firstEntity = orderedEntities.get(0); Entity firstEntity = orderedEntities.get(0);
List<EntityPositionSequence> positionSequences = text.getSequences(firstEntity.getWord(), dictionary.isCaseInsensitiveDictionary(firstEntity List<EntityPositionSequence> positionSequences = text.getSequences(firstEntity.getWord().trim(), dictionary.isCaseInsensitiveDictionary(firstEntity
.getType()), firstEntity.getTargetSequences()); .getType()), firstEntity.getTargetSequences());
for (int i = 0; i <= orderedEntities.size() - 1; i++) { for (int i = 0; i <= orderedEntities.size() - 1; i++) {