|
|
|
|
@ -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<RedactionEntity> 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<RedactionEntity> getEntitiesOfType(List<String> 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<String> 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<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
|
|
|
|
|
*/
|
|
|
|
|
@ -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<Page, Rectangle2D> getBBoxFromTerminalTextBlock(Map<Page, Rectangle2D> bBoxPerPage) {
|
|
|
|
|
|
|
|
|
|
|