Pull request #292: RED-3059: Fixed inital expansion overlaps

Merge in RED/redaction-service from RED-3059-port to master

* commit '0e21e5b4d988d43040573a4fc71547829c815ec0':
  RED-3059: Fixed inital expansion overlaps
This commit is contained in:
Dominique Eiflaender 2021-12-10 11:37:24 +01:00
commit a2c57b94a2
5 changed files with 50 additions and 10 deletions

View File

@ -193,15 +193,35 @@ public class EntitySearchUtils {
Set<Entity> result = new HashSet<>(); Set<Entity> result = new HashSet<>();
if (existingEntities != null && foundEntities != null) { if (existingEntities != null && foundEntities != null) {
for (Entity existingEntity : existingEntities) { for (Entity foundEntity : foundEntities) {
for (Entity foundEntity : foundEntities) {
if (existingEntity.getEnd() < foundEntity.getStart() || foundEntity.getEnd() < existingEntity.getStart()) { if (!overlaps(existingEntities, foundEntity)) {
result.add(foundEntity); result.add(foundEntity);
}
} }
} }
} }
return result; return result;
} }
private boolean overlaps(Set<Entity> existingEntities, Entity found) {
for (Entity existing : existingEntities) {
if(existing.getStart().equals(found.getStart())){
continue;
}
for (int i = existing.getStart(); i <= existing.getEnd(); i++) {
for (int j = found.getStart(); j <= found.getEnd(); j++) {
if (i == j) {
return true;
}
}
}
}
return false;
}
} }

View File

@ -611,6 +611,23 @@ public class RedactionIntegrationTest {
} }
@Test
public void redactionExpansionOverlap() throws IOException {
ClassPathResource pdfFileResource = new ClassPathResource("files/Minimal Examples/ExpansionTest.pdf");
AnalyzeRequest request = prepareStorage(pdfFileResource.getInputStream());
analyzeService.analyzeDocumentStructure(new StructureAnalyzeRequest(request.getDossierId(), request.getFileId()));
AnalyzeResult result = analyzeService.analyze(request);
var redactionLog = redactionStorageService.getRedactionLog(TEST_DOSSIER_ID, TEST_FILE_ID);
var values = redactionLog.getRedactionLogEntry().stream().map(RedactionLogEntry::getValue).collect(Collectors.toList());
assertThat(values).containsExactlyInAnyOrder("Lastname M.", "Doe", "Doe J.", "M. Mustermann", "Mustermann M.", "F. Lastname");
}
@Test @Test
@Ignore @Ignore
public void noExceptionShouldBeThrownForAnyFiles() throws IOException { public void noExceptionShouldBeThrownForAnyFiles() throws IOException {

View File

@ -151,8 +151,7 @@ public class EntitySearchUtilsTest {
Set<Entity> result = EntitySearchUtils.findNonOverlappingMatchEntities(existingEntities, foundEntities); Set<Entity> result = EntitySearchUtils.findNonOverlappingMatchEntities(existingEntities, foundEntities);
// Assert // Assert
assertThat(result.size()).isEqualTo(1); assertThat(result.size()).isEqualTo(0);
assertThat(result).contains(foundEntities2);
} }
@ -182,8 +181,7 @@ public class EntitySearchUtilsTest {
Set<Entity> result = EntitySearchUtils.findNonOverlappingMatchEntities(existingEntities, foundEntities); Set<Entity> result = EntitySearchUtils.findNonOverlappingMatchEntities(existingEntities, foundEntities);
// Assert // Assert
assertThat(result.size()).isEqualTo(1); assertThat(result.size()).isEqualTo(0);
assertThat(result).contains(foundEntities2);
} }

View File

@ -8616,3 +8616,8 @@ Zoriki Hosomi Rosana
Zuberer D Zuberer D
Zubrod J Zubrod J
Zwicker R.E. Zwicker R.E.
Doe
M. Mustermann
F. Lastname
Mustermann
Lastname