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 a092f992..70cc61a2 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 @@ -175,27 +175,27 @@ public class Section { @ThenAction - public void expandByRegEx(@Argument(ArgumentType.TYPE) String type, @Argument(ArgumentType.REGEX) String pattern, + public void expandByRegEx(@Argument(ArgumentType.TYPE) String type, @Argument(ArgumentType.REGEX) String suffixPattern, @Argument(ArgumentType.BOOLEAN) boolean patternCaseInsensitive, @Argument(ArgumentType.INTEGER) int group) { - expandByRegEx(type, pattern, patternCaseInsensitive, group, null); + expandByRegEx(type, suffixPattern, patternCaseInsensitive, group, null); } @ThenAction - public void expandByRegEx(@Argument(ArgumentType.TYPE) String type, @Argument(ArgumentType.REGEX) String pattern, + public void expandByRegEx(@Argument(ArgumentType.TYPE) String type, @Argument(ArgumentType.REGEX) String suffixPattern, @Argument(ArgumentType.BOOLEAN) boolean patternCaseInsensitive, @Argument(ArgumentType.INTEGER) int group, - @Argument(ArgumentType.REGEX) String withoutPattern) { + @Argument(ArgumentType.REGEX) String compiledValuePattern) { Pattern compiledWithoutPattern = null; - if (withoutPattern != null) { - compiledWithoutPattern = Patterns.getCompiledPattern(withoutPattern, patternCaseInsensitive); + if (compiledValuePattern != null) { + compiledWithoutPattern = Patterns.getCompiledPattern(compiledValuePattern, patternCaseInsensitive); } - Pattern compiledPattern = Patterns.getCompiledPattern(pattern, patternCaseInsensitive); + Pattern compiledPattern = Patterns.getCompiledPattern(suffixPattern, patternCaseInsensitive); Set expanded = new HashSet<>(); for (Entity entity : entities) { @@ -204,9 +204,9 @@ public class Section { continue; } - if (withoutPattern != null) { - Matcher matcherWithout = compiledWithoutPattern.matcher(entity.getWord()); - if (matcherWithout.find()) { + if (compiledValuePattern != null) { + Matcher matcherCompiledValuePattern = compiledWithoutPattern.matcher(entity.getWord()); + if (!matcherCompiledValuePattern.matches()) { continue; } } 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 007fea23..2ed23658 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 @@ -19,8 +19,8 @@ rule "0: Expand CBI Authors with firstname initials" when Section(matchesType("CBI_author") || matchesType("recommendation_CBI_author")) then - section.expandByRegEx("CBI_author", "(,? [A-Z]\\.?( ?[A-Z]\\.?)?( ?[A-Z]\\.?)?\\b\\.?)", false, 1, "[\\s]+"); - section.expandByRegEx("recommendation_CBI_author", "(,? [A-Z]\\.?( ?[A-Z]\\.?)?( ?[A-Z]\\.?)?\\b\\.?)", false, 1, "[\\s]+"); + section.expandByRegEx("CBI_author", "(,? [A-Z]\\.?( ?[A-Z]\\.?)?( ?[A-Z]\\.?)?\\b\\.?)", false, 1, "[^\\s]+"); + section.expandByRegEx("recommendation_CBI_author", "(,? [A-Z]\\.?( ?[A-Z]\\.?)?( ?[A-Z]\\.?)?\\b\\.?)", false, 1, "[^\\s]+"); end