RSS-83: Test new rules for headline detection 3

This commit is contained in:
deiflaender 2022-09-30 13:58:29 +02:00
parent 7dae9e8f0b
commit 5503c7929b
2 changed files with 26 additions and 21 deletions

View File

@ -84,10 +84,10 @@ public class ClassificationService {
// textBlock.setClassification("Title");
// }
} 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.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");
document.setHeadlines(true);

View File

@ -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 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()));
@ -153,11 +135,34 @@ public class PdfSegmentationService {
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);
}
document.setPages(pages);
classificationService.classifyDocument(document);
sectionsBuilderService.buildSections(document);
sectionsBuilderService.addImagesToSections(document);