From bdc231f3c25aa9e3c1d4e77e62293bca90824b30 Mon Sep 17 00:00:00 2001 From: deiflaender Date: Wed, 18 Nov 2020 13:29:33 +0100 Subject: [PATCH] RED-473: Fixed missing batched produced at annotation --- .../v1/server/redaction/model/Section.java | 24 +++++++++++++------ .../src/test/resources/drools/rules.drl | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java index 7678ad92..d519bf06 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java @@ -94,6 +94,12 @@ public class Section { } + public void addHintAnnotation(String value, String asType){ + Set found = findEntities(value.trim(), asType, true); + entities.addAll(found); + } + + public void redactLineAfter(String start, String asType, int ruleNumber, String reason, String legalBasis) { String[] values = StringUtils.substringsBetween(text, start, "\n"); @@ -101,7 +107,7 @@ public class Section { if (values != null) { for (String value : values) { if (StringUtils.isNotBlank(value)) { - Set found = findEntities(value.trim(), asType); + Set found = findEntities(value.trim(), asType, false); entities.addAll(found); } } @@ -127,7 +133,7 @@ public class Section { if (values != null) { for (String value : values) { if (StringUtils.isNotBlank(value)) { - Set found = findEntities(value.trim(), asType); + Set found = findEntities(value.trim(), asType, false); entities.addAll(found); } } @@ -145,18 +151,22 @@ public class Section { } - private Set findEntities(String value, String asType) { + private Set findEntities(String value, String asType, boolean caseinsensitive) { Set found = new HashSet<>(); + String text = caseinsensitive ? searchText.toLowerCase() : searchText; + String searchValue = caseinsensitive ? value.toLowerCase() : value; + + int startIndex; int stopIndex = 0; do { - startIndex = searchText.indexOf(value, stopIndex); - stopIndex = startIndex + value.length(); + startIndex = text.indexOf(searchValue, stopIndex); + stopIndex = startIndex + searchValue.length(); - if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(searchText.charAt(startIndex - 1)) || isSeparator( - searchText.charAt(startIndex - 1))) && (stopIndex == searchText.length() || isSeparator(searchText.charAt( + if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(text.charAt(startIndex - 1)) || isSeparator( + text.charAt(startIndex - 1))) && (stopIndex == text.length() || isSeparator(text.charAt( stopIndex)))) { found.add(new Entity(searchText.substring(startIndex, stopIndex), asType, diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules.drl index 99477701..44498439 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules.drl @@ -80,7 +80,6 @@ rule "7: Redact contact information if Producer is found" when Section(text.toLowerCase().contains("producer of the plant protection") || text.toLowerCase().contains("producer of the active substance") || text.contains("Manufacturer of the active substance") || text.contains("Manufacturer:") || text.contains("Producer or producers of the active substance")) then - section.redactLineAfter("Contact:", "address", 7, "Producer was found", "Reg (EC) No 1107/2009 Art. 63 (2g)"); section.redactLineAfter("Contact:", "address", 7, "Producer was found", "Reg (EC) No 1107/2009 Art. 63 (2g)"); section.redactLineAfter("Telephone:", "address", 7, "Producer was found", "Reg (EC) No 1107/2009 Art. 63 (2g)"); section.redactLineAfter("Phone:", "address", 7, "Producer was found", "Reg (EC) No 1107/2009 Art. 63 (2g)"); @@ -128,4 +127,5 @@ rule "11: Redact sponsor company" Section(searchText.toLowerCase().contains("batches produced at")) then section.redactIfPrecededBy("batches produced at", "sponsor", 11, "Redacted because it represents a sponsor company", "Reg (EC) No 1107/2009 Art. 63 (2g)"); + section.addHintAnnotation("batches produced at", "must_redact"); end \ No newline at end of file