diff --git a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/Rectangle.java b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/Rectangle.java index 0ed06644..3938e14e 100644 --- a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/Rectangle.java +++ b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/Rectangle.java @@ -20,15 +20,29 @@ public class Rectangle { + + + + + + + + + + + + + + @JsonIgnore @JsonAttribute(ignore = true) public float getX1(int dir, float pageWidth, float pageHeight) { if (dir == 90) { - return topLeft.getX(); + return topLeft.getY(); } else if (dir == 180) { - return pageWidth - topLeft.getX() + width; + return topLeft.getX() + width; } else if (dir == 270) { @@ -46,11 +60,11 @@ public class Rectangle { public float getX2(int dir, float pageWidth, float pageHeight) { if (dir == 90) { - return topLeft.getX() + width; + return topLeft.getY() + height; } else if (dir == 180) { - return pageWidth - topLeft.getX(); + return topLeft.getX(); } else if (dir == 270) { @@ -72,11 +86,11 @@ public class Rectangle { public float getY1(int dir, float pageWidth, float pageHeight) { if (dir == 90 ) { - return topLeft.getY(); + return topLeft.getX(); } else if (dir == 180) { - return pageHeight - topLeft.getY() + height; + return pageHeight - topLeft.getY() - height; } @@ -95,12 +109,12 @@ public class Rectangle { public float getY2(int dir, float pageWidth, float pageHeight) { if (dir == 90) { - return topLeft.getY() + height; + return topLeft.getX() + width; } else if (dir == 180 ) { - return pageHeight - topLeft.getY(); + return pageHeight - topLeft.getY(); } else if (dir == 270 ) { diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/BlockificationService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/BlockificationService.java index d1416a5b..8ba5e2a0 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/BlockificationService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/BlockificationService.java @@ -61,7 +61,7 @@ public class BlockificationService { || isSplittedByRuling(minX, minY, word.getX1(), word.getY2(), verticalRulingLines, word.getDir().getDegrees(), cropbox.getWidth(), cropbox.getHeight()); boolean splitByDir = prev != null && !prev.getDir().equals(word.getDir()); - if (prev != null && (lineSeparation || startFromTop || xIsBeforeFirstX || splitByX || splitByDir || startFromTop || splittedByRuling)) { + if (prev != null && (lineSeparation || startFromTop || xIsBeforeFirstX || splitByX || splitByDir || splittedByRuling)) { Orientation prevOrientation = null; if (!chunkBlockList1.isEmpty()) { @@ -332,32 +332,20 @@ public class BlockificationService { if (documentFontSizeCounter.getMostPopular() != null) { if (textBlock.getMostPopularWordFontSize() >= documentFontSizeCounter.getMostPopular()) { - if (textBlock.getX1() < minX) { - minX = textBlock.getX1(); - } - if (textBlock.getX2() > maxX) { - maxX = textBlock.getX2(); - } - if (textBlock.getY1() < minY) { - minY = textBlock.getY1(); - } - if (textBlock.getY2() > maxY) { - maxY = textBlock.getY2(); - } - - } - } - } - - if (container instanceof Table) { - Table table = (Table) container; - for (List row : table.getRows()) { - for (Cell cell : row) { - - if (cell == null || cell.getTextBlocks() == null) { - continue; - } - for (TextBlock textBlock : cell.getTextBlocks()) { + if(page.getRotation() == 90 || page.getRotation() == 270){ + if (textBlock.getY1() < minX) { + minX = textBlock.getY1(); + } + if (textBlock.getY2() > maxX) { + maxX = textBlock.getY2(); + } + if (textBlock.getX1() < minY) { + minY = textBlock.getX1(); + } + if (textBlock.getX2() > maxY) { + maxY = textBlock.getX2(); + } + } else { if (textBlock.getX1() < minX) { minX = textBlock.getX1(); } @@ -374,30 +362,56 @@ public class BlockificationService { } } } + + if (container instanceof Table) { + Table table = (Table) container; + for (List row : table.getRows()) { + for (Cell cell : row) { + + if (cell == null || cell.getTextBlocks() == null) { + continue; + } + for (TextBlock textBlock : cell.getTextBlocks()) { + if(page.getRotation() == 90 || page.getRotation() == 270){ + if (textBlock.getY1() < minX) { + minX = textBlock.getMinY(); + } + if (textBlock.getY2() > maxX) { + maxX = textBlock.getY2(); + } + if (textBlock.getX1() < minY) { + minY = textBlock.getX1(); + } + if (textBlock.getX2() > maxY) { + maxY = textBlock.getX2(); + } + } else { + if (textBlock.getX1() < minX) { + minX = textBlock.getX1(); + } + if (textBlock.getX2() > maxX) { + maxX = textBlock.getX2(); + } + if (textBlock.getY1() < minY) { + minY = textBlock.getY1(); + } + if (textBlock.getY2() > maxY) { + maxY = textBlock.getY2(); + } + } + } + } + } + } } + System.out.println("Page: " + page.getPageNumber() + " Landscape: " + page.isLandscape()+ " MinX: " + minX + " MaxX: " + maxX + " MinY: " +minY + " MaxY: " + maxY); } return new Rectangle(new Point(minX, minY), maxX - minX, maxY - minY, 0); } - private void sortRotatedSequences(List sequences) { - List rotatedWords = new ArrayList<>(); - Iterator itty = sequences.iterator(); - while (itty.hasNext()) { - var pos = itty.next(); - if (pos.getTextPositions().get(0).getDir() == 270) { - rotatedWords.add(pos); - itty.remove(); - } - } - - if (!rotatedWords.isEmpty() && !sequences.isEmpty()) { - rotatedWords.sort(Comparator.comparing(TextPositionSequence::getX1)); - } - sequences.addAll(rotatedWords); - } private double round(float value, int decimalPoints) { diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/ClassificationService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/ClassificationService.java index bd790c9a..f3909635 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/ClassificationService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/classification/service/ClassificationService.java @@ -34,7 +34,7 @@ public class ClassificationService { for (Page page : document.getPages()) { Rectangle btf = page.isLandscape() ? landscapeBodyTextFrame : bodyTextFrame; - if (!page.isLandscape() && (page.getRotation() == 90 || page.getRotation() == 270)){ + var width = btf.getX2(page.getRotation(), page.getCropBox().getWidth(), page.getCropBox().getHeight()) - btf.getX1(page.getRotation(), page.getCropBox().getWidth(), page.getCropBox().getHeight()); var height = btf.getY2(page.getRotation(), page.getCropBox().getWidth(), page.getCropBox().getHeight()) - btf.getY1(page.getRotation(), page.getCropBox().getWidth(), page.getCropBox().getHeight()); @@ -42,11 +42,7 @@ public class ClassificationService { var y1 = btf.getY1(page.getRotation(), page.getCropBox().getWidth(), page.getCropBox().getHeight()); page.setBodyTextFrame(new Rectangle(new Point(x1, y1), width, height,0)); - } else if (page.getRotation() == 180) { - page.setBodyTextFrame(new Rectangle(new Point(btf.getTopLeft().getX(), page.getCropBox().getHeight() - btf.getTopLeft().getY() -btf.getHeight()), btf.getWidth(), btf.getHeight(),0)); - } else { - page.setBodyTextFrame(btf); - } + diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/PdfVisualisationService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/PdfVisualisationService.java index 778aaf41..49b5f89f 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/PdfVisualisationService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/PdfVisualisationService.java @@ -79,10 +79,13 @@ public class PdfVisualisationService { } contentStream.setStrokingColor(Color.YELLOW); -// var widhth = analyzedPage.getBodyTextFrame().getX2(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()) - analyzedPage.getBodyTextFrame().getX1(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()); +// var width = analyzedPage.getBodyTextFrame().getX2(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()) - analyzedPage.getBodyTextFrame().getX1(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()); // var height = analyzedPage.getBodyTextFrame().getY2(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()) - analyzedPage.getBodyTextFrame().getY1(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()); +// +// contentStream.addRect(analyzedPage.getBodyTextFrame().getX1(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()), analyzedPage.getBodyTextFrame().getY1(pdPage.getRotation(), pdPage.getCropBox().getWidth(), pdPage.getCropBox().getHeight()), width, height); + + contentStream.addRect(analyzedPage.getBodyTextFrame().getTopLeft().getX(), analyzedPage.getBodyTextFrame().getTopLeft().getY(), analyzedPage.getBodyTextFrame().getWidth(), analyzedPage.getBodyTextFrame().getHeight()); - contentStream.addRect(analyzedPage.getBodyTextFrame().getTopLeft().getX(), analyzedPage.getBodyTextFrame().getTopLeft().getY(), analyzedPage.getBodyTextFrame().getWidth(), analyzedPage.getBodyTextFrame().getHeight()); contentStream.stroke(); contentStream.close(); @@ -97,17 +100,18 @@ public class PdfVisualisationService { contentStream.addRect(textBlock.getX1(), textBlock.getY1(), textBlock.getX2() - textBlock.getX1(), textBlock.getY2() - textBlock.getY1()); contentStream.stroke(); -// if (textBlock.getClassification() != null) { -// contentStream.beginText(); -// -// contentStream.setFont(PDType1Font.TIMES_ROMAN, 6f); -// -// contentStream.newLineAtOffset(textBlock.getX1(), textBlock.getY2() + 2); -// contentStream.showText(textBlock.getClassification() + textBlock.getOrientation() + "-->" + textBlock.getSequences().get(0).getDir()); -// -// contentStream.endText(); -// -// + if (textBlock.getClassification() != null) { + contentStream.beginText(); + + contentStream.setNonStrokingColor(Color.BLUE); + contentStream.setFont(PDType1Font.TIMES_ROMAN, 9f); + + contentStream.newLineAtOffset(textBlock.getX1(), textBlock.getY2() + 2); + contentStream.showText(textBlock.getClassification() + textBlock.getOrientation() + "-->" + textBlock.getSequences().get(0).getDir()); + + contentStream.endText(); + + // contentStream.setNonStrokingColor(Color.BLUE); // contentStream.setFont(PDType1Font.TIMES_ROMAN, 2f); // @@ -131,7 +135,7 @@ public class PdfVisualisationService { // // // contentStream.endText(); -// } + } } diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java index 635bbebd..cf70a1b2 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java +++ b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java @@ -1168,7 +1168,7 @@ public class RedactionIntegrationTest { System.out.println("classificationTest"); - AnalyzeRequest request = prepareStorage("files/Metolachlor/S-Metolachlor_RAR_01_Volume_1_2018-09-06.pdf"); + AnalyzeRequest request = prepareStorage("files/RSS/09 - CGA100251 - Acute Oral Toxicity (Up and Down Procedure) - Rat.pdf"); RedactionRequest redactionRequest = RedactionRequest.builder() .dossierId(request.getDossierId())