RSS-181: Use pdfbox quicksort for sorting in rules

This commit is contained in:
deiflaender 2022-11-03 15:50:20 +01:00
parent ae93fe7997
commit 4603b567bb
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
&& ((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().startsWith("APPENDIX") || textBlock.toString().startsWith("TABLE")) && !textBlock.toString().endsWith(":"))) {
|| textBlock.toString().startsWith("APPENDIX") || textBlock.toString().startsWith("TABLE")) && !textBlock.toString().endsWith(":")) {
textBlock.setClassification("H 1");
document.setHeadlines(true);

View File

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