DM-357 - Save manual redactions for which we did not find an exact match #85
@ -47,25 +47,25 @@ public class CustomEntityCreationAdapter {
|
||||
}
|
||||
|
||||
|
||||
public List<RedactionEntity> toRedactionEntity(RedactionLog redactionLog, SemanticNode node) {
|
||||
public void toRedactionEntity(RedactionLog redactionLog, SemanticNode node) {
|
||||
|
||||
List<EntityIdentifier> entityIdentifiers = redactionLog.getRedactionLogEntry().stream().map(EntityIdentifier::fromRedactionLogEntry).toList();
|
||||
return toRedactionEntity(entityIdentifiers, node);
|
||||
toRedactionEntity(entityIdentifiers, node);
|
||||
}
|
||||
|
||||
|
||||
public List<RedactionEntity> createRedactionEntities(Set<ManualRedactionEntry> manualRedactionEntries, SemanticNode node) {
|
||||
public void createRedactionEntities(Set<ManualRedactionEntry> manualRedactionEntries, SemanticNode node) {
|
||||
|
||||
List<EntityIdentifier> entityIdentifiers = manualRedactionEntries.stream()
|
||||
.filter(manualRedactionEntry -> !(manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary()))
|
||||
.map(EntityIdentifier::fromManualRedactionEntry)
|
||||
.toList();
|
||||
|
||||
return toRedactionEntity(entityIdentifiers, node);
|
||||
toRedactionEntity(entityIdentifiers, node);
|
||||
}
|
||||
|
||||
|
||||
private List<RedactionEntity> toRedactionEntity(List<EntityIdentifier> entityIdentifiers, SemanticNode node) {
|
||||
private void toRedactionEntity(List<EntityIdentifier> entityIdentifiers, SemanticNode node) {
|
||||
|
||||
Set<Integer> pageNumbers = entityIdentifiers.stream().flatMap(entry -> entry.entityPosition().stream().map(RectangleWithPage::pageNumber)).collect(Collectors.toSet());
|
||||
Set<String> entryValues = entityIdentifiers.stream().map(EntityIdentifier::value).map(String::toLowerCase).collect(Collectors.toSet());
|
||||
@ -73,15 +73,14 @@ public class CustomEntityCreationAdapter {
|
||||
Map<String, List<RedactionEntity>> tempEntitiesByValue = findAllPossibleEntitiesAndGroupByValue(node, pageNumbers, entryValues);
|
||||
assert allValuesFound(tempEntitiesByValue, entryValues);
|
||||
|
||||
List<RedactionEntity> correctEntities = entityIdentifiers.stream()
|
||||
.map(entityIdentifier -> findClosestEntity(entityIdentifier, tempEntitiesByValue).map(tempEntity -> createCorrectEntity(entityIdentifier,
|
||||
node,
|
||||
tempEntity.getBoundary())))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.toList();
|
||||
entityIdentifiers.forEach(entityIdentifier -> {
|
||||
findClosestEntity(entityIdentifier, tempEntitiesByValue)
|
||||
.ifPresent(entities -> entities.forEach(redactionEntity -> {
|
||||
createCorrectEntity(entityIdentifier, node, redactionEntity.getBoundary());
|
||||
}));
|
||||
});
|
||||
|
||||
tempEntitiesByValue.values().stream().flatMap(Collection::stream).forEach(RedactionEntity::removeFromGraph);
|
||||
return correctEntities;
|
||||
}
|
||||
|
||||
|
||||
@ -91,9 +90,8 @@ public class CustomEntityCreationAdapter {
|
||||
* @param entityIdentifier The entity identifier for the RedactionEntity.
|
||||
* @param node The SemanticNode associated with the RedactionEntity.
|
||||
* @param closestBoundary The closest Boundary to the RedactionEntity.
|
||||
* @return The created correct RedactionEntity.
|
||||
*/
|
||||
private RedactionEntity createCorrectEntity(EntityIdentifier entityIdentifier, SemanticNode node, Boundary closestBoundary) {
|
||||
private void createCorrectEntity(EntityIdentifier entityIdentifier, SemanticNode node, Boundary closestBoundary) {
|
||||
|
||||
RedactionEntity correctEntity = entityCreationService.forceByBoundary(closestBoundary, entityIdentifier.type(), entityIdentifier.entityType, node);
|
||||
|
||||
@ -104,11 +102,10 @@ public class CustomEntityCreationAdapter {
|
||||
}
|
||||
correctEntity.setDictionaryEntry(entityIdentifier.isDictionaryEntry());
|
||||
correctEntity.setDossierDictionaryEntry(entityIdentifier.isDossierDictionaryEntry());
|
||||
return correctEntity;
|
||||
}
|
||||
|
||||
|
||||
private Optional<RedactionEntity> findClosestEntity(EntityIdentifier identifier, Map<String, List<RedactionEntity>> entitiesWithSameValue) {
|
||||
private Optional<List<RedactionEntity>> findClosestEntity(EntityIdentifier identifier, Map<String, List<RedactionEntity>> entitiesWithSameValue) {
|
||||
|
||||
List<RedactionEntity> possibleEntities = entitiesWithSameValue.get(identifier.value().toLowerCase(Locale.ROOT));
|
||||
|
||||
@ -123,7 +120,7 @@ public class CustomEntityCreationAdapter {
|
||||
|
||||
if (optionalClosestEntity.isEmpty()) {
|
||||
log.warn("No Entity with value {} found on page {}", identifier.value(), identifier.entityPosition());
|
||||
return optionalClosestEntity;
|
||||
return Optional.of(possibleEntities);
|
||||
}
|
||||
|
||||
RedactionEntity closestEntity = optionalClosestEntity.get();
|
||||
@ -134,10 +131,10 @@ public class CustomEntityCreationAdapter {
|
||||
MATCH_THRESHOLD,
|
||||
identifier.entityPosition(),
|
||||
closestEntity.getRedactionPositionsPerPage()));
|
||||
return Optional.empty();
|
||||
return Optional.of(possibleEntities);
|
||||
}
|
||||
|
||||
return Optional.of(closestEntity);
|
||||
return Optional.of(List.of(closestEntity));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user