RED-6411 - extend logic when replacing entities with higher rank

This commit is contained in:
Thomas Beyer 2023-03-27 12:49:33 +02:00
parent 459af9e33b
commit 7644afc3aa

View File

@ -273,14 +273,14 @@ public final class EntitySearchUtils {
existing.setLegalBasis(found.getLegalBasis()); existing.setLegalBasis(found.getLegalBasis());
existing.setMatchedRule(found.getMatchedRule()); existing.setMatchedRule(found.getMatchedRule());
existing.setRedactionReason(found.getRedactionReason()); existing.setRedactionReason(found.getRedactionReason());
if (existing.getEntityType().equals(EntityType.RECOMMENDATION) && found.getEntityType().equals(EntityType.ENTITY) || existing.getEntityType() if (isOneARecommendationAndTheOtherEntity(found, existing)) {
.equals(EntityType.ENTITY) && found.getEntityType().equals(EntityType.RECOMMENDATION)) {
existing.setEntityType(EntityType.ENTITY); existing.setEntityType(EntityType.ENTITY);
if (found.isRedaction()) { if (found.isRedaction()) {
existing.setRedaction(true); existing.setRedaction(true);
} }
} }
} else if (dictionary.getDictionaryRank(existing.getType()) <= dictionary.getDictionaryRank(found.getType())) { } else if (dictionary.getDictionaryRank(existing.getType()) <= dictionary.getDictionaryRank(found.getType()) &&
!(isOneARecommendationAndTheOtherEntity(found, existing) && existing.isRedaction() && found.isRedaction()) ) {
entities.remove(found); entities.remove(found);
entities.add(found); entities.add(found);
} }
@ -290,6 +290,13 @@ public final class EntitySearchUtils {
} }
private boolean isOneARecommendationAndTheOtherEntity (Entity found, Entity existing) {
return existing.getEntityType().equals(EntityType.RECOMMENDATION) && found.getEntityType().equals(EntityType.ENTITY) || existing.getEntityType()
.equals(EntityType.ENTITY) && found.getEntityType().equals(EntityType.RECOMMENDATION);
}
public void addEntitiesIgnoreRank(Set<Entity> entities, Set<Entity> found) { public void addEntitiesIgnoreRank(Set<Entity> entities, Set<Entity> found) {
// HashSet keeps old value but we want the new. // HashSet keeps old value but we want the new.
entities.removeAll(found); entities.removeAll(found);