RSS-181: Use pdfbox quicksort for sorting in rules

This commit is contained in:
deiflaender 2022-11-03 15:50:20 +01:00
parent 8e74615a1e
commit 7ba9ae22fe
2 changed files with 8 additions and 4 deletions

View File

@ -70,9 +70,9 @@ public class ClassificationService {
} }
if (textBlock.getText().length() > 5 && (textBlock.getMostPopularWordHeight() > document.getTextHeightCounter().getMostPopular() || textBlock.getMostPopularWordFontSize() > document.getFontSizeCounter().getMostPopular()) && PositionUtils.getApproxLineCount(textBlock) < 5.9 if (textBlock.getText().length() > 5 && (textBlock.getMostPopularWordHeight() > document.getTextHeightCounter().getMostPopular() || textBlock.getMostPopularWordFontSize() > document.getFontSizeCounter().getMostPopular()) && PositionUtils.getApproxLineCount(textBlock) < 5.9
&& ((textBlock.getMostPopularWordStyle().contains("bold") && Character.isDigit(textBlock.toString().charAt(0)) && !matcher2.matches() && !textBlock.toString().contains(":") && (textBlock.getMostPopularWordStyle().contains("bold") && Character.isDigit(textBlock.toString().charAt(0)) && !matcher2.matches() && !textBlock.toString().contains(":")
|| textBlock.toString().equals(textBlock.toString().toUpperCase(Locale.ROOT)) && !matcher2.matches() && !textBlock.toString().contains(":") || textBlock.toString().equals(textBlock.toString().toUpperCase(Locale.ROOT)) && !matcher2.matches() && !textBlock.toString().contains(":")
|| textBlock.toString().startsWith("APPENDIX") || textBlock.toString().startsWith("TABLE")) && !textBlock.toString().endsWith(":"))) { || textBlock.toString().startsWith("APPENDIX") || textBlock.toString().startsWith("TABLE")) && !textBlock.toString().endsWith(":")) {
textBlock.setClassification("H 1"); textBlock.setClassification("H 1");
document.setHeadlines(true); document.setHeadlines(true);

View File

@ -14,6 +14,8 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.pdfbox.util.QuickSort;
import lombok.Getter; import lombok.Getter;
public class SearchableText { public class SearchableText {
@ -217,8 +219,10 @@ public class SearchableText {
public String getAsStringWithLinebreaksSorted(List<TextPositionSequence> sequences) { public String getAsStringWithLinebreaksSorted(List<TextPositionSequence> sequences) {
var sorted = sequences.stream() var quickSorted = new ArrayList<>(sequences);
.sorted(new TextPositionSequenceComparator()) QuickSort.sort(quickSorted, new TextPositionSequenceComparator());
var sorted = quickSorted.stream()
.sorted(Comparator.comparing(a -> a.getPage())) .sorted(Comparator.comparing(a -> a.getPage()))
.collect(Collectors.toList()); .collect(Collectors.toList());