DM-357 - Save manual redactions for which we did not find an exact match
This commit is contained in:
parent
1dc92c3534
commit
6db3ca0968
@ -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();
|
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()
|
List<EntityIdentifier> entityIdentifiers = manualRedactionEntries.stream()
|
||||||
.filter(manualRedactionEntry -> !(manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary()))
|
.filter(manualRedactionEntry -> !(manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary()))
|
||||||
.map(EntityIdentifier::fromManualRedactionEntry)
|
.map(EntityIdentifier::fromManualRedactionEntry)
|
||||||
.toList();
|
.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<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());
|
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);
|
Map<String, List<RedactionEntity>> tempEntitiesByValue = findAllPossibleEntitiesAndGroupByValue(node, pageNumbers, entryValues);
|
||||||
assert allValuesFound(tempEntitiesByValue, entryValues);
|
assert allValuesFound(tempEntitiesByValue, entryValues);
|
||||||
|
|
||||||
List<RedactionEntity> correctEntities = entityIdentifiers.stream()
|
entityIdentifiers.forEach(entityIdentifier -> {
|
||||||
.map(entityIdentifier -> findClosestEntity(entityIdentifier, tempEntitiesByValue).map(tempEntity -> createCorrectEntity(entityIdentifier,
|
findClosestEntity(entityIdentifier, tempEntitiesByValue)
|
||||||
node,
|
.ifPresent(entities -> entities.forEach(redactionEntity -> {
|
||||||
tempEntity.getBoundary())))
|
createCorrectEntity(entityIdentifier, node, redactionEntity.getBoundary());
|
||||||
.filter(Optional::isPresent)
|
}));
|
||||||
.map(Optional::get)
|
});
|
||||||
.toList();
|
|
||||||
tempEntitiesByValue.values().stream().flatMap(Collection::stream).forEach(RedactionEntity::removeFromGraph);
|
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 entityIdentifier The entity identifier for the RedactionEntity.
|
||||||
* @param node The SemanticNode associated with the RedactionEntity.
|
* @param node The SemanticNode associated with the RedactionEntity.
|
||||||
* @param closestBoundary The closest Boundary to 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);
|
RedactionEntity correctEntity = entityCreationService.forceByBoundary(closestBoundary, entityIdentifier.type(), entityIdentifier.entityType, node);
|
||||||
|
|
||||||
@ -104,11 +102,10 @@ public class CustomEntityCreationAdapter {
|
|||||||
}
|
}
|
||||||
correctEntity.setDictionaryEntry(entityIdentifier.isDictionaryEntry());
|
correctEntity.setDictionaryEntry(entityIdentifier.isDictionaryEntry());
|
||||||
correctEntity.setDossierDictionaryEntry(entityIdentifier.isDossierDictionaryEntry());
|
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));
|
List<RedactionEntity> possibleEntities = entitiesWithSameValue.get(identifier.value().toLowerCase(Locale.ROOT));
|
||||||
|
|
||||||
@ -123,7 +120,7 @@ public class CustomEntityCreationAdapter {
|
|||||||
|
|
||||||
if (optionalClosestEntity.isEmpty()) {
|
if (optionalClosestEntity.isEmpty()) {
|
||||||
log.warn("No Entity with value {} found on page {}", identifier.value(), identifier.entityPosition());
|
log.warn("No Entity with value {} found on page {}", identifier.value(), identifier.entityPosition());
|
||||||
return optionalClosestEntity;
|
return Optional.of(possibleEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
RedactionEntity closestEntity = optionalClosestEntity.get();
|
RedactionEntity closestEntity = optionalClosestEntity.get();
|
||||||
@ -134,10 +131,10 @@ public class CustomEntityCreationAdapter {
|
|||||||
MATCH_THRESHOLD,
|
MATCH_THRESHOLD,
|
||||||
identifier.entityPosition(),
|
identifier.entityPosition(),
|
||||||
closestEntity.getRedactionPositionsPerPage()));
|
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