RED-5381: Test1: Rotate in TextPositionSequence
This commit is contained in:
parent
ddbf80e4a6
commit
5f0b7d8344
@ -29,7 +29,8 @@ public class BlockificationService {
|
|||||||
static final float THRESHOLD = 1f;
|
static final float THRESHOLD = 1f;
|
||||||
|
|
||||||
|
|
||||||
public Page blockify(List<TextPositionSequence> textPositions, List<Ruling> horizontalRulingLines, List<Ruling> verticalRulingLines) {
|
public Page blockify(List<TextPositionSequence> textPositions, List<Ruling> horizontalRulingLines,
|
||||||
|
List<Ruling> verticalRulingLines) {
|
||||||
|
|
||||||
sortRotatedSequences(textPositions);
|
sortRotatedSequences(textPositions);
|
||||||
|
|
||||||
@ -47,19 +48,15 @@ public class BlockificationService {
|
|||||||
boolean startFromTop = word.getY1() > maxY + word.getHeight();
|
boolean startFromTop = word.getY1() > maxY + word.getHeight();
|
||||||
boolean splitByX = prev != null && maxX + 50 < word.getX1() && prev.getY1() == word.getY1();
|
boolean splitByX = prev != null && maxX + 50 < word.getX1() && prev.getY1() == word.getY1();
|
||||||
boolean newLineAfterSplit = prev != null && word.getY1() != prev.getY1() && wasSplitted && splitX1 != word.getX1();
|
boolean newLineAfterSplit = prev != null && word.getY1() != prev.getY1() && wasSplitted && splitX1 != word.getX1();
|
||||||
boolean splittedByRuling = isSplittedByRuling(maxX, minY, word.getX1(), word.getY1(), verticalRulingLines) || isSplittedByRuling(minX,
|
boolean splittedByRuling =
|
||||||
minY,
|
isSplittedByRuling(maxX, minY, word.getX1(), word.getY1(), verticalRulingLines) ||
|
||||||
word.getX1(),
|
isSplittedByRuling(minX, minY, word.getX1(), word.getY2(), horizontalRulingLines)
|
||||||
word.getY2(),
|
|
||||||
horizontalRulingLines)
|
|
||||||
|
|
||||||
|| isSplittedByRuling(maxX, minY, word.getX1(), word.getY1(), horizontalRulingLines) || isSplittedByRuling(minX,
|
|| isSplittedByRuling(maxX, minY, word.getX1(), word.getY1(), horizontalRulingLines)
|
||||||
minY,
|
|| isSplittedByRuling(minX, minY, word.getX1(), word.getY2(), verticalRulingLines);
|
||||||
word.getX1(),
|
boolean splitByDir = prev != null && !prev.getDir().equals(word.getDir());
|
||||||
word.getY2(),
|
|
||||||
verticalRulingLines);
|
|
||||||
|
|
||||||
if (prev != null && (lineSeparation || startFromTop || splitByX || newLineAfterSplit || splittedByRuling)) {
|
if (prev != null && (lineSeparation || startFromTop || splitByX || newLineAfterSplit || splittedByRuling || splitByDir)) {
|
||||||
|
|
||||||
Orientation prevOrientation = null;
|
Orientation prevOrientation = null;
|
||||||
if (!chunkBlockList1.isEmpty()) {
|
if (!chunkBlockList1.isEmpty()) {
|
||||||
@ -119,7 +116,8 @@ public class BlockificationService {
|
|||||||
TextBlock block = (TextBlock) itty.next();
|
TextBlock block = (TextBlock) itty.next();
|
||||||
|
|
||||||
if (previousLeft != null && block.getOrientation().equals(Orientation.LEFT)) {
|
if (previousLeft != null && block.getOrientation().equals(Orientation.LEFT)) {
|
||||||
if (previousLeft.getMinY() > block.getMinY() && block.getMaxY() + block.getMostPopularWordHeight() > previousLeft.getMinY()) {
|
if (previousLeft.getMinY() > block.getMinY() && block.getMaxY() + block.getMostPopularWordHeight() > previousLeft
|
||||||
|
.getMinY()) {
|
||||||
previousLeft.add(block);
|
previousLeft.add(block);
|
||||||
itty.remove();
|
itty.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -127,7 +125,8 @@ public class BlockificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (previousRight != null && block.getOrientation().equals(Orientation.RIGHT)) {
|
if (previousRight != null && block.getOrientation().equals(Orientation.RIGHT)) {
|
||||||
if (previousRight.getMinY() > block.getMinY() && block.getMaxY() + block.getMostPopularWordHeight() > previousRight.getMinY()) {
|
if (previousRight.getMinY() > block.getMinY() && block.getMaxY() + block.getMostPopularWordHeight() > previousRight
|
||||||
|
.getMinY()) {
|
||||||
previousRight.add(block);
|
previousRight.add(block);
|
||||||
itty.remove();
|
itty.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -146,8 +145,10 @@ public class BlockificationService {
|
|||||||
while (itty.hasNext()) {
|
while (itty.hasNext()) {
|
||||||
TextBlock block = (TextBlock) itty.next();
|
TextBlock block = (TextBlock) itty.next();
|
||||||
|
|
||||||
if (previous != null && previous.getOrientation().equals(Orientation.LEFT) && block.getOrientation().equals(Orientation.LEFT) && equalsWithThreshold(block.getMaxY(),
|
if (previous != null && previous.getOrientation().equals(Orientation.LEFT) && block.getOrientation()
|
||||||
previous.getMaxY()) || previous != null && previous.getOrientation().equals(Orientation.LEFT) && block.getOrientation()
|
.equals(Orientation.LEFT) && equalsWithThreshold(block.getMaxY(), previous.getMaxY()) || previous != null && previous
|
||||||
|
.getOrientation()
|
||||||
|
.equals(Orientation.LEFT) && block.getOrientation()
|
||||||
.equals(Orientation.RIGHT) && equalsWithThreshold(block.getMaxY(), previous.getMaxY())) {
|
.equals(Orientation.RIGHT) && equalsWithThreshold(block.getMaxY(), previous.getMaxY())) {
|
||||||
previous.add(block);
|
previous.add(block);
|
||||||
itty.remove();
|
itty.remove();
|
||||||
@ -186,10 +187,12 @@ public class BlockificationService {
|
|||||||
styleFrequencyCounter.add(wordBlock.getFontStyle());
|
styleFrequencyCounter.add(wordBlock.getFontStyle());
|
||||||
|
|
||||||
if (textBlock == null) {
|
if (textBlock == null) {
|
||||||
textBlock = new TextBlock(wordBlock.getX1(), wordBlock.getX2(), wordBlock.getY1(), wordBlock.getY2(), wordBlockList, wordBlock.getRotation());
|
textBlock = new TextBlock(wordBlock.getX1(), wordBlock.getX2(), wordBlock.getY1(), wordBlock.getY2(), wordBlockList, wordBlock
|
||||||
|
.getRotation());
|
||||||
} else {
|
} else {
|
||||||
TextBlock spatialEntity = textBlock.union(wordBlock);
|
TextBlock spatialEntity = textBlock.union(wordBlock);
|
||||||
textBlock.resize(spatialEntity.getMinX(), spatialEntity.getMinY(), spatialEntity.getWidth(), spatialEntity.getHeight());
|
textBlock.resize(spatialEntity.getMinX(), spatialEntity.getMinY(), spatialEntity.getWidth(), spatialEntity
|
||||||
|
.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,14 +205,19 @@ public class BlockificationService {
|
|||||||
textBlock.setHighestFontSize(fontSizeFrequencyCounter.getHighest());
|
textBlock.setHighestFontSize(fontSizeFrequencyCounter.getHighest());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textBlock != null && textBlock.getSequences() != null && textBlock.getSequences().stream().map(t -> round(t.getY1(), 3)).collect(toSet()).size() == 1) {
|
if (textBlock != null && textBlock.getSequences() != null && textBlock.getSequences()
|
||||||
|
.stream()
|
||||||
|
.map(t -> round(t.getY1(), 3))
|
||||||
|
.collect(toSet())
|
||||||
|
.size() == 1) {
|
||||||
textBlock.getSequences().sort(Comparator.comparing(TextPositionSequence::getX1));
|
textBlock.getSequences().sort(Comparator.comparing(TextPositionSequence::getX1));
|
||||||
}
|
}
|
||||||
return textBlock;
|
return textBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isSplittedByRuling(float previousX2, float previousY1, float currentX1, float currentY1, List<Ruling> rulingLines) {
|
private boolean isSplittedByRuling(float previousX2, float previousY1, float currentX1, float currentY1,
|
||||||
|
List<Ruling> rulingLines) {
|
||||||
|
|
||||||
for (Ruling ruling : rulingLines) {
|
for (Ruling ruling : rulingLines) {
|
||||||
if (ruling.intersectsLine(previousX2, previousY1, currentX1, currentY1)) {
|
if (ruling.intersectsLine(previousX2, previousY1, currentX1, currentY1)) {
|
||||||
@ -220,7 +228,8 @@ public class BlockificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Rectangle calculateBodyTextFrame(List<Page> pages, FloatFrequencyCounter documentFontSizeCounter, boolean landscape) {
|
public Rectangle calculateBodyTextFrame(List<Page> pages, FloatFrequencyCounter documentFontSizeCounter,
|
||||||
|
boolean landscape) {
|
||||||
|
|
||||||
float minX = 10000;
|
float minX = 10000;
|
||||||
float maxX = -100;
|
float maxX = -100;
|
||||||
|
|||||||
@ -147,29 +147,6 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
@JsonAttribute(ignore = true)
|
|
||||||
public float getX1() {
|
|
||||||
|
|
||||||
if (rotation == 90) {
|
|
||||||
return textPositions.get(0).getYDirAdj() - getTextHeight();
|
|
||||||
} else {
|
|
||||||
return textPositions.get(0).getXDirAdj();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
@JsonAttribute(ignore = true)
|
|
||||||
public float getX2() {
|
|
||||||
|
|
||||||
if (rotation == 90) {
|
|
||||||
return textPositions.get(0).getYDirAdj();
|
|
||||||
} else {
|
|
||||||
return textPositions.get(textPositions.size() - 1).getXDirAdj() + textPositions.get(textPositions.size() - 1).getWidthDirAdj() + HEIGHT_PADDING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@JsonAttribute(ignore = true)
|
@JsonAttribute(ignore = true)
|
||||||
@ -179,13 +156,72 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
@JsonAttribute(ignore = true)
|
||||||
|
public float getX1() {
|
||||||
|
|
||||||
|
if (getDir().getDegrees() == 90) {
|
||||||
|
return textPositions.get(0).getYDirAdj() - getTextHeight();
|
||||||
|
}
|
||||||
|
else if (getDir().getDegrees() == 180) {
|
||||||
|
return pageWidth - textPositions.get(textPositions.size() - 1).getXDirAdj() - textPositions.get(textPositions.size() - 1).getWidthDirAdj() - HEIGHT_PADDING;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (getDir().getDegrees() == 270) {
|
||||||
|
|
||||||
|
return pageWidth - textPositions.get(0).getYDirAdj() ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return textPositions.get(0).getXDirAdj();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
@JsonAttribute(ignore = true)
|
||||||
|
public float getX2() {
|
||||||
|
|
||||||
|
if (getDir().getDegrees() == 90) {
|
||||||
|
return textPositions.get(0).getYDirAdj();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (getDir().getDegrees() == 180) {
|
||||||
|
return pageWidth - textPositions.get(0).getXDirAdj() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (getDir().getDegrees() == 270) {
|
||||||
|
return pageWidth - textPositions.get(0).getYDirAdj() + getTextHeight();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
return textPositions.get(textPositions.size() - 1).getXDirAdj() + textPositions.get(textPositions.size() - 1).getWidthDirAdj() + HEIGHT_PADDING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@JsonAttribute(ignore = true)
|
@JsonAttribute(ignore = true)
|
||||||
public float getY1() {
|
public float getY1() {
|
||||||
|
|
||||||
if (rotation == 90) {
|
if (getDir().getDegrees() == 90 ) {
|
||||||
return textPositions.get(0).getXDirAdj();
|
return textPositions.get(0).getXDirAdj();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
else if (getDir().getDegrees() == 180) {
|
||||||
|
return textPositions.get(0).getYDirAdj() - getTextHeight();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
else if (getDir().getDegrees() == 270) {
|
||||||
|
return pageHeight - textPositions.get(textPositions.size() - 1).getXDirAdj() - getTextHeight() + HEIGHT_PADDING;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
return pageHeight - textPositions.get(0).getYDirAdj();
|
return pageHeight - textPositions.get(0).getYDirAdj();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,14 +231,26 @@ public class TextPositionSequence implements CharSequence {
|
|||||||
@JsonAttribute(ignore = true)
|
@JsonAttribute(ignore = true)
|
||||||
public float getY2() {
|
public float getY2() {
|
||||||
|
|
||||||
if (rotation == 90) {
|
if (getDir().getDegrees() == 90) {
|
||||||
return textPositions.get(textPositions.size() - 1).getXDirAdj() + getTextHeight() - HEIGHT_PADDING;
|
return textPositions.get(textPositions.size() - 1).getXDirAdj() + getTextHeight() - HEIGHT_PADDING;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
else if (getDir().getDegrees() == 180 ) {
|
||||||
|
|
||||||
|
return textPositions.get(0).getYDirAdj();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (getDir().getDegrees() == 270 ) {
|
||||||
|
return pageHeight - textPositions.get(0).getXDirAdj();
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
return pageHeight - textPositions.get(0).getYDirAdj() + getTextHeight();
|
return pageHeight - textPositions.get(0).getYDirAdj() + getTextHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@JsonAttribute(ignore = true)
|
@JsonAttribute(ignore = true)
|
||||||
public float getTextHeight() {
|
public float getTextHeight() {
|
||||||
|
|||||||
@ -101,11 +101,27 @@ public class PdfVisualisationService {
|
|||||||
contentStream.beginText();
|
contentStream.beginText();
|
||||||
|
|
||||||
contentStream.setNonStrokingColor(Color.BLUE);
|
contentStream.setNonStrokingColor(Color.BLUE);
|
||||||
contentStream.setFont(PDType1Font.TIMES_ROMAN, 12f);
|
contentStream.setFont(PDType1Font.TIMES_ROMAN, 2f);
|
||||||
|
|
||||||
|
contentStream.newLineAtOffset(textBlock.getMinX(), textBlock.getMaxY() + 10);
|
||||||
|
contentStream.showText(textBlock.getClassification() + textBlock.getOrientation() + "-->" + textBlock.getSequences().get(0).getDir());
|
||||||
|
contentStream.endText();
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.newLineAtOffset(textBlock.getMinX(), textBlock.getMinY());
|
||||||
|
contentStream.showText("MinX,MinY");
|
||||||
|
contentStream.endText();
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.newLineAtOffset(textBlock.getMaxX(), textBlock.getMinY());
|
||||||
|
contentStream.showText("MaxX,MinY");
|
||||||
|
contentStream.endText();
|
||||||
|
contentStream.beginText();
|
||||||
contentStream.newLineAtOffset(textBlock.getMinX(), textBlock.getMaxY());
|
contentStream.newLineAtOffset(textBlock.getMinX(), textBlock.getMaxY());
|
||||||
|
contentStream.showText("MinX,MaxY");
|
||||||
|
contentStream.endText();
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.newLineAtOffset(textBlock.getMaxX(), textBlock.getMaxY());
|
||||||
|
contentStream.showText("MaxX,MaxY");
|
||||||
|
|
||||||
contentStream.showText(textBlock.getClassification() + textBlock.getOrientation());
|
|
||||||
|
|
||||||
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/new/RotateTestFile.pdf");
|
||||||
|
|
||||||
RedactionRequest redactionRequest = RedactionRequest.builder()
|
RedactionRequest redactionRequest = RedactionRequest.builder()
|
||||||
.dossierId(request.getDossierId())
|
.dossierId(request.getDossierId())
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user