From 574a3d0717354322232e8a3b6f0a81ad55e73356 Mon Sep 17 00:00:00 2001 From: Kilian Schuettler Date: Wed, 5 Jul 2023 17:55:29 +0200 Subject: [PATCH] RED-6929: fix acceptance tests/rules * updated rule files --- .../src/test/resources/drools/all_rules.drl | 31 ++++++++++------ .../src/test/resources/drools/rules.drl | 37 +++++++++++++------ 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_rules.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_rules.drl index c41c0240..e4c9eb39 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_rules.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_rules.drl @@ -246,7 +246,6 @@ rule "CBI.5.0: Redact Names and Addresses if no_redaction_indicator but also red then $section.getEntitiesOfType(List.of("CBI_author", "CBI_address")) .forEach(entity -> { - entity.addEngine(Engine.RULE); entity.applyWithReferences( "CBI.5.0", "no_redaction_indicator but also redaction_indicator found", @@ -264,10 +263,9 @@ rule "CBI.5.1: Redact Names and Addresses if no_redaction_indicator but also red hasEntitiesOfType("redaction_indicator"), (hasEntitiesOfType("CBI_author") || hasEntitiesOfType("CBI_address"))) then - $table.streamEntitiesWhereRowContainsEntitiesOfType(List.of("redaction_indicator", "no-redaction_indicator")) + $table.streamEntitiesWhereRowContainsEntitiesOfType(List.of("redaction_indicator", "no_redaction_indicator")) .filter(entity -> entity.getType().equals("CBI_author") || entity.getType().equals("CBI_address")) .forEach(entity -> { - entity.addEngine(Engine.RULE); entity.applyWithReferences( "CBI.5.1", "no_redaction_indicator but also redaction_indicator found", @@ -290,7 +288,6 @@ rule "CBI.6.0: Don't redact Names and Addresses if vertebrate but also published then $section.getEntitiesOfType(List.of("CBI_author", "CBI_address")) .forEach(entity -> { - entity.addEngine(Engine.RULE); entity.skipWithReferences( "CBI.6.0", "vertebrate but also published_information found", @@ -307,10 +304,9 @@ rule "CBI.6.1: Don't redact Names and Addresses if vertebrate but also published hasEntitiesOfType("published_information"), (hasEntitiesOfType("CBI_author") || hasEntitiesOfType("CBI_address"))) then - $table.streamEntitiesWhereRowContainsEntitiesOfType(List.of("redaction_indicator", "no-redaction_indicator")) + $table.streamEntitiesWhereRowContainsEntitiesOfType(List.of("vertebrate", "published_information")) .filter(entity -> entity.getType().equals("CBI_author") || entity.getType().equals("CBI_address")) .forEach(entity -> { - entity.addEngine(Engine.RULE); entity.skipWithReferences( "CBI.6.1", "vertebrate but also published_information found", @@ -1229,8 +1225,9 @@ rule "ETC.5.0: Ignore dossier_redaction entries if confidentiality is not 'confi not FileAttribute(label == "Confidentiality", value == "confidential") $dossierRedaction: RedactionEntity(type == "dossier_redaction") then - $dossierRedaction.removeFromGraph(); - retract($dossierRedaction); + $dossierRedaction.setIgnored(true); + update($dossierRedaction); + $dossierRedaction.getIntersectingNodes().forEach(node -> update(node)); end @@ -1334,6 +1331,7 @@ rule "MAN.0.0: Apply manual resize redaction" manualRedactionApplicationService.resizeEntityAndReinsert($entityToBeResized, $resizeRedaction); retract($resizeRedaction); update($entityToBeResized); + $entityToBeResized.getIntersectingNodes().forEach(node -> update(node)); end @@ -1369,11 +1367,14 @@ rule "MAN.1.1: Apply id removals that are valid and not in forced redactions to rule "MAN.2.0: Apply force redaction" salience 128 when - ManualForceRedaction($id: annotationId, status == AnnotationStatus.APPROVED, requestDate != null, $legalBasis: legalBasis) + $force: ManualForceRedaction($id: annotationId, status == AnnotationStatus.APPROVED, requestDate != null, $legalBasis: legalBasis) $entityToForce: RedactionEntity(matchesAnnotationId($id)) then $entityToForce.apply("MAN.2.0", "Forced redaction", $legalBasis); $entityToForce.setSkipRemoveEntitiesContainedInLarger(true); + update($entityToForce); + retract($force); + $entityToForce.getIntersectingNodes().forEach(node -> update(node)); end @@ -1381,10 +1382,13 @@ rule "MAN.2.0: Apply force redaction" rule "MAN.3.0: Apply image recategorization" salience 128 when - ManualImageRecategorization($id: annotationId, status == AnnotationStatus.APPROVED, $imageType: type) - $image: Image($id == id) + $recategorization: ManualImageRecategorization($id: annotationId, status == AnnotationStatus.APPROVED, $imageType: type) + $imageToBeRecategorized: Image($id == id) then - $image.setImageType(ImageType.fromString($imageType)); + $imageToBeRecategorized.setImageType(ImageType.fromString($imageType)); + update($imageToBeRecategorized); + retract($recategorization); + update($imageToBeRecategorized.getParent()); end @@ -1415,6 +1419,7 @@ rule "X.1.0: merge intersecting Entities of same type" retract($first); retract($second); insert(mergedEntity); + mergedEntity.getIntersectingNodes().forEach(node -> update(node)); end @@ -1425,6 +1430,7 @@ rule "X.2.0: remove Entity of type ENTITY when contained by FALSE_POSITIVE" $falsePositive: RedactionEntity($type: type, entityType == EntityType.FALSE_POSITIVE) $entity: RedactionEntity(containedBy($falsePositive), type == $type, entityType == EntityType.ENTITY, !resized, !skipRemoveEntitiesContainedInLarger) then + $entity.getIntersectingNodes().forEach(node -> update(node)); $entity.removeFromGraph(); retract($entity) end @@ -1474,6 +1480,7 @@ rule "X.6.0: remove Entity of lower rank, when intersected by entity of type ENT $higherRank: RedactionEntity($type: type, entityType == EntityType.ENTITY) $lowerRank: RedactionEntity(intersects($higherRank), type != $type, dictionary.getDictionaryRank(type) < dictionary.getDictionaryRank($type), !resized, !skipRemoveEntitiesContainedInLarger) then + $lowerRank.getIntersectingNodes().forEach(node -> update(node)); $lowerRank.removeFromGraph(); retract($lowerRank); end 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 57c5e799..00a2d7ff 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 @@ -184,7 +184,6 @@ rule "CBI.5.0: Redact Names and Addresses if no_redaction_indicator but also red then $section.getEntitiesOfType(List.of("CBI_author", "CBI_address")) .forEach(entity -> { - entity.addEngine(Engine.RULE); entity.applyWithReferences( "CBI.5.0", "no_redaction_indicator but also redaction_indicator found", @@ -202,10 +201,9 @@ rule "CBI.5.1: Redact Names and Addresses if no_redaction_indicator but also red hasEntitiesOfType("redaction_indicator"), (hasEntitiesOfType("CBI_author") || hasEntitiesOfType("CBI_address"))) then - $table.streamEntitiesWhereRowContainsEntitiesOfType(List.of("redaction_indicator", "no-redaction_indicator")) + $table.streamEntitiesWhereRowContainsEntitiesOfType(List.of("redaction_indicator", "no_redaction_indicator")) .filter(entity -> entity.getType().equals("CBI_author") || entity.getType().equals("CBI_address")) .forEach(entity -> { - entity.addEngine(Engine.RULE); entity.applyWithReferences( "CBI.5.1", "no_redaction_indicator but also redaction_indicator found", @@ -909,8 +907,9 @@ rule "ETC.5.0: Ignore dossier_redaction entries if confidentiality is not 'confi not FileAttribute(label == "Confidentiality", value == "confidential") $dossierRedaction: RedactionEntity(type == "dossier_redaction") then - $dossierRedaction.removeFromGraph(); - retract($dossierRedaction); + $dossierRedaction.setIgnored(true); + update($dossierRedaction); + $dossierRedaction.getIntersectingNodes().forEach(node -> update(node)); end @@ -1001,6 +1000,7 @@ rule "MAN.0.0: Apply manual resize redaction" manualRedactionApplicationService.resizeEntityAndReinsert($entityToBeResized, $resizeRedaction); retract($resizeRedaction); update($entityToBeResized); + $entityToBeResized.getIntersectingNodes().forEach(node -> update(node)); end @@ -1008,21 +1008,27 @@ rule "MAN.0.0: Apply manual resize redaction" rule "MAN.1.0: Apply id removals that are valid and not in forced redactions to Entity" salience 128 when - IdRemoval(status == AnnotationStatus.APPROVED, !removeFromDictionary, requestDate != null, $id: annotationId) + $idRemoval: IdRemoval(status == AnnotationStatus.APPROVED, !removeFromDictionary, requestDate != null, $id: annotationId) not ManualForceRedaction($id == annotationId, status == AnnotationStatus.APPROVED, requestDate != null) $entityToBeRemoved: RedactionEntity(matchesAnnotationId($id)) then $entityToBeRemoved.setIgnored(true); + update($entityToBeRemoved); + retract($idRemoval); + $entityToBeRemoved.getIntersectingNodes().forEach(node -> update(node)); end rule "MAN.1.1: Apply id removals that are valid and not in forced redactions to Image" salience 128 when - IdRemoval(status == AnnotationStatus.APPROVED, !removeFromDictionary, requestDate != null, $id: annotationId) + $idRemoval: IdRemoval(status == AnnotationStatus.APPROVED, !removeFromDictionary, requestDate != null, $id: annotationId) not ManualForceRedaction($id == annotationId, status == AnnotationStatus.APPROVED, requestDate != null) $imageEntityToBeRemoved: Image($id == id) then $imageEntityToBeRemoved.setIgnored(true); + update($imageEntityToBeRemoved); + retract($idRemoval); + update($imageEntityToBeRemoved.getParent()); end @@ -1030,11 +1036,14 @@ rule "MAN.1.1: Apply id removals that are valid and not in forced redactions to rule "MAN.2.0: Apply force redaction" salience 128 when - ManualForceRedaction($id: annotationId, status == AnnotationStatus.APPROVED, requestDate != null, $legalBasis: legalBasis) + $force: ManualForceRedaction($id: annotationId, status == AnnotationStatus.APPROVED, requestDate != null, $legalBasis: legalBasis) $entityToForce: RedactionEntity(matchesAnnotationId($id)) then $entityToForce.apply("MAN.2.0", "Forced redaction", $legalBasis); $entityToForce.setSkipRemoveEntitiesContainedInLarger(true); + update($entityToForce); + retract($force); + $entityToForce.getIntersectingNodes().forEach(node -> update(node)); end @@ -1042,10 +1051,13 @@ rule "MAN.2.0: Apply force redaction" rule "MAN.3.0: Apply image recategorization" salience 128 when - ManualImageRecategorization($id: annotationId, status == AnnotationStatus.APPROVED, $imageType: type) - $image: Image($id == id) + $recategorization: ManualImageRecategorization($id: annotationId, status == AnnotationStatus.APPROVED, $imageType: type) + $imageToBeRecategorized: Image($id == id) then - $image.setImageType(ImageType.fromString($imageType)); + $imageToBeRecategorized.setImageType(ImageType.fromString($imageType)); + update($imageToBeRecategorized); + retract($recategorization); + update($imageToBeRecategorized.getParent()); end @@ -1076,6 +1088,7 @@ rule "X.1.0: merge intersecting Entities of same type" retract($first); retract($second); insert(mergedEntity); + mergedEntity.getIntersectingNodes().forEach(node -> update(node)); end @@ -1086,6 +1099,7 @@ rule "X.2.0: remove Entity of type ENTITY when contained by FALSE_POSITIVE" $falsePositive: RedactionEntity($type: type, entityType == EntityType.FALSE_POSITIVE) $entity: RedactionEntity(containedBy($falsePositive), type == $type, entityType == EntityType.ENTITY, !resized, !skipRemoveEntitiesContainedInLarger) then + $entity.getIntersectingNodes().forEach(node -> update(node)); $entity.removeFromGraph(); retract($entity) end @@ -1135,6 +1149,7 @@ rule "X.6.0: remove Entity of lower rank, when intersected by entity of type ENT $higherRank: RedactionEntity($type: type, entityType == EntityType.ENTITY) $lowerRank: RedactionEntity(intersects($higherRank), type != $type, dictionary.getDictionaryRank(type) < dictionary.getDictionaryRank($type), !resized, !skipRemoveEntitiesContainedInLarger) then + $lowerRank.getIntersectingNodes().forEach(node -> update(node)); $lowerRank.removeFromGraph(); retract($lowerRank); end