diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/DocumentGraphMapper.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/DocumentGraphMapper.java index 7702f176..371e0f35 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/DocumentGraphMapper.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/DocumentGraphMapper.java @@ -152,7 +152,7 @@ public class DocumentGraphMapper { } - private static AtomicTextBlock getAtomicTextBlock(Context context, SemanticNode parent, Long atomicTextBlockId) { + private AtomicTextBlock getAtomicTextBlock(Context context, SemanticNode parent, Long atomicTextBlockId) { return AtomicTextBlock.fromAtomicTextBlockData(context.atomicTextBlockData.get(Math.toIntExact(atomicTextBlockId)), context.atomicPositionBlockData.get(Math.toIntExact(atomicTextBlockId)), diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/PropertiesMapper.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/PropertiesMapper.java index eaebbe38..5b475217 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/PropertiesMapper.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/data/mapper/PropertiesMapper.java @@ -13,21 +13,27 @@ import com.iqser.red.service.redaction.v1.server.layoutparsing.document.graph.no import com.iqser.red.service.redaction.v1.server.layoutparsing.document.graph.nodes.Table; import com.iqser.red.service.redaction.v1.server.layoutparsing.document.graph.nodes.TableCell; +import lombok.AccessLevel; +import lombok.experimental.FieldDefaults; +import lombok.experimental.UtilityClass; + +@UtilityClass +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) public class PropertiesMapper { - private static final String imageType = "imageType"; - private static final String transparency = "transparency"; - private static final String position = "position"; - private static final String id = "id"; - private static final String row = "row"; - private static final String col = "col"; - private static final String header = "header"; - private static final String bBox = "bBox"; - private static final String numberOfRows = "numberOfRows"; - private static final String numberOfCols = "numberOfCols"; + String imageType = "imageType"; + private final String transparency = "transparency"; + private final String position = "position"; + String id = "id"; + String row = "row"; + String col = "col"; + String header = "header"; + String bBox = "bBox"; + String numberOfRows = "numberOfRows"; + String numberOfCols = "numberOfCols"; - public static Map buildImageProperties(Image image) { + public Map buildImageProperties(Image image) { Map properties = new HashMap<>(); properties.put(imageType, image.getImageType().toString()); @@ -38,13 +44,13 @@ public class PropertiesMapper { } - private static String toString(Rectangle2D rectangle2D) { + private String toString(Rectangle2D rectangle2D) { return format("%f,%f,%f,%f", rectangle2D.getX(), rectangle2D.getY(), rectangle2D.getWidth(), rectangle2D.getHeight()); } - public static Map buildTableCellProperties(TableCell tableCell) { + public Map buildTableCellProperties(TableCell tableCell) { Map properties = new HashMap<>(); properties.put(row, String.valueOf(tableCell.getRow())); @@ -61,7 +67,7 @@ public class PropertiesMapper { } - public static Map buildTableProperties(Table table) { + public Map buildTableProperties(Table table) { Map properties = new HashMap<>(); properties.put(numberOfRows, String.valueOf(table.getNumberOfRows())); @@ -70,7 +76,7 @@ public class PropertiesMapper { } - public static void parseImageProperties(Map properties, Image.ImageBuilder builder) { + public void parseImageProperties(Map properties, Image.ImageBuilder builder) { builder.imageType(ImageType.fromString(properties.get(imageType))); builder.transparent(Boolean.parseBoolean(properties.get(transparency))); @@ -79,7 +85,7 @@ public class PropertiesMapper { } - public static void parseTableCellProperties(Map properties, TableCell.TableCellBuilder builder) { + public void parseTableCellProperties(Map properties, TableCell.TableCellBuilder builder) { builder.row(Integer.parseInt(properties.get(row))); builder.col(Integer.parseInt(properties.get(col))); @@ -88,14 +94,14 @@ public class PropertiesMapper { } - public static void parseTableProperties(Map properties, Table.TableBuilder builder) { + public void parseTableProperties(Map properties, Table.TableBuilder builder) { builder.numberOfRows(Integer.parseInt(properties.get(numberOfRows))); builder.numberOfCols(Integer.parseInt(properties.get(numberOfCols))); } - private static Rectangle2D parseRectangle2D(String bBox) { + private Rectangle2D parseRectangle2D(String bBox) { List floats = Arrays.stream(bBox.split(",")).map(Float::parseFloat).toList(); return new Rectangle2D.Float(floats.get(0), floats.get(1), floats.get(2), floats.get(3)); diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/DocumentGraphFactory.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/DocumentGraphFactory.java index d42c4216..d564e83a 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/DocumentGraphFactory.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/DocumentGraphFactory.java @@ -196,7 +196,7 @@ public class DocumentGraphFactory { @Builder @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) - public static final class Context { + public final class Context { DocumentTree documentTree; Map pages; diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SearchTextWithTextPositionFactory.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SearchTextWithTextPositionFactory.java index 3a2601bd..eb4f8af8 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SearchTextWithTextPositionFactory.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SearchTextWithTextPositionFactory.java @@ -10,18 +10,21 @@ import com.iqser.red.service.redaction.v1.server.layoutparsing.classification.mo import com.iqser.red.service.redaction.v1.server.layoutparsing.classification.model.text.TextDirection; import com.iqser.red.service.redaction.v1.server.layoutparsing.classification.model.text.TextPositionSequence; +import lombok.experimental.UtilityClass; + +@UtilityClass public class SearchTextWithTextPositionFactory { - public static final int HEIGHT_PADDING = 2; + public final int HEIGHT_PADDING = 2; // when checking for a hyphen linebreak, we need to check after a linebreak if the last hyphen was less than three symbols away. // We detect a linebreak as either a "\n" character or if two adjacent symbol's position differ in y-coordinates by at least one character height. // If there is a hyphen linebreak, the hyphen will be 1 position in front of a "\n" or 2 positions in front of the character which has a lower y-coordinate // This is why, we need to initialize this to < -2, otherwise, if the very first symbol is a \n we would detect a hyphen linebreak that isn't there. // Also, Integer.MIN_VALUE is a bad idea due to potential overflow during arithmetic operations. This is why the default should be -3. - public static final int MAX_HYPHEN_LINEBREAK_DISTANCE = 3; + public final int MAX_HYPHEN_LINEBREAK_DISTANCE = 3; - public static SearchTextWithTextPositionDto buildSearchTextToTextPositionModel(List sequences) { + public SearchTextWithTextPositionDto buildSearchTextToTextPositionModel(List sequences) { if (sequences.isEmpty() || sequences.stream().allMatch(sequence -> sequence.getTextPositions().isEmpty())) { return SearchTextWithTextPositionDto.empty(); @@ -72,7 +75,7 @@ public class SearchTextWithTextPositionFactory { } - private static void appendCurrentTextPosition(Context context, RedTextPosition currentTextPosition) { + private void appendCurrentTextPosition(Context context, RedTextPosition currentTextPosition) { context.stringBuilder.append(currentTextPosition.getUnicode()); @@ -84,7 +87,7 @@ public class SearchTextWithTextPositionFactory { } - private static void removeHyphenLinebreaks(Context context) { + private void removeHyphenLinebreaks(Context context) { if (lastHyphenDirectlyBeforeLineBreak(context)) { context.stringBuilder.delete(context.lastHyphenIdx, context.stringBuilder.length()); @@ -95,19 +98,19 @@ public class SearchTextWithTextPositionFactory { } - private static boolean lastHyphenDirectlyBeforeLineBreak(Context context) { + private boolean lastHyphenDirectlyBeforeLineBreak(Context context) { return context.stringIdx - context.lastHyphenIdx < MAX_HYPHEN_LINEBREAK_DISTANCE; } - private static boolean isLineBreak(RedTextPosition currentTextPosition, RedTextPosition previousTextPosition) { + private boolean isLineBreak(RedTextPosition currentTextPosition, RedTextPosition previousTextPosition) { return Objects.equals(currentTextPosition.getUnicode(), "\n") || isDeltaYLargerThanTextHeight(currentTextPosition, previousTextPosition); } - private static boolean isDeltaYLargerThanTextHeight(RedTextPosition currentPosition, RedTextPosition previousPosition) { + private boolean isDeltaYLargerThanTextHeight(RedTextPosition currentPosition, RedTextPosition previousPosition) { if (previousPosition == null) { return false; @@ -118,13 +121,13 @@ public class SearchTextWithTextPositionFactory { } - private static boolean isRepeatedWhitespace(String currentUnicode, String previousUnicode) { + private boolean isRepeatedWhitespace(String currentUnicode, String previousUnicode) { return Objects.equals(previousUnicode, " ") && Objects.equals(currentUnicode, " "); } - private static boolean isHyphen(String unicodeCharacter) { + private boolean isHyphen(String unicodeCharacter) { return Objects.equals(unicodeCharacter, "-") || // Objects.equals(unicodeCharacter, "~") || // @@ -140,7 +143,7 @@ public class SearchTextWithTextPositionFactory { } - private static Rectangle2D mapRedTextPositionToInitialUserSpace(RedTextPosition textPosition, TextPositionSequence sequence) { + private Rectangle2D mapRedTextPositionToInitialUserSpace(RedTextPosition textPosition, TextPositionSequence sequence) { float textHeight = sequence.getTextHeight() + HEIGHT_PADDING; Rectangle2D rectangle2D = new Rectangle2D.Double(textPosition.getXDirAdj(), @@ -166,7 +169,7 @@ public class SearchTextWithTextPositionFactory { } - private static class Context { + private class Context { List stringIdxToPositionIdx = new LinkedList<>(); List lineBreaksStringIdx = new LinkedList<>(); diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SectionNodeFactory.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SectionNodeFactory.java index 6a97e731..eabe4ecc 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SectionNodeFactory.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/SectionNodeFactory.java @@ -48,7 +48,7 @@ public class SectionNodeFactory { } - private static List getTreeId(GenericSemanticNode parentNode, DocumentGraphFactory.Context context, Section section) { + private List getTreeId(GenericSemanticNode parentNode, DocumentGraphFactory.Context context, Section section) { if (parentNode == null) { return context.getDocumentTree().createNewMainEntryAndReturnId(section); diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/TableNodeFactory.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/TableNodeFactory.java index c0e79d78..2a04e4ad 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/TableNodeFactory.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/factory/TableNodeFactory.java @@ -24,7 +24,7 @@ import lombok.experimental.UtilityClass; @UtilityClass public class TableNodeFactory { - public static final double TABLE_CELL_MERGE_CONTENTS_SIZE_THRESHOLD = 0.05; + public final double TABLE_CELL_MERGE_CONTENTS_SIZE_THRESHOLD = 0.05; public void addTable(GenericSemanticNode parentNode, List tablesToMerge, DocumentGraphFactory.Context context) { @@ -56,7 +56,7 @@ public class TableNodeFactory { } - private static void setPageNumberInTextBlocksWithPageNumberSetTo0(TablePageBlock table, Cell cell) { + private void setPageNumberInTextBlocksWithPageNumberSetTo0(TablePageBlock table, Cell cell) { cell.getTextBlocks().stream()// .filter(tb -> tb.getPage() == 0)//