diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/model/document/nodes/Table.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/model/document/nodes/Table.java index a85acb28..6638c85e 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/model/document/nodes/Table.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/model/document/nodes/Table.java @@ -172,6 +172,18 @@ public class Table implements SemanticNode { return streamChildrenOfType(NodeType.TABLE_CELL).map(node -> (TableCell) node); } + /** + * Streams all TableCells that contain at least one entity of a given type in this Table row-wise. + * + * @param type The type of the entity + * @return Stream of filtered TableCells + */ + public Stream streamTableCellsWhichContainType(String type) { + + return streamTableCells() + .filter(tableCell -> tableCell.getEntities().stream().filter(TextEntity::active).anyMatch(entity -> entity.getType().equals(type))); + } + /** * Streams all TableCells in this Table which have the provided header row-wise. diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/acceptance_rules.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/acceptance_rules.drl index ed3716f4..2500757a 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/acceptance_rules.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/acceptance_rules.drl @@ -147,9 +147,8 @@ rule "CBI.7.0: Do not redact Names and Addresses if published information found rule "CBI.7.1: Do not redact Names and Addresses if published information found in same table row" when $table: Table(hasEntitiesOfType("published_information"), hasEntitiesOfType("CBI_author")) - $tableCell: TableCell() from $table.streamTableCells().toList() - $sameRowCell: TableCell(row == $tableCell.row) from $table.streamTableCells().toList() - TextEntity(type == "published_information", active()) from $tableCell.getEntities() + $cellsWithPublishedInformation: TableCell() from $table.streamTableCellsWhichContainType("published_information").toList() + $tableCell: TableCell(row == $cellsWithPublishedInformation.row) from $table.streamTableCells().toList() $author: TextEntity(type == "CBI_author", active()) from $tableCell.getEntities() then $author.skipWithReferences("CBI.7.1", "Published Information found in row", $table.getEntitiesOfTypeInSameRow("published_information", $author)); diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_redact_manager_rules.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_redact_manager_rules.drl index b8d5afd7..738187dc 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_redact_manager_rules.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/all_redact_manager_rules.drl @@ -330,9 +330,8 @@ rule "CBI.7.0: Do not redact Names and Addresses if published information found rule "CBI.7.1: Do not redact Names and Addresses if published information found in same table row" when $table: Table(hasEntitiesOfType("published_information"), hasEntitiesOfType("CBI_author")) - $tableCell: TableCell() from $table.streamTableCells().toList() - $sameRowCell: TableCell(row == $tableCell.row) from $table.streamTableCells().toList() - TextEntity(type == "published_information", active()) from $tableCell.getEntities() + $cellsWithPublishedInformation: TableCell() from $table.streamTableCellsWhichContainType("published_information").toList() + $tableCell: TableCell(row == $cellsWithPublishedInformation.row) from $table.streamTableCells().toList() $author: TextEntity(type == "CBI_author", active()) from $tableCell.getEntities() then $author.skipWithReferences("CBI.7.1", "Published Information found in row", $table.getEntitiesOfTypeInSameRow("published_information", $author)); diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/performance/dictionaries/EFSA_sanitisation_GFL_v1/rules.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/performance/dictionaries/EFSA_sanitisation_GFL_v1/rules.drl index ac5b6b78..78418a93 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/performance/dictionaries/EFSA_sanitisation_GFL_v1/rules.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/performance/dictionaries/EFSA_sanitisation_GFL_v1/rules.drl @@ -143,9 +143,8 @@ rule "CBI.7.0: Do not redact Names and Addresses if published information found rule "CBI.7.1: Do not redact Names and Addresses if published information found in same table row" when $table: Table(hasEntitiesOfType("published_information"), hasEntitiesOfType("CBI_author")) - $tableCell: TableCell() from $table.streamTableCells().toList() - $sameRowCell: TableCell(row == $tableCell.row) from $table.streamTableCells().toList() - TextEntity(type == "published_information", active()) from $tableCell.getEntities() + $cellsWithPublishedInformation: TableCell() from $table.streamTableCellsWhichContainType("published_information").toList() + $tableCell: TableCell(row == $cellsWithPublishedInformation.row) from $table.streamTableCells().toList() $author: TextEntity(type == "CBI_author", active()) from $tableCell.getEntities() then $author.skipWithReferences("CBI.7.1", "Published Information found in row", $table.getEntitiesOfTypeInSameRow("published_information", $author)); diff --git a/redaction-service-v1/rules-management/src/main/resources/all_redact_manager_rules.drl b/redaction-service-v1/rules-management/src/main/resources/all_redact_manager_rules.drl index 8bcb710c..df06969b 100644 --- a/redaction-service-v1/rules-management/src/main/resources/all_redact_manager_rules.drl +++ b/redaction-service-v1/rules-management/src/main/resources/all_redact_manager_rules.drl @@ -330,9 +330,8 @@ rule "CBI.7.0: Do not redact Names and Addresses if published information found rule "CBI.7.1: Do not redact Names and Addresses if published information found in same table row" when $table: Table(hasEntitiesOfType("published_information"), hasEntitiesOfType("CBI_author")) - $tableCell: TableCell() from $table.streamTableCells().toList() - $sameRowCell: TableCell(row == $tableCell.row) from $table.streamTableCells().toList() - TextEntity(type == "published_information", active()) from $tableCell.getEntities() + $cellsWithPublishedInformation: TableCell() from $table.streamTableCellsWhichContainType("published_information").toList() + $tableCell: TableCell(row == $cellsWithPublishedInformation.row) from $table.streamTableCells().toList() $author: TextEntity(type == "CBI_author", active()) from $tableCell.getEntities() then $author.skipWithReferences("CBI.7.1", "Published Information found in row", $table.getEntitiesOfTypeInSameRow("published_information", $author)); diff --git a/redaction-service-v1/rules-management/src/test/resources/all_redact_manager_rules.drl b/redaction-service-v1/rules-management/src/test/resources/all_redact_manager_rules.drl index 8bcb710c..df06969b 100644 --- a/redaction-service-v1/rules-management/src/test/resources/all_redact_manager_rules.drl +++ b/redaction-service-v1/rules-management/src/test/resources/all_redact_manager_rules.drl @@ -330,9 +330,8 @@ rule "CBI.7.0: Do not redact Names and Addresses if published information found rule "CBI.7.1: Do not redact Names and Addresses if published information found in same table row" when $table: Table(hasEntitiesOfType("published_information"), hasEntitiesOfType("CBI_author")) - $tableCell: TableCell() from $table.streamTableCells().toList() - $sameRowCell: TableCell(row == $tableCell.row) from $table.streamTableCells().toList() - TextEntity(type == "published_information", active()) from $tableCell.getEntities() + $cellsWithPublishedInformation: TableCell() from $table.streamTableCellsWhichContainType("published_information").toList() + $tableCell: TableCell(row == $cellsWithPublishedInformation.row) from $table.streamTableCells().toList() $author: TextEntity(type == "CBI_author", active()) from $tableCell.getEntities() then $author.skipWithReferences("CBI.7.1", "Published Information found in row", $table.getEntitiesOfTypeInSameRow("published_information", $author));