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
feat: enhance rule delimited code detection by adding vertical rule height coverage and refining hanging indent recognition
myhloli62dd9721780e
diff --git a/mineru/backend/flash/native_pdf/code_blocks.py b/mineru/backend/flash/native_pdf/code_blocks.pyindex 937db404..053c6ed6 100644--- a/mineru/backend/flash/native_pdf/code_blocks.py+++ b/mineru/backend/flash/native_pdf/code_blocks.py@@ -108,6 +108,23 @@ def _materialize_code_candidates(return blocks, claimed+def _vertical_rule_candidate_height_coverage(+ rule_bbox: BBox,+ candidate_bbox: BBox,+) -> float:+ """计算竖轨在候选高度方向上的实际覆盖比例,长轨超出候选时仍按交集计量。"""++ candidate_height = max(0.0, candidate_bbox[3] - candidate_bbox[1])+ if candidate_height <= 0:+ return 0.0+ overlap = max(+ 0.0,+ min(rule_bbox[3], candidate_bbox[3])+ - max(rule_bbox[1], candidate_bbox[1]),+ )+ return overlap / candidate_height++def _detect_rule_delimited_code_candidates(source: _PageSource,excluded_bboxes: list[BBox],@@ -181,8 +198,12 @@ def _detect_rule_delimited_code_candidates(if candidate_bbox[0] + median_height< _bbox_center_x(rule.bbox)< candidate_bbox[2] - median_height- and rule.bbox[3] - rule.bbox[1] >= 0.6 * candidate_height- and _bbox_overlap_in_first(rule.bbox, candidate_bbox) >= 0.8+ # 表格竖轨可能贯穿候选上下边界,必须相对候选高度计算覆盖率。+ and _vertical_rule_candidate_height_coverage(+ rule.bbox,+ candidate_bbox,+ )+ >= 0.6]if internal_vertical_rules:continuediff --git a/mineru/backend/flash/native_pdf/formulas.py b/mineru/backend/flash/native_pdf/formulas.pyindex 2120e188..26555adc 100644--- a/mineru/backend/flash/native_pdf/formulas.py+++ b/mineru/backend/flash/native_pdf/formulas.py@@ -858,10 +858,17 @@ def _is_isolated_compact_formula_cluster(return Falseif bbox[3] - bbox[1] > 3.0 * median_height:return False- if (- abs(_bbox_center_x(bbox) - 0.5 * (lane.left + lane.right))- > 0.2 * lane_width- ):+ center_delta_ratio = abs(+ _bbox_center_x(bbox) - 0.5 * (lane.left + lane.right)+ ) / lane_width+ left_indent_ratio = (bbox[0] - lane.left) / lane_width+ right_blank_ratio = (lane.right - bbox[2]) / lane_width+ # 部分期刊把独立公式按固定左缩进排版;同时要求右侧大留白,排除贴栏正文。+ deliberately_left_indented = (+ 0.03 <= left_indent_ratio <= 0.25+ and right_blank_ratio >= 0.35+ )+ if center_delta_ratio > 0.2 and not deliberately_left_indented:return Falsecandidate_center = _bbox_center_y(bbox)@@ -941,6 +948,8 @@ def _is_isolated_unnumbered_formula_line(return Falseif bbox[3] - bbox[1] > 1.8 * median_height:return False+ if _is_hanging_indent_tail_line(candidate, lane, median_height):+ return Falsecandidate_center = _bbox_center_y(bbox)if any(other_line.source_index != line.source_index@@ -986,6 +995,51 @@ def _is_isolated_unnumbered_formula_line()+def _is_hanging_indent_tail_line(+ candidate: tuple[_LineItem, BBox],+ lane: _TextLane,+ median_height: float,+) -> bool:+ """用相邻行缩进、字体和节奏识别参考条目的悬挂缩进尾行。"""++ line, bbox = candidate+ if line.font_signature is None:+ return False+ candidate_center = _bbox_center_y(bbox)+ rows_above = [+ item+ for item in lane.lines+ if item[0].source_index != line.source_index+ and _bbox_center_y(item[1]) < candidate_center+ ]+ rows_below = [+ item+ for item in lane.lines+ if item[0].source_index != line.source_index+ and _bbox_center_y(item[1]) > candidate_center+ ]+ if not rows_above or not rows_below:+ return False+ previous = max(rows_above, key=lambda item: _bbox_center_y(item[1]))+ following = min(rows_below, key=lambda item: _bbox_center_y(item[1]))+ previous_line, previous_bbox = previous+ _following_line, following_bbox = following+ previous_pitch = candidate_center - _bbox_center_y(previous_bbox)+ following_pitch = _bbox_center_y(following_bbox) - candidate_center+ lane_width = max(0.1, lane.right - lane.left)+ candidate_width = bbox[2] - bbox[0]+ previous_width = previous_bbox[2] - previous_bbox[0]+ return (+ previous_line.font_signature == line.font_signature+ and abs(previous_bbox[0] - bbox[0]) <= 0.5 * median_height+ and candidate_width <= 0.9 * previous_width+ and 0.65 * median_height <= previous_pitch <= 1.6 * median_height+ and 0.65 * median_height <= following_pitch <= 1.6 * median_height+ and following_bbox[0] <= bbox[0] - 1.5 * median_height+ and following_bbox[2] - following_bbox[0] >= 0.75 * lane_width+ )++def _has_nearby_punctuated_formula_number_anchor(candidate: tuple[_LineItem, BBox],lane: _TextLane,diff --git a/mineru/backend/flash/native_pdf/graphics.py b/mineru/backend/flash/native_pdf/graphics.pyindex 858856d8..89fc71a2 100644--- a/mineru/backend/flash/native_pdf/graphics.py+++ b/mineru/backend/flash/native_pdf/graphics.py@@ -76,6 +76,52 @@ def _form_supersedes_nested_bbox(form_bbox: BBox, nested_bbox: BBox) -> bool:)+def _tighten_form_image_bbox(+ source: _PageSource,+ form_bbox: BBox,+) -> BBox:+ """用充分的 Form 内部矢量与文本证据收紧空白容器,证据不足时保留原框。"""++ internal_paths = [+ path_info.bbox+ for path_info in source.path_infos+ if path_info.form_depth > 0+ and _bbox_overlap_in_first(path_info.bbox, form_bbox) >= 0.9+ ]+ internal_drawing_lines = [+ drawing_line.bbox+ for drawing_line in source.drawing_lines+ if _bbox_overlap_in_first(drawing_line.bbox, form_bbox) >= 0.9+ ]+ # 至少两个嵌套 Path 和四个矢量元素,避免只凭普通边框或少量文本裁剪 Form。+ if len(internal_paths) < 2 or len(internal_paths) + len(internal_drawing_lines) < 4:+ return form_bbox+ internal_text = [+ line.bbox+ for line in source.lines+ if _bbox_overlap_in_first(line.bbox, form_bbox) >= 0.9+ ]+ evidence_bbox = _clip_bbox(+ _bbox_union_many(+ internal_paths + internal_drawing_lines + internal_text+ ),+ source.page_size,+ )+ if evidence_bbox is None:+ return form_bbox+ form_width = max(0.1, form_bbox[2] - form_bbox[0])+ form_height = max(0.1, form_bbox[3] - form_bbox[1])+ evidence_width = evidence_bbox[2] - evidence_bbox[0]+ evidence_height = evidence_bbox[3] - evidence_bbox[1]+ if (+ evidence_width < 0.5 * form_width+ or evidence_height < 0.5 * form_height+ or _bbox_area(evidence_bbox) < 0.25 * _bbox_area(form_bbox)+ ):+ return form_bbox+ return evidence_bbox++def _select_form_image_bboxes(source: _PageSource) -> list[BBox]:"""按页面占比、行高和内部视觉证据筛选矢量 Form 图片候选。"""@@ -114,7 +160,7 @@ def _select_form_image_bboxes(source: _PageSource) -> list[BBox]:)if len(member_rows) < 2 and internal_drawing_count < 4:continue- output.append(bbox)+ output.append(_tighten_form_image_bbox(source, bbox))return sorted(output, key=lambda bbox: (bbox[1], bbox[0], bbox[3], bbox[2]))@@ -726,11 +772,22 @@ def _is_graphic_label_member(else:primary_length = line.bbox[2] - line.bbox[0]core_primary_length = core_bbox[2] - core_bbox[0]- if primary_length > min(5.0 * line_height, 0.5 * core_primary_length):- return Falsehorizontal_gap = max(core_bbox[0] - line.bbox[2], line.bbox[0] - core_bbox[2], 0.0)vertical_gap = max(core_bbox[1] - line.bbox[3], line.bbox[1] - core_bbox[3], 0.0)+ # 横排坐标轴标题允许比刻度标签略长,但必须与图宽、行高和上下间距同时相容。+ is_horizontal_axis_title = (+ line.angle in {0, 180}+ and primary_length <= 8.0 * line_height+ and primary_length <= 0.45 * core_primary_length+ and _bbox_axis_overlap_ratio(line.bbox, core_bbox, axis="x") >= 0.15+ and vertical_gap <= 2.5 * median_height+ )+ if is_horizontal_axis_title:+ return True+ if primary_length > min(5.0 * line_height, 0.5 * core_primary_length):+ return False+if _bbox_axis_overlap_ratio(line.bbox, core_bbox, axis="x") >= 0.15:return vertical_gap <= margin_scale * median_heightif _bbox_axis_overlap_ratio(line.bbox, core_bbox, axis="y") >= 0.15:diff --git a/mineru/backend/flash/native_pdf/pipeline.py b/mineru/backend/flash/native_pdf/pipeline.pyindex 6f1969c1..fa15adf7 100644--- a/mineru/backend/flash/native_pdf/pipeline.py+++ b/mineru/backend/flash/native_pdf/pipeline.py@@ -285,8 +285,10 @@ def _prepare_page_source(source: _PageSource) -> _PreparedPage:for form_bbox in form_bboxes)]+ # 候选检测仍避开预分类边缘文本;已确认表格物化时回到原始行,+ # 让 core_bbox 内的误标页脚可被重新认领,表格外边缘文本不会被矩形扩张带入。table_blocks, claimed_line_indices = _materialize_table_blocks(- analysis_source,+ source,candidates,)claimed_line_indices.update(claimed_rule_code_line_indices)diff --git a/tests/unittest/test_flash_pdf_code_blocks.py b/tests/unittest/test_flash_pdf_code_blocks.pyindex 5cb84094..dad38e96 100644--- a/tests/unittest/test_flash_pdf_code_blocks.py+++ b/tests/unittest/test_flash_pdf_code_blocks.py@@ -210,3 +210,28 @@ def test_rule_delimited_listing_rejects_real_table_internal_grid() -> None:assert blocks == []assert claimed == set()+++def test_rule_delimited_listing_rejects_vertical_track_spanning_candidate() -> None:+ """验证跨越上下边界的长竖轨按候选高度计量并否决伪代码区域。"""++ source = _rule_delimited_code_source()+ source.drawing_lines.append(+ models._AxisLine(+ (70.0, 0.0, 71.0, 250.0),+ 1.0,+ "vertical",+ )+ )++ blocks, claimed = code_blocks._build_rule_delimited_code_blocks(+ source,+ [],+ )++ assert code_blocks._vertical_rule_candidate_height_coverage(+ source.drawing_lines[-1].bbox,+ (20.0, 20.0, 180.0, 105.0),+ ) == 1.0+ assert blocks == []+ assert claimed == set()diff --git a/tests/unittest/test_flash_pdf_formulas.py b/tests/unittest/test_flash_pdf_formulas.pyindex 6472b9ed..75fb5482 100644--- a/tests/unittest/test_flash_pdf_formulas.py+++ b/tests/unittest/test_flash_pdf_formulas.py@@ -725,6 +725,121 @@ def test_compact_multiline_cluster_becomes_one_isolated_equation() -> None:assert compact_cluster not in remaining+ ("candidate_bbox", "expected_equation_count"),+ [+ ((5.0, 36.0, 38.0, 46.0), 1),+ ((0.0, 36.0, 33.0, 46.0), 0),+ ],+ ids=["deliberate-indent", "flush-left"],+)+def test_compact_formula_accepts_deliberate_indent_but_rejects_flush_left(+ candidate_bbox: tuple[float, float, float, float],+ expected_equation_count: int,+) -> None:+ """验证正文间紧凑公式可按明确左缩进升级,贴栏短文本仍保留为正文。"""++ body_font = ("Body", 0)+ candidate = replace(+ _text_line(+ "F = dY, G = dX",+ candidate_bbox,+ 2,+ effective_height=10.0,+ font_signature=("Math", 1),+ font_coverage=0.5,+ ),+ compact_formula_cluster=True,+ )+ lines = [+ _text_line(+ "body above",+ (0.0, 20.0, 100.0, 30.0),+ 0,+ effective_height=10.0,+ font_signature=body_font,+ font_coverage=1.0,+ ),+ candidate,+ _text_line(+ "body below",+ (0.0, 52.0, 100.0, 62.0),+ 1,+ effective_height=10.0,+ font_signature=body_font,+ font_coverage=1.0,+ ),+ ]++ blocks, remaining = formulas._build_formula_like_blocks(+ lines,+ [],+ (100.0, 100.0),+ )++ assert len(blocks) == expected_equation_count+ assert (candidate in remaining) is (expected_equation_count == 0)+++def test_hanging_indent_reference_tail_is_not_unnumbered_equation() -> None:+ """验证同字体续行后接左突新条目的短尾行不会因偶然居中升级为公式。"""++ body_font = ("Body", 0)+ reference_font = ("Reference", 0)+ candidate = _text_line(+ "short reference tail",+ (15.0, 36.0, 85.0, 46.0),+ 2,+ effective_height=10.0,+ font_signature=reference_font,+ font_coverage=0.5,+ )+ lines = [+ _text_line(+ "body above",+ (0.0, 0.0, 100.0, 10.0),+ 0,+ effective_height=10.0,+ font_signature=body_font,+ font_coverage=1.0,+ ),+ _text_line(+ "long reference continuation",+ (15.0, 24.0, 95.0, 34.0),+ 1,+ effective_height=10.0,+ font_signature=reference_font,+ font_coverage=1.0,+ ),+ candidate,+ _text_line(+ "next reference entry",+ (0.0, 48.0, 100.0, 58.0),+ 3,+ effective_height=10.0,+ font_signature=body_font,+ font_coverage=1.0,+ ),+ _text_line(+ "body below",+ (0.0, 60.0, 100.0, 70.0),+ 4,+ effective_height=10.0,+ font_signature=body_font,+ font_coverage=1.0,+ ),+ ]++ blocks, remaining = formulas._build_formula_like_blocks(+ lines,+ [],+ (100.0, 100.0),+ )++ assert blocks == []+ assert candidate in remaining++def _build_compact_margin_case(candidate_bbox: tuple[float, float, float, float],above_bbox: tuple[float, float, float, float],diff --git a/tests/unittest/test_flash_pdf_graphics.py b/tests/unittest/test_flash_pdf_graphics.pyindex adff3170..43914527 100644--- a/tests/unittest/test_flash_pdf_graphics.py+++ b/tests/unittest/test_flash_pdf_graphics.py@@ -37,6 +37,7 @@ def _path_info(segment_count: int = 5,fill_visible: bool = True,stroke_visible: bool = False,+ form_depth: int = 0,) -> PDFPathInfo:"""构造强图形核心测试使用的根层 PDF Path。"""@@ -45,7 +46,7 @@ def _path_info(segment_count=segment_count,fill_visible=fill_visible,stroke_visible=stroke_visible,- form_depth=0,+ form_depth=form_depth,source_index=source_index,)@@ -286,6 +287,77 @@ def test_form_image_claims_internal_text_and_small_table_but_not_caption() -> No]+def test_form_image_bbox_tightens_to_supported_internal_evidence() -> None:+ """验证含充分嵌套 Path 的 Form 去除空白边缘,文本轻微越界仍纳入证据并裁到页面。"""++ source = models._PageSource(+ page_size=(120.0, 120.0),+ lines=[+ _text_line("top label", (20.0, 25.0, 70.0, 34.0), 0),+ _text_line("bottom label", (25.0, 68.0, 80.0, 81.0), 1),+ ],+ chars=[],+ drawing_lines=[+ _drawing_axis_line("horizontal", (20.0, 25.0, 85.0, 25.5)),+ _drawing_axis_line("horizontal", (20.0, 75.0, 85.0, 75.5)),+ _drawing_axis_line("vertical", (20.0, 25.0, 20.5, 75.0)),+ _drawing_axis_line("vertical", (84.5, 25.0, 85.0, 75.0)),+ ],+ form_bboxes=[(10.0, 10.0, 100.0, 80.0)],+ path_infos=[+ _path_info((20.0, 25.0, 80.0, 70.0), 0, form_depth=1),+ _path_info((25.0, 30.0, 85.0, 75.0), 1, form_depth=1),+ ],+ )++ assert graphics._select_form_image_bboxes(source) == [+ (20.0, 25.0, 85.0, 81.0)+ ]+++def test_graphic_label_absorbs_short_axis_title_but_rejects_long_caption() -> None:+ """验证上下坐标轴标题可放宽到八倍行高,长图注仍被图形容器拒绝。"""++ core_bbox = (20.0, 30.0, 140.0, 80.0)+ top_axis_title = _text_line(+ "axis title",+ (20.0, 17.0, 70.0, 25.0),+ 0,+ effective_height=8.0,+ )+ bottom_axis_title = _text_line(+ "axis title",+ (80.0, 85.0, 115.0, 91.0),+ 1,+ effective_height=6.0,+ )+ long_caption = _text_line(+ "a deliberately long figure caption",+ (20.0, 85.0, 140.0, 93.0),+ 2,+ effective_height=8.0,+ )++ assert graphics._is_graphic_label_member(+ top_axis_title,+ core_bbox,+ 8.0,+ margin_scale=1.0,+ )+ assert graphics._is_graphic_label_member(+ bottom_axis_title,+ core_bbox,+ 8.0,+ margin_scale=1.0,+ )+ assert not graphics._is_graphic_label_member(+ long_caption,+ core_bbox,+ 8.0,+ margin_scale=1.0,+ )++def _inline_raster_sequence_source() -> models._PageSource:"""构造四张点阵图、三个同行间隔符及其右侧三行正文。"""diff --git a/tests/unittest/test_flash_pdf_pipeline.py b/tests/unittest/test_flash_pdf_pipeline.pyindex f86e5265..ebf3c4a4 100644--- a/tests/unittest/test_flash_pdf_pipeline.py+++ b/tests/unittest/test_flash_pdf_pipeline.py@@ -38,6 +38,55 @@ def _image_info(return PDFImageInfo(bbox=bbox, fingerprint=fingerprint)+def test_prepare_page_materializes_table_against_original_semantic_lines(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """验证表格检测避开预分类行,但物化阶段可看到 core 内误标页脚。"""++ body = _text_line("body", (10.0, 10.0, 90.0, 20.0), 0)+ footer = _text_line(+ "table tail",+ (10.0, 80.0, 40.0, 90.0),+ 1,+ semantic_type="footer",+ )+ source = models._PageSource(+ page_size=(100.0, 100.0),+ lines=[body, footer],+ chars=[],+ drawing_lines=[],+ )+ observed: dict[str, list[int]] = {}++ def fake_detect(+ analysis_source: models._PageSource,+ *,+ excluded_bboxes: list[tuple[float, float, float, float]],+ ) -> list[models._TableCandidate]:+ """记录候选检测阶段可见的来源行。"""++ assert excluded_bboxes == []+ observed["detect"] = [line.source_index for line in analysis_source.lines]+ return []++ def fake_materialize(+ materialization_source: models._PageSource,+ candidates: list[models._TableCandidate],+ ) -> tuple[list[dict[str, object]], set[int]]:+ """记录表格物化阶段可见的来源行。"""++ assert candidates == []+ observed["materialize"] = [+ line.source_index for line in materialization_source.lines+ ]+ return [], set()++ monkeypatch.setattr(pipeline, "_detect_table_candidates", fake_detect)+ monkeypatch.setattr(pipeline, "_materialize_table_blocks", fake_materialize)++ pipeline._prepare_page_source(source)++ assert observed == {"detect": [0], "materialize": [0, 1]}def test_repeated_large_image_requires_three_distinct_pages() -> None:"""验证同页重复只计一次,面积恰好 8% 且跨三页时才命中水印。"""diff --git a/tests/unittest/test_flash_pdf_samples.py b/tests/unittest/test_flash_pdf_samples.pyindex 7562dcc3..acf9185a 100644--- a/tests/unittest/test_flash_pdf_samples.py+++ b/tests/unittest/test_flash_pdf_samples.py@@ -36,6 +36,16 @@ def _txt_model_list(pdf_name: str) -> list[list[dict[str, Any]]]:)+def _auto_model_list(pdf_name: str) -> list[list[dict[str, Any]]]:+ """通过稳定公共入口以 auto 模式解析仓库内最小回归 PDF。"""++ pdf_path = Path(__file__).parents[2] / "demo" / "pdfs" / pdf_name+ return pdf_extractor.doc_analyze(+ pdf_path.read_bytes(),+ parse_mode="auto",+ )++def _native_table_counts(pdf_name: str) -> list[int]:"""返回仓库内数字 PDF 样例的逐页表格块数量。"""@@ -180,6 +190,7 @@ def test_demo2_page1_forms_sixteen_blocks_and_keeps_figure_caption_separate() ->assert "Figure 1:" not in graphic_block["content"]assert "Left camera" not in caption_block["content"]assert sum(block["content"].count("Left camera") for block in page) == 1+ assert graphic_block["bbox"] == [0.516, 0.311, 0.913, 0.442]copyright_block = next(blockfor block in page@@ -906,6 +917,31 @@ def test_demo5_targeted_table_and_footer_regressions() -> None:]assert not residual_text+ repaired_table_bboxes = {+ 23: [0.034, 0.151, 0.968, 0.696],+ 24: [0.034, 0.151, 0.968, 0.696],+ 36: [0.033, 0.151, 0.967, 0.525],+ 71: [0.057, 0.151, 0.943, 0.685],+ 75: [0.057, 0.151, 0.943, 0.684],+ 81: [0.143, 0.086, 0.857, 0.785],+ }+ for page_number, expected_bbox in repaired_table_bboxes.items():+ page = model_list[page_number - 1]+ table_blocks = [block for block in page if block["type"] == "table"]+ assert [block["bbox"] for block in table_blocks] == [expected_bbox]+ assert not [block for block in page if block["type"] == "code"]+ assert not [+ block+ for block in page+ if block["type"] in {"text", "header"}+ and expected_bbox[0]+ <= (block["bbox"][0] + block["bbox"][2]) / 2+ <= expected_bbox[2]+ and expected_bbox[1]+ <= (block["bbox"][1] + block["bbox"][3]) / 2+ <= expected_bbox[3]+ ]+page77_note = _blocks_containing(model_list[76], "注:(1)指气量")assert len(page77_note) == 1assert page77_note[0]["type"] == "text"@@ -1037,7 +1073,7 @@ def test_mixed_elements_pages_03_06_force_txt_regressions() -> None:page5 = model_list[2]axis_label = _blocks_containing(page5, "T–1/4, K–1/4")assert len(axis_label) == 1- assert axis_label[0]["type"] == "text"+ assert axis_label[0]["type"] == "image"assert _blocks_containing(page5, "MIKOLAICHUK et al.")[0]["type"] == "header"assert len([block for block in page5 if block["type"] == "footer"]) == 1lower_graphs = [@@ -1046,8 +1082,63 @@ def test_mixed_elements_pages_03_06_force_txt_regressions() -> None:if block["type"] == "image" and block["bbox"][1] >= 0.6]assert len(lower_graphs) == 1- assert lower_graphs[0]["bbox"][2] <= 0.48+ assert lower_graphs[0]["bbox"] == [0.096, 0.634, 0.46, 0.862]+ assert "σT1/2, S K1/2/m" in str(lower_graphs[0]["content"])+ assert "T–1/4, K–1/4" in str(lower_graphs[0]["content"])assert "ular films." not in str(lower_graphs[0]["content"])+ figure4_caption = _blocks_containing(page5, "Fig. 4. Plots of σT1/2")+ assert len(figure4_caption) == 1+ assert figure4_caption[0]["type"] == "text"+++def test_caibao_table_reclaims_repeated_dates_but_keeps_real_marginals() -> None:+ """验证财报两页表格回收底部日期行,免责声明与页码仍独立保留。"""++ model_list = _auto_model_list("caibao1_pages_10_11.pdf")++ assert len(model_list) == 2+ for page in model_list:+ tables_on_page = [block for block in page if block["type"] == "table"]+ footers = [block for block in page if block["type"] == "footer"]+ page_numbers = [block for block in page if block["type"] == "page_number"]+ assert len(tables_on_page) == len(footers) == len(page_numbers) == 1+ assert "2024 年 07 月" in str(tables_on_page[0]["content"])+ assert footers[0]["content"] == "免责声明和披露以及分析师声明是报告的一部分,请务必一起阅读。"+ assert "2024 年" not in str(footers[0]["content"])+ assert tables_on_page[0]["bbox"][3] < footers[0]["bbox"][1]+ assert tables_on_page[0]["bbox"][3] < page_numbers[0]["bbox"][1]+++def test_iebm_left_indented_compact_formula_is_equation() -> None:+ """验证右栏左缩进紧凑公式通过公共 auto 入口输出为 equation。"""++ page = _auto_model_list("IEBM_A_2667169_O-5_page_1.pdf")[0]+ target = [+ block+ for block in page+ if block["bbox"] == [0.532, 0.292, 0.658, 0.312]+ ]++ assert len(target) == 1+ assert target[0]["type"] == "equation"+ assert target[0]["content"] == "F ¼ @ψ @Y, G ¼ @ψ @X."+++def test_frozen_soil_reference_tails_remain_single_text_blocks() -> None:+ """验证三条悬挂缩进参考文献尾行不再误报 equation,且各自仅出现一次。"""++ page = _auto_model_list("frozen_soil_ensemble_page_9.pdf")[0]++ assert not [block for block in page if block["type"] == "equation"]+ for probe in (+ "分析[J]. 深空探测学报,2023",+ "形变监测[J]. 测绘通报,2025",+ "岩爆预测[J]. 高压物理学报,2025",+ ):+ matches = _blocks_containing(page, probe)+ assert len(matches) == 1+ assert matches[0]["type"] == "text"+ assert str(matches[0]["content"]).count(probe) == 1def test_mixed_elements_pages_07_10_force_txt_regressions() -> None:diff --git a/tests/unittest/test_flash_pdf_tables.py b/tests/unittest/test_flash_pdf_tables.pyindex 12337172..7cdadea6 100644--- a/tests/unittest/test_flash_pdf_tables.py+++ b/tests/unittest/test_flash_pdf_tables.py@@ -270,6 +270,71 @@ def test_filled_grid_materialization_uses_existing_spatial_projection(]+def test_table_core_reclaims_semantic_line_without_touching_outer_marginals(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """验证 core 内预标页脚可被表格认领,表框外页脚与页码保持未认领。"""++ lines = [+ models._LineItem(+ text="cell",+ bbox=(10.0, 10.0, 40.0, 20.0),+ angle=0,+ source_index=0,+ effective_height=10.0,+ ),+ models._LineItem(+ text="table tail",+ bbox=(10.0, 40.0, 40.0, 50.0),+ angle=0,+ source_index=1,+ effective_height=10.0,+ semantic_type="footer",+ ),+ models._LineItem(+ text="disclaimer",+ bbox=(10.0, 70.0, 60.0, 80.0),+ angle=0,+ source_index=2,+ effective_height=10.0,+ semantic_type="footer",+ ),+ models._LineItem(+ text="1",+ bbox=(90.0, 70.0, 95.0, 80.0),+ angle=0,+ source_index=3,+ effective_height=10.0,+ semantic_type="page_number",+ ),+ ]+ source = models._PageSource(+ page_size=(100.0, 100.0),+ lines=lines,+ chars=[],+ drawing_lines=[],+ )+ candidate = models._TableCandidate(+ bbox=(0.0, 0.0, 80.0, 60.0),+ local_bbox=(0.0, 0.0, 80.0, 60.0),+ angle=0,+ score=1.0,+ core_bbox=(0.0, 0.0, 80.0, 60.0),+ line_indices={0},+ )+ projection = MagicMock(return_value="cell\ntable tail")+ monkeypatch.setattr(tables, "project_pdf_table_text", projection)++ blocks, claimed = tables._materialize_table_blocks(source, [candidate])++ assert len(blocks) == 1+ assert claimed == {0, 1}+ assert {line.source_index for line in lines if line.source_index not in claimed} == {+ 2,+ 3,+ }++@pytest.mark.parametrize(("median_height", "rejected_length", "accepted_length"),[