diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/nodes/SemanticNode.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/nodes/SemanticNode.java index 6c82ad20..e6c717c8 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/nodes/SemanticNode.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/nodes/SemanticNode.java @@ -21,10 +21,10 @@ public interface SemanticNode { /** * Searches all Nodes located underneath this Node in the DocumentTree and concatenates their AtomicTextBlocks into a single TextBlockEntity. - * So, for a ClassificationSection all TextBlocks of Subsections, Paragraphs, and Tables are concatenated into a single TextBlockEntity + * So, for a Section all TextBlocks of Subsections, Paragraphs, and Tables are concatenated into a single TextBlockEntity * If the Node is Terminal, the TerminalTextBlock will be returned instead. * - * @return ClassificationTextBlock containing all AtomicTextBlocks that are located under this Node. + * @return TextBlock containing all AtomicTextBlocks that are located under this Node. */ TextBlock buildTextBlock(); @@ -39,7 +39,7 @@ public interface SemanticNode { /** - * Each AtomicTextBlock is assigned a page, so to get the pages this node appears on, it collects the PageNodes from each AtomicTextBlock belonging to this node's ClassificationTextBlock. + * Each AtomicTextBlock is assigned a page, so to get the pages this node appears on, it collects the PageNodes from each AtomicTextBlock belonging to this node's TextBlock. * * @return Set of PageNodes this node appears on. */ @@ -50,7 +50,7 @@ public interface SemanticNode { /** - * Each AtomicTextBlock is assigned a page, so to get the pages for this boundary, it collects the PageNodes from each AtomicTextBlock belonging to this node's ClassificationTextBlock. + * Each AtomicTextBlock is assigned a page, so to get the pages for this boundary, it collects the PageNodes from each AtomicTextBlock belonging to this node's TextBlock. * * @return Set of PageNodes this node appears on. */ @@ -64,7 +64,9 @@ public interface SemanticNode { /** - * @return the DocumentTree of the ClassificationDocument this node belongs to + * Returns the DocumentTree Object. + * + * @return the DocumentTree of the Document this node belongs to */ DocumentTree getDocumentTree(); @@ -129,11 +131,11 @@ public interface SemanticNode { /** - * Terminal means a SemanticNode has direct access to a ClassificationTextBlock, by default this is false and must be overridden. + * Terminal means a SemanticNode has direct access to a TextBlock, by default this is false and must be overridden. * Currently only Sections, Images, and Tables are not terminal. * A TableCell might be Terminal depending on its area compared to the page. * - * @return boolean, indicating if a Node has direct access to a ClassificationTextBlock + * @return boolean, indicating if a Node has direct access to a TextBlock */ default boolean isTerminal() { @@ -142,7 +144,7 @@ public interface SemanticNode { /** - * Terminal means a SemanticNode has direct access to a ClassificationTextBlock, by default this is false and must be overridden. + * Terminal means a SemanticNode has direct access to a TextBlock, by default this is false and must be overridden. * Currently only Sections and Tables are not terminal. * * @return AtomicTextBlock @@ -153,24 +155,47 @@ public interface SemanticNode { } + /** + * Should only be used during construction of the Graph. Sets the TerminalTextBlock of this SemanticNode. + * + * @param textBlock the TextBlock to set as the terminalTextBlock of this SemanticNode + */ default void setTerminalTextBlock(TextBlock textBlock) { throw new UnsupportedOperationException(); } + /** + * Checks whether this SemanticNode has any Entity of the provided type. + * + * @param type string representing the type of entity to check for + * @return true, if this SemanticNode has at least one Entity of the provided type + */ default boolean hasEntitiesOfType(String type) { return getEntities().stream().anyMatch(redactionEntity -> redactionEntity.getType().equals(type)); } + /** + * Returns a List of Entities in this SemanticNode which are of the provided type such as "CBI_author". + * + * @param type string representing the type of entities to return + * @return List of RedactionEntities of any the type + */ default List getEntitiesOfType(String type) { return getEntities().stream().filter(redactionEntity -> redactionEntity.getType().equals(type)).toList(); } + /** + * Returns a List of Entities in this SemanticNode which have any of the provided types such as "CBI_author". + * + * @param types A list of strings representing the types of entities to return + * @return List of RedactionEntities of any provided type + */ default List getEntitiesOfType(List types) { return getEntities().stream().filter(redactionEntity -> redactionEntity.isAnyType(types)).toList(); @@ -195,7 +220,9 @@ public interface SemanticNode { /** - * @return true, if this node's ClassificationTextBlock is not empty + * Checks if the SemanticNode contains any text. + * + * @return true, if this node's TextBlock is not empty */ default boolean hasText() { @@ -204,6 +231,8 @@ public interface SemanticNode { /** + * Checks whether this SemanticNode contains the provided String. + * * @param string A String which the TextBlock might contain * @return true, if this node's TextBlock contains the string */ @@ -214,6 +243,8 @@ public interface SemanticNode { /** + * Checks whether this SemanticNode contains all the provided Strings. + * * @param strings A List of Strings which the TextBlock might contain * @return true, if this node's TextBlock contains all strings */ @@ -224,8 +255,10 @@ public interface SemanticNode { /** - * @param string A String which the ClassificationTextBlock might contain - * @return true, if this node's ClassificationTextBlock contains the string + * Checks whether this SemanticNode contains all the provided Strings ignoring case. + * + * @param string A String which the TextBlock might contain + * @return true, if this node's TextBlock contains the string ignoring case */ default boolean containsStringIgnoreCase(String string) { @@ -234,8 +267,10 @@ public interface SemanticNode { /** - * @param strings A List of Strings which the ClassificationTextBlock might contain - * @return true, if this node's ClassificationTextBlock contains any of the strings + * Checks whether this SemanticNode contains any of the provided Strings. + * + * @param strings A List of Strings which the TextBlock might contain + * @return true, if this node's TextBlock contains any of the strings */ default boolean containsAnyString(List strings) { @@ -244,8 +279,10 @@ public interface SemanticNode { /** - * @param strings A List of Strings which the ClassificationTextBlock might contain - * @return true, if this node's ClassificationTextBlock contains any of the strings + * Checks whether this SemanticNode contains any of the provided Strings ignoring case. + * + * @param strings A List of Strings which the TextBlock might contain + * @return true, if this node's TextBlock contains any of the strings */ default boolean containsAnyStringIgnoreCase(List strings) { @@ -286,7 +323,7 @@ public interface SemanticNode { /** - * recursively streams all SemanticNodes located underneath this node in the DocumentTree in order. + * Recursively streams all SemanticNodes located underneath this node in the DocumentTree in order. * * @return Stream of all SubNodes */ @@ -297,7 +334,9 @@ public interface SemanticNode { /** - * @return Boundary of this Node's ClassificationTextBlock + * The Boundary is the start and end string offsets in the reading order of the document. + * + * @return Boundary of this Node's TextBlock */ default Boundary getBoundary() { @@ -307,7 +346,7 @@ public interface SemanticNode { /** * If this Node is Terminal it will calculate the boundingBox of its TerminalTextBlock, otherwise it will calculate the Union of the BoundingBoxes of all its Children. - * If called on the ClassificationDocument, it will return the cropbox of each page + * If called on the Document, it will return the cropbox of each page * * @return Rectangle2D fully encapsulating this Node for each page. */ @@ -356,7 +395,7 @@ public interface SemanticNode { /** * @param bBoxPerPage initial empty BoundingBox - * @return The union of all BoundingBoxes of the ClassificationTextBlock of this node + * @return The union of all BoundingBoxes of the TextBlock of this node */ private Map getBBoxFromTerminalTextBlock(Map bBoxPerPage) { diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/conditions/SemanticNodeRuleConditions.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/conditions/SemanticNodeRuleConditions.java deleted file mode 100644 index 223d8186..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/conditions/SemanticNodeRuleConditions.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.iqser.red.service.redaction.v1.server.redaction.conditions; - -import java.util.List; - -import com.iqser.red.service.redaction.v1.server.layoutparsing.document.graph.nodes.SemanticNode; - -import lombok.experimental.UtilityClass; - -@UtilityClass -public class SemanticNodeRuleConditions { - - public boolean hasEntitiesOfType(SemanticNode semanticNode, String type) { - - return semanticNode.getEntities().stream().anyMatch(redactionEntity -> redactionEntity.getType().equals(type)); - } - - - public boolean hasEntitiesOfType(SemanticNode semanticNode, List types) { - - return types.stream().allMatch(type -> hasEntitiesOfType(semanticNode, type)); - } - -} diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/utils/Liszt.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/utils/Liszt.java deleted file mode 100644 index 9524b78b..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/utils/Liszt.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.iqser.red.service.redaction.v1.server.redaction.utils; - -import java.util.List; - -/** - * Drools fucked up and introduced a bug with newer versions of java, use this class instead of java.util.List.of(e1, e2) or else. - * java.lang.IncompatibleClassChangeError: Method 'java.util.List java.util.List.of(java.lang.Object, java.lang.Object)' must be InterfaceMethodref constant - * Will be thrown on LHS of rules, but only sometimes, I was not able to recreate this bug in a different project. - */ -public class Liszt { - - public static List of(E e1, E e2) { - - return List.of(e1, e2); - } - -} diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/manual_redaction_rules.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/manual_redaction_rules.drl index 93b9c177..11b0ea70 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/manual_redaction_rules.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/manual_redaction_rules.drl @@ -6,7 +6,6 @@ import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.u import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType; import java.util.List; -import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt; import java.util.LinkedList; import java.util.HashSet; diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/prod_syngenta_new.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/prod_syngenta_new.drl index c22d37ea..a14f2480 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/prod_syngenta_new.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/prod_syngenta_new.drl @@ -6,7 +6,6 @@ import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.u import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType; import java.util.List; -import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt; import java.util.LinkedList; import java.util.HashSet; 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 db4042a3..548983ef 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 @@ -6,7 +6,6 @@ import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.u import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType; import java.util.List; -import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt; import java.util.LinkedList; import java.util.HashSet; diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules_v2.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules_v2.drl index 4425bdda..7db4d5b8 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules_v2.drl +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules_v2.drl @@ -6,7 +6,6 @@ import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.u import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType; import java.util.List; -import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt; import java.util.LinkedList; import java.util.HashSet; 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 db4042a3..548983ef 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 @@ -6,7 +6,6 @@ import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.u import static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType; import java.util.List; -import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt; import java.util.LinkedList; import java.util.HashSet;