Pull request #97: Avoid IndexOutOfBoundsException if dictionary entry has blank at end

Merge in RED/redaction-service from IndexOutOfBoundsBlankFix to master

* commit 'e23ed69e04aa0507eee022cd590a51422a1b09d3':
  Avoid IndexOutOfBoundsException if dictionary entry has blank at end
This commit is contained in:
Dominique Eiflaender 2021-01-07 16:32:19 +01:00
commit a8fdfc4edd

View File

@ -29,15 +29,17 @@ public class EntitySearchUtils {
for (String value : values) {
if (value.trim().length() <= 2) {
String cleanValue = value.trim();
if (cleanValue.length() <= 2) {
continue;
}
int startIndex;
int stopIndex = 0;
do {
startIndex = inputString.indexOf(value, stopIndex);
stopIndex = startIndex + value.length();
startIndex = inputString.indexOf(cleanValue, stopIndex);
stopIndex = startIndex + cleanValue.length();
if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(inputString.charAt(startIndex - 1)) || isSeparator(inputString
.charAt(startIndex - 1))) && (stopIndex == inputString.length() || isSeparator(inputString.charAt(stopIndex)))) {
@ -70,7 +72,7 @@ public class EntitySearchUtils {
.sorted(Comparator.comparing(Entity::getStart))
.collect(Collectors.toList());
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());
for (int i = 0; i <= orderedEntities.size() - 1; i++) {