RED-5381: Fixed calculation of bodyTextFrame
This commit is contained in:
parent
c23dd86b6d
commit
4be5487e64
@ -1,8 +1,5 @@
|
|||||||
package com.iqser.red.service.redaction.v1.model;
|
package com.iqser.red.service.redaction.v1.model;
|
||||||
|
|
||||||
import com.dslplatform.json.JsonAttribute;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -18,100 +15,4 @@ public class Rectangle {
|
|||||||
|
|
||||||
private int page;
|
private int page;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
@JsonAttribute(ignore = true)
|
|
||||||
public float getX1(int dir, float pageWidth, float pageHeight) {
|
|
||||||
|
|
||||||
if (dir == 90) {
|
|
||||||
return topLeft.getX();
|
|
||||||
}
|
|
||||||
else if (dir == 180) {
|
|
||||||
return pageWidth - topLeft.getX() + width;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (dir == 270) {
|
|
||||||
|
|
||||||
return topLeft.getY() + height;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return topLeft.getX();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
@JsonAttribute(ignore = true)
|
|
||||||
public float getX2(int dir, float pageWidth, float pageHeight) {
|
|
||||||
|
|
||||||
if (dir == 90) {
|
|
||||||
return topLeft.getX() + width;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (dir == 180) {
|
|
||||||
return pageWidth - topLeft.getX();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (dir == 270) {
|
|
||||||
return topLeft.getY() ;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
return topLeft.getX() + width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
@JsonAttribute(ignore = true)
|
|
||||||
public float getY1(int dir, float pageWidth, float pageHeight) {
|
|
||||||
|
|
||||||
if (dir == 90 ) {
|
|
||||||
return topLeft.getY();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (dir == 180) {
|
|
||||||
return pageHeight - topLeft.getY() + height;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (dir == 270) {
|
|
||||||
return pageHeight - topLeft.getX() ;
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return topLeft.getY();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
@JsonAttribute(ignore = true)
|
|
||||||
public float getY2(int dir, float pageWidth, float pageHeight) {
|
|
||||||
|
|
||||||
if (dir == 90) {
|
|
||||||
return topLeft.getY() + height;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (dir == 180 ) {
|
|
||||||
|
|
||||||
return pageHeight - topLeft.getY();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (dir == 270 ) {
|
|
||||||
return pageHeight -topLeft.getX() - width;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
return topLeft.getY() + height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class BlockificationService {
|
|||||||
|| isSplittedByRuling(minX, minY, word.getX1(), word.getY2(), verticalRulingLines, word.getDir().getDegrees(), cropbox.getWidth(), cropbox.getHeight());
|
|| isSplittedByRuling(minX, minY, word.getX1(), word.getY2(), verticalRulingLines, word.getDir().getDegrees(), cropbox.getWidth(), cropbox.getHeight());
|
||||||
boolean splitByDir = prev != null && !prev.getDir().equals(word.getDir());
|
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;
|
Orientation prevOrientation = null;
|
||||||
if (!chunkBlockList1.isEmpty()) {
|
if (!chunkBlockList1.isEmpty()) {
|
||||||
@ -332,6 +332,20 @@ public class BlockificationService {
|
|||||||
if (documentFontSizeCounter.getMostPopular() != null) {
|
if (documentFontSizeCounter.getMostPopular() != null) {
|
||||||
if (textBlock.getMostPopularWordFontSize() >= documentFontSizeCounter.getMostPopular()) {
|
if (textBlock.getMostPopularWordFontSize() >= documentFontSizeCounter.getMostPopular()) {
|
||||||
|
|
||||||
|
if(page.getCropBox().getWidth() > page.getCropBox().getHeight() && page.getRotation() != 0){
|
||||||
|
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) {
|
if (textBlock.getX1() < minX) {
|
||||||
minX = textBlock.getX1();
|
minX = textBlock.getX1();
|
||||||
}
|
}
|
||||||
@ -344,7 +358,7 @@ public class BlockificationService {
|
|||||||
if (textBlock.getY2() > maxY) {
|
if (textBlock.getY2() > maxY) {
|
||||||
maxY = textBlock.getY2();
|
maxY = textBlock.getY2();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,6 +372,20 @@ public class BlockificationService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (TextBlock textBlock : cell.getTextBlocks()) {
|
for (TextBlock textBlock : cell.getTextBlocks()) {
|
||||||
|
if(page.getCropBox().getWidth() > page.getCropBox().getHeight() && page.getRotation() != 0){
|
||||||
|
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) {
|
if (textBlock.getX1() < minX) {
|
||||||
minX = textBlock.getX1();
|
minX = textBlock.getX1();
|
||||||
}
|
}
|
||||||
@ -375,29 +403,15 @@ public class BlockificationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
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);
|
return new Rectangle(new Point(minX, minY), maxX - minX, maxY - minY, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sortRotatedSequences(List<TextPositionSequence> sequences) {
|
|
||||||
|
|
||||||
List<TextPositionSequence> rotatedWords = new ArrayList<>();
|
|
||||||
Iterator<TextPositionSequence> 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) {
|
private double round(float value, int decimalPoints) {
|
||||||
|
|||||||
@ -34,22 +34,24 @@ public class ClassificationService {
|
|||||||
for (Page page : document.getPages()) {
|
for (Page page : document.getPages()) {
|
||||||
Rectangle btf = page.isLandscape() ? landscapeBodyTextFrame : bodyTextFrame;
|
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());
|
|
||||||
|
|
||||||
var x1= btf.getX1(page.getRotation(), page.getCropBox().getWidth(), page.getCropBox().getHeight());
|
if(page.getCropBox().getWidth() > page.getCropBox().getHeight() && page.getRotation() == 270) {
|
||||||
var y1 = btf.getY1(page.getRotation(), page.getCropBox().getWidth(), page.getCropBox().getHeight());
|
page.setBodyTextFrame(new Rectangle(new Point(btf.getTopLeft().getY(),page.getCropBox().getHeight() - btf.getTopLeft().getX()), btf.getHeight(), -btf.getWidth(), 0));
|
||||||
|
}
|
||||||
|
else if(page.getCropBox().getWidth() > page.getCropBox().getHeight() && page.getRotation() != 0) {
|
||||||
|
page.setBodyTextFrame(new Rectangle(new Point(btf.getTopLeft().getY(), btf.getTopLeft().getX()), btf.getHeight(), btf.getWidth(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
page.setBodyTextFrame(new Rectangle(new Point(x1, y1), width, height,0));
|
else if(page.getRotation() == 180){
|
||||||
} else if (page.getRotation() == 180) {
|
page.setBodyTextFrame(new Rectangle(new Point( btf.getTopLeft().getX(), page.getCropBox().getHeight() - btf.getTopLeft().getY()), btf.getWidth(), -btf.getHeight(), 0));
|
||||||
page.setBodyTextFrame(new Rectangle(new Point(btf.getTopLeft().getX(), page.getCropBox().getHeight() - btf.getTopLeft().getY() -btf.getHeight()), btf.getWidth(), btf.getHeight(),0));
|
}
|
||||||
} else {
|
else {
|
||||||
page.setBodyTextFrame(btf);
|
page.setBodyTextFrame(btf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
classifyPage(btf, page, document, headlineFontSizes);
|
classifyPage(btf, page, document, headlineFontSizes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,6 +112,8 @@ public class PdfSegmentationService {
|
|||||||
float cropboxArea = cropbox.getHeight() * cropbox.getWidth();
|
float cropboxArea = cropbox.getHeight() * cropbox.getWidth();
|
||||||
page.setCropBoxArea(cropboxArea);
|
page.setCropBoxArea(cropboxArea);
|
||||||
|
|
||||||
|
System.out.println("CropBox: w:" + cropbox.getWidth() + " h:" +cropbox.getHeight() + "MediaBox: w:" + pdPage.getMediaBox().getWidth() + " h:" +pdPage.getMediaBox().getHeight());
|
||||||
|
|
||||||
page.setRotation(rotation);
|
page.setRotation(rotation);
|
||||||
page.setLandscape(isLandscape);
|
page.setLandscape(isLandscape);
|
||||||
page.setPageNumber(pageNumber);
|
page.setPageNumber(pageNumber);
|
||||||
|
|||||||
@ -79,10 +79,13 @@ public class PdfVisualisationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
contentStream.setStrokingColor(Color.YELLOW);
|
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());
|
// 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.stroke();
|
||||||
|
|
||||||
contentStream.close();
|
contentStream.close();
|
||||||
@ -97,17 +100,18 @@ public class PdfVisualisationService {
|
|||||||
contentStream.addRect(textBlock.getX1(), textBlock.getY1(), textBlock.getX2() - textBlock.getX1(), textBlock.getY2() - textBlock.getY1());
|
contentStream.addRect(textBlock.getX1(), textBlock.getY1(), textBlock.getX2() - textBlock.getX1(), textBlock.getY2() - textBlock.getY1());
|
||||||
contentStream.stroke();
|
contentStream.stroke();
|
||||||
|
|
||||||
// if (textBlock.getClassification() != null) {
|
if (textBlock.getClassification() != null) {
|
||||||
// contentStream.beginText();
|
contentStream.beginText();
|
||||||
//
|
|
||||||
// contentStream.setFont(PDType1Font.TIMES_ROMAN, 6f);
|
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.newLineAtOffset(textBlock.getX1(), textBlock.getY2() + 2);
|
||||||
//
|
contentStream.showText(textBlock.getClassification() + textBlock.getOrientation() + "-->" + textBlock.getSequences().get(0).getDir());
|
||||||
// contentStream.endText();
|
|
||||||
//
|
contentStream.endText();
|
||||||
//
|
|
||||||
|
|
||||||
// contentStream.setNonStrokingColor(Color.BLUE);
|
// contentStream.setNonStrokingColor(Color.BLUE);
|
||||||
// contentStream.setFont(PDType1Font.TIMES_ROMAN, 2f);
|
// contentStream.setFont(PDType1Font.TIMES_ROMAN, 2f);
|
||||||
//
|
//
|
||||||
@ -131,7 +135,7 @@ public class PdfVisualisationService {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// contentStream.endText();
|
// contentStream.endText();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1098,7 +1098,7 @@ public class RedactionIntegrationTest {
|
|||||||
|
|
||||||
System.out.println("classificationTest");
|
System.out.println("classificationTest");
|
||||||
|
|
||||||
AnalyzeRequest request = prepareStorage("files/Metolachlor/S-Metolachlor_RAR_01_Volume_1_2018-09-06.pdf");
|
AnalyzeRequest request = prepareStorage("files/Primicarb/74 Pirimicarb_RAR_01_Volume_1_2017-12-04.pdf");
|
||||||
|
|
||||||
RedactionRequest redactionRequest = RedactionRequest.builder()
|
RedactionRequest redactionRequest = RedactionRequest.builder()
|
||||||
.dossierId(request.getDossierId())
|
.dossierId(request.getDossierId())
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user