Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
fix(remove_overlaps_min_spans): optimize overlap detection in OCR span list modification
myhlolie4810cee1700
diff --git a/magic_pdf/pre_proc/ocr_span_list_modify.py b/magic_pdf/pre_proc/ocr_span_list_modify.pyindex 9c2d6cc8..84fca74e 100644--- a/magic_pdf/pre_proc/ocr_span_list_modify.py+++ b/magic_pdf/pre_proc/ocr_span_list_modify.py@@ -38,11 +38,15 @@ def remove_overlaps_min_spans(spans):for span1 in spans:for span2 in spans:if span1 != span2:- overlap_box = get_minbox_if_overlap_by_ratio(span1['bbox'], span2['bbox'], 0.65)- if overlap_box is not None:- span_need_remove = next((span for span in spans if span['bbox'] == overlap_box), None)- if span_need_remove is not None and span_need_remove not in dropped_spans:- dropped_spans.append(span_need_remove)+ # span1 或 span2 任何一个都不应该在 dropped_spans 中+ if span1 in dropped_spans or span2 in dropped_spans:+ continue+ else:+ overlap_box = get_minbox_if_overlap_by_ratio(span1['bbox'], span2['bbox'], 0.65)+ if overlap_box is not None:+ span_need_remove = next((span for span in spans if span['bbox'] == overlap_box), None)+ if span_need_remove is not None and span_need_remove not in dropped_spans:+ dropped_spans.append(span_need_remove)if len(dropped_spans) > 0:for span_need_remove in dropped_spans: