RED-6009 - Document Tree Structure
* added more javadoc
This commit is contained in:
parent
088a5cde1a
commit
e31a7b1a2f
@ -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.
|
* 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.
|
* 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();
|
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.
|
* @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.
|
* @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();
|
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.
|
* Currently only Sections, Images, and Tables are not terminal.
|
||||||
* A TableCell might be Terminal depending on its area compared to the page.
|
* 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() {
|
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.
|
* Currently only Sections and Tables are not terminal.
|
||||||
*
|
*
|
||||||
* @return AtomicTextBlock
|
* @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) {
|
default void setTerminalTextBlock(TextBlock textBlock) {
|
||||||
|
|
||||||
throw new UnsupportedOperationException();
|
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) {
|
default boolean hasEntitiesOfType(String type) {
|
||||||
|
|
||||||
return getEntities().stream().anyMatch(redactionEntity -> redactionEntity.getType().equals(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<RedactionEntity> getEntitiesOfType(String type) {
|
default List<RedactionEntity> getEntitiesOfType(String type) {
|
||||||
|
|
||||||
return getEntities().stream().filter(redactionEntity -> redactionEntity.getType().equals(type)).toList();
|
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<RedactionEntity> getEntitiesOfType(List<String> types) {
|
default List<RedactionEntity> getEntitiesOfType(List<String> types) {
|
||||||
|
|
||||||
return getEntities().stream().filter(redactionEntity -> redactionEntity.isAnyType(types)).toList();
|
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() {
|
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
|
* @param string A String which the TextBlock might contain
|
||||||
* @return true, if this node's TextBlock contains the string
|
* @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
|
* @param strings A List of Strings which the TextBlock might contain
|
||||||
* @return true, if this node's TextBlock contains all strings
|
* @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
|
* Checks whether this SemanticNode contains all the provided Strings ignoring case.
|
||||||
* @return true, if this node's ClassificationTextBlock contains the string
|
*
|
||||||
|
* @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) {
|
default boolean containsStringIgnoreCase(String string) {
|
||||||
|
|
||||||
@ -234,8 +267,10 @@ public interface SemanticNode {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param strings A List of Strings which the ClassificationTextBlock might contain
|
* Checks whether this SemanticNode contains any of the provided Strings.
|
||||||
* @return true, if this node's ClassificationTextBlock contains any of the 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<String> strings) {
|
default boolean containsAnyString(List<String> strings) {
|
||||||
|
|
||||||
@ -244,8 +279,10 @@ public interface SemanticNode {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param strings A List of Strings which the ClassificationTextBlock might contain
|
* Checks whether this SemanticNode contains any of the provided Strings ignoring case.
|
||||||
* @return true, if this node's ClassificationTextBlock contains any of the 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 containsAnyStringIgnoreCase(List<String> strings) {
|
default boolean containsAnyStringIgnoreCase(List<String> 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
|
* @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() {
|
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 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.
|
* @return Rectangle2D fully encapsulating this Node for each page.
|
||||||
*/
|
*/
|
||||||
@ -356,7 +395,7 @@ public interface SemanticNode {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bBoxPerPage initial empty BoundingBox
|
* @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<Page, Rectangle2D> getBBoxFromTerminalTextBlock(Map<Page, Rectangle2D> bBoxPerPage) {
|
private Map<Page, Rectangle2D> getBBoxFromTerminalTextBlock(Map<Page, Rectangle2D> bBoxPerPage) {
|
||||||
|
|
||||||
|
|||||||
@ -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<String> types) {
|
|
||||||
|
|
||||||
return types.stream().allMatch(type -> hasEntitiesOfType(semanticNode, type));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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 <E> List<E> of(E e1, E e2) {
|
|
||||||
|
|
||||||
return List.of(e1, e2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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 static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|||||||
@ -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 static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|||||||
@ -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 static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|||||||
@ -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 static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|||||||
@ -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 static com.iqser.red.service.redaction.v1.server.layoutparsing.document.data.mapper.PropertiesMapper.parseImageType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.Liszt;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user