Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b900cfaf31 | ||
|
|
cdc2081785 | ||
|
|
a9287ec406 | ||
|
|
5b6a706c28 | ||
|
|
28d8ad0a3f | ||
|
|
0c1583c1be | ||
|
|
7633566d9b | ||
|
|
cc4f09711e |
+10
-2
@@ -82,10 +82,18 @@ public class OutlineExtractorService {
|
||||
|
||||
String title = item.getTitle();
|
||||
|
||||
PDPage page = item.findDestinationPage(document);
|
||||
if (page == null) {
|
||||
PDPage page;
|
||||
try {
|
||||
// Can throw: "Error: can't convert to Destination COSArray" for some OCR'd PDFs
|
||||
page = item.findDestinationPage(document);
|
||||
if (page == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}catch (IOException e){
|
||||
log.info(String.format("Error occurred during position resolution for outline item with title %s: " + e, title));
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
int pageNumber = document.getPages().indexOf(page);
|
||||
|
||||
Optional<Point2D> outlinePosition = Optional.empty();
|
||||
|
||||
+5
-1
@@ -273,6 +273,10 @@ public class BlockificationPostprocessingService {
|
||||
List<TextPositionSequence> postSequence = new ArrayList<>();
|
||||
StringBuilder currentSequence = new StringBuilder();
|
||||
|
||||
if (target.isBlank()){
|
||||
return new WordSequenceResult();
|
||||
}
|
||||
|
||||
for (TextPositionSequence sequence : textPositionSequences) {
|
||||
|
||||
currentSequence.append(sanitizeString(sequence.toString()));
|
||||
@@ -332,7 +336,7 @@ public class BlockificationPostprocessingService {
|
||||
TextPositionSequence in = null;
|
||||
TextPositionSequence out;
|
||||
|
||||
String currentSequence = sequence.toString();
|
||||
String currentSequence = sequence.toString().toLowerCase(Locale.ROOT);
|
||||
int index = currentSequence.indexOf(toRemove);
|
||||
int endIndex = index + toRemove.length();
|
||||
|
||||
|
||||
+42
-7
@@ -51,13 +51,48 @@ public class TextPositionSequenceComparator implements Comparator<TextPositionSe
|
||||
|
||||
double yDifference = Math.abs(pos1YBottom - pos2YBottom);
|
||||
|
||||
// we will do a simple tolerance comparison
|
||||
if (yDifference < .1 || pos2YBottom >= pos1YTop && pos2YBottom <= pos1YBottom || pos1YBottom >= pos2YTop && pos1YBottom <= pos2YBottom) {
|
||||
return Double.compare(x1, x2);
|
||||
} else if (pos1YBottom < pos2YBottom) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
|
||||
// Adjust for text rotation
|
||||
switch (pos1.getRotation()) {
|
||||
case 0:
|
||||
// 0 degrees (horizontal, top to bottom and left to right): Sort primarily by y-coordinates from top to bottom (pos1YBottom < pos2YBottom).
|
||||
if (yDifference < .1 || (pos2YBottom >= pos1YTop && pos2YBottom <= pos1YBottom) || (pos1YBottom >= pos2YTop && pos1YBottom <= pos2YBottom)) {
|
||||
return Double.compare(x1, x2);
|
||||
} else if (pos1YBottom < pos2YBottom) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
case 90:
|
||||
// 90 degrees (vertical, right to left): Sort by x-coordinates first (x1 > x2), then by y-coordinates from top to bottom (pos1YBottom < pos2YBottom).
|
||||
if (x1 > x2) {
|
||||
return -1;
|
||||
} else if (x1 < x2) {
|
||||
return 1;
|
||||
} else {
|
||||
return Double.compare(pos1YBottom, pos2YBottom);
|
||||
}
|
||||
case 180:
|
||||
// 180 degrees (horizontal, bottom to top and right to left): Sort primarily by y-coordinates from bottom to top (pos1YBottom > pos2YBottom).
|
||||
if (yDifference < .1 || (pos2YBottom >= pos1YTop && pos2YBottom <= pos1YBottom) || (pos1YBottom >= pos2YTop && pos1YBottom <= pos2YBottom)) {
|
||||
return Double.compare(x2, x1);
|
||||
|
||||
} else if (pos1YBottom > pos2YBottom) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
case 270:
|
||||
// 270 degrees (vertical, left to right): Sort by x-coordinates in reverse (x2 > x1), then by y-coordinates from bottom to top (pos2YBottom > pos1YBottom).
|
||||
if (x2 > x1) {
|
||||
return -1;
|
||||
} else if (x2 < x1) {
|
||||
return 1;
|
||||
} else {
|
||||
return Double.compare(pos2YBottom, pos1YBottom);
|
||||
}
|
||||
default:
|
||||
throw new RuntimeException("Rotation not supported. Only 0/90/180/270 degree rotation is supported.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -31,10 +31,9 @@ public class LayoutparserEnd2EndTest extends AbstractTest {
|
||||
private LayoutParsingPipeline layoutParsingPipeline;
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testLayoutParserEndToEnd() {
|
||||
|
||||
String filePath = "files/syngenta/CustomerFiles/Documine/Flora/425_F.1.1.1 - A13617AV - Acute Oral Toxicity Study.pdf";
|
||||
String filePath = "files/test-1.pdf";
|
||||
|
||||
runForFile(filePath);
|
||||
}
|
||||
|
||||
+10
@@ -1,5 +1,6 @@
|
||||
package com.knecon.fforesight.service.layoutparser.server;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -56,6 +57,15 @@ public class OutlineDetectionTest extends AbstractTest {
|
||||
pdfNetInitializer.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
public void testOutlineError(){
|
||||
String fileName = "files/syngenta/CustomerFiles/Clarifynd/VV-470942.pdf";
|
||||
|
||||
ClassificationDocument classificationDocument = parseLayout(fileName, LayoutParsingType.CLARIFYND);
|
||||
assertThat(classificationDocument).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:323c3c6ddfa263701d4f4be883df2a46c44db8a9113016c3fe5bd90625d1bea6
|
||||
size 823960
|
||||
Reference in New Issue
Block a user