RSS-83: Test new rules for headline detection 3
This commit is contained in:
parent
7dae9e8f0b
commit
5503c7929b
@ -84,10 +84,10 @@ public class ClassificationService {
|
|||||||
// textBlock.setClassification("Title");
|
// textBlock.setClassification("Title");
|
||||||
// }
|
// }
|
||||||
} else
|
} else
|
||||||
if (textBlock.getText().length() > 5 && textBlock.getMostPopularWordHeight() > document.getTextHeightCounter().getMostPopular() && PositionUtils.getApproxLineCount(textBlock) < 2.9
|
if (textBlock.getText().length() > 5 && textBlock.getMostPopularWordHeight() > document.getTextHeightCounter().getMostPopular() && PositionUtils.getApproxLineCount(textBlock) < 5.9
|
||||||
&& !textBlock.getOrientation().equals(Orientation.RIGHT)
|
&& !textBlock.getOrientation().equals(Orientation.RIGHT)
|
||||||
|
|
||||||
&& (textBlock.getMostPopularWordStyle().contains("bold") || textBlock.toString().equals(textBlock.toString().toUpperCase(Locale.ROOT)))) {
|
&& ((textBlock.getMostPopularWordStyle().contains("bold") && Character.isDigit(textBlock.toString().charAt(0))) || textBlock.toString().equals(textBlock.toString().toUpperCase(Locale.ROOT)))) {
|
||||||
textBlock.setClassification("H 1");
|
textBlock.setClassification("H 1");
|
||||||
document.setHeadlines(true);
|
document.setHeadlines(true);
|
||||||
|
|
||||||
|
|||||||
@ -103,7 +103,7 @@ public class PdfSegmentationService {
|
|||||||
|
|
||||||
// var sorted = stripper.getTextPositionSequences().stream().sorted(Comparator.comparing(a -> a.getTextPositions().get(0).getXDirAdj())).sorted(Comparator.comparing(a -> a.getTextPositions().get(0).getYDirAdj())).sorted(Comparator.comparing(a -> a.getPage())).collect(Collectors.toList());
|
// var sorted = stripper.getTextPositionSequences().stream().sorted(Comparator.comparing(a -> a.getTextPositions().get(0).getXDirAdj())).sorted(Comparator.comparing(a -> a.getTextPositions().get(0).getYDirAdj())).sorted(Comparator.comparing(a -> a.getPage())).collect(Collectors.toList());
|
||||||
|
|
||||||
var pattern = Patterns.getCompiledPattern("^\\d[\\d.]{0,5}", true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -114,24 +114,6 @@ public class PdfSegmentationService {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
page.getTextBlocks().sort(Comparator.comparing(a -> a.getMinY(), Comparator.reverseOrder()));
|
|
||||||
|
|
||||||
AbstractTextContainer prev = null;
|
|
||||||
List<AbstractTextContainer> toRemove = new ArrayList<>();
|
|
||||||
for (AbstractTextContainer current : page.getTextBlocks()) {
|
|
||||||
|
|
||||||
if(prev != null && prev instanceof TextBlock && current instanceof TextBlock){
|
|
||||||
Matcher matcher = pattern.matcher(prev.getText());
|
|
||||||
if (matcher.matches()) {
|
|
||||||
((TextBlock) current).getSequences().add(0, ((TextBlock) prev).getSequences().get(0));
|
|
||||||
toRemove.add(prev);
|
|
||||||
current.setMinX(prev.getMinX());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prev = current;
|
|
||||||
}
|
|
||||||
|
|
||||||
page.getTextBlocks().removeAll(toRemove);
|
|
||||||
|
|
||||||
// page.getTextBlocks().sort(Comparator.comparing(a -> a.getMinX()));
|
// page.getTextBlocks().sort(Comparator.comparing(a -> a.getMinX()));
|
||||||
|
|
||||||
@ -153,11 +135,34 @@ public class PdfSegmentationService {
|
|||||||
imageService.findOcr(page);
|
imageService.findOcr(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var pattern = Patterns.getCompiledPattern("^\\d[\\d.]{0,5}", true);
|
||||||
|
page.getTextBlocks().sort(Comparator.comparing(a -> a.getMinY(), Comparator.reverseOrder()));
|
||||||
|
|
||||||
|
AbstractTextContainer prev = null;
|
||||||
|
List<AbstractTextContainer> toRemove = new ArrayList<>();
|
||||||
|
for (AbstractTextContainer current : page.getTextBlocks()) {
|
||||||
|
|
||||||
|
if(prev != null && prev instanceof TextBlock && current instanceof TextBlock && Math.abs(prev.getMinY() - current.getMinY()) <=1){
|
||||||
|
Matcher matcher = pattern.matcher(prev.getText());
|
||||||
|
if (matcher.matches()) {
|
||||||
|
((TextBlock) current).getSequences().add(0, ((TextBlock) prev).getSequences().get(0));
|
||||||
|
toRemove.add(prev);
|
||||||
|
current.setMinX(prev.getMinX());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
page.getTextBlocks().removeAll(toRemove);
|
||||||
|
|
||||||
|
|
||||||
pages.add(page);
|
pages.add(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.setPages(pages);
|
document.setPages(pages);
|
||||||
|
|
||||||
|
|
||||||
classificationService.classifyDocument(document);
|
classificationService.classifyDocument(document);
|
||||||
sectionsBuilderService.buildSections(document);
|
sectionsBuilderService.buildSections(document);
|
||||||
sectionsBuilderService.addImagesToSections(document);
|
sectionsBuilderService.addImagesToSections(document);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user