RED-8481: Use visual layout parsing to detect signatures

added a new layer for visual parsing results

codestyle
This commit is contained in:
yhampe 2024-02-23 12:46:51 +01:00
parent a927cbd9dc
commit 71477dabde
2 changed files with 31 additions and 24 deletions

View File

@ -3,7 +3,6 @@ package com.knecon.fforesight.service.layoutparser.internal.api.data.redaction;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -45,6 +44,7 @@ public class DocumentStructure implements Serializable {
public static final String ID = "id"; public static final String ID = "id";
} }
@Schema(description = "Object containing the extra field names, a table cell has in its properties field.") @Schema(description = "Object containing the extra field names, a table cell has in its properties field.")
public static class TableCellProperties implements Serializable { public static class TableCellProperties implements Serializable {
@ -116,7 +116,7 @@ public class DocumentStructure implements Serializable {
Map<String, String> properties; Map<String, String> properties;
@Schema(description = "All child Entries of this Entry.", example = "[1, 2, 3]") @Schema(description = "All child Entries of this Entry.", example = "[1, 2, 3]")
List<EntryData> children; List<EntryData> children;
@Schema(description = "Describes the origin of the semantic node",example = "[ALGORITHM]") @Schema(description = "Describes the origin of the semantic node", example = "[ALGORITHM]")
Set<LayoutEngine> engines; Set<LayoutEngine> engines;

View File

@ -61,12 +61,15 @@ public class LayoutGridService {
static Color IMAGE_VISUAL_COLOR = new Color(122, 0, 255); static Color IMAGE_VISUAL_COLOR = new Color(122, 0, 255);
@SneakyThrows @SneakyThrows
@Observed(name = "ViewerDocumentService", contextualName = "create-viewer-document") @Observed(name = "ViewerDocumentService", contextualName = "create-viewer-document")
public void addLayoutGrid(File originFile, Document document, File destinationFile, boolean layerVisibilityDefaultValue) { public void addLayoutGrid(File originFile, Document document, File destinationFile, boolean layerVisibilityDefaultValue) {
this.addLayoutGrid(originFile,document,destinationFile,layerVisibilityDefaultValue,false);
this.addLayoutGrid(originFile, document, destinationFile, layerVisibilityDefaultValue, false);
} }
@SneakyThrows @SneakyThrows
@Observed(name = "ViewerDocumentService", contextualName = "create-viewer-document") @Observed(name = "ViewerDocumentService", contextualName = "create-viewer-document")
public void addLayoutGrid(File originFile, Document document, File destinationFile, boolean layerVisibilityDefaultValue, boolean visualParsingGrid) { public void addLayoutGrid(File originFile, Document document, File destinationFile, boolean layerVisibilityDefaultValue, boolean visualParsingGrid) {
@ -82,33 +85,37 @@ public class LayoutGridService {
.build()); .build());
} }
private LayoutGrid createLayoutGrid(Document document, boolean visualParsingGrid) { private LayoutGrid createLayoutGrid(Document document, boolean visualParsingGrid) {
LayoutGrid layoutGrid = new LayoutGrid(document.getNumberOfPages()); LayoutGrid layoutGrid = new LayoutGrid(document.getNumberOfPages());
document.streamAllSubNodes().filter(node -> (node.getEngines().contains(LayoutEngine.AI) && visualParsingGrid ) || (node.getEngines().contains(LayoutEngine.ALGORITHM) && !visualParsingGrid)).forEach(semanticNode -> { document.streamAllSubNodes()
Color color = switch (semanticNode.getType()) { .filter(node -> (node.getEngines().contains(LayoutEngine.AI) && visualParsingGrid) || (node.getEngines().contains(LayoutEngine.ALGORITHM) && !visualParsingGrid))
case PARAGRAPH -> PARAGRAPH_COLOR; .forEach(semanticNode -> {
case TABLE -> TABLE_COLOR; Color color = switch (semanticNode.getType()) {
case SECTION -> SECTION_COLOR; case PARAGRAPH -> PARAGRAPH_COLOR;
case HEADLINE -> HEADLINE_COLOR; case TABLE -> TABLE_COLOR;
case HEADER, FOOTER -> HEADER_COLOR; case SECTION -> SECTION_COLOR;
case IMAGE -> IMAGE_COLOR; case HEADLINE -> HEADLINE_COLOR;
default -> null; case HEADER, FOOTER -> HEADER_COLOR;
}; case IMAGE -> IMAGE_COLOR;
if (isNotSectionOrTableCellOrDocument(semanticNode)) { default -> null;
addAsRectangle(semanticNode, layoutGrid, color); };
} if (isNotSectionOrTableCellOrDocument(semanticNode)) {
if (semanticNode.getType().equals(NodeType.SECTION)) { addAsRectangle(semanticNode, layoutGrid, color);
addSection(semanticNode, layoutGrid, color); }
} if (semanticNode.getType().equals(NodeType.SECTION)) {
if (semanticNode.getType().equals(NodeType.TABLE)) { addSection(semanticNode, layoutGrid, color);
Table table = (Table) semanticNode; }
addInnerTableLines(table, layoutGrid); if (semanticNode.getType().equals(NodeType.TABLE)) {
} Table table = (Table) semanticNode;
}); addInnerTableLines(table, layoutGrid);
}
});
return layoutGrid; return layoutGrid;
} }
private void addInnerTableLines(Table table, LayoutGrid layoutGrid) { private void addInnerTableLines(Table table, LayoutGrid layoutGrid) {
if (table.getNumberOfCols() < 1 || table.getNumberOfRows() < 1) { if (table.getNumberOfCols() < 1 || table.getNumberOfRows() < 1) {