Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

fix: enhance table merging logic to support additional continuation markers

myhlolia4b07a0d1fc6
diff --git a/mineru/backend/vlm/vlm_magic_model.py b/mineru/backend/vlm/vlm_magic_model.py
index 3e9ab03c..315a3f2f 100644
--- a/mineru/backend/vlm/vlm_magic_model.py
+++ b/mineru/backend/vlm/vlm_magic_model.py
@@ -45,7 +45,7 @@ class MagicModel:
continue
span_type = "unknown"
- line_type = None
+ code_block_sub_type = None
guess_lang = None
if block_type in [
@@ -74,7 +74,7 @@ class MagicModel:
span_type = ContentType.TABLE
elif block_type in ["code", "algorithm"]:
block_content = code_content_clean(block_content)
- line_type = block_type
+ code_block_sub_type = block_type
block_type = BlockType.CODE_BODY
span_type = ContentType.TEXT
guess_lang = guess_language_by_text(block_content)
@@ -82,6 +82,9 @@ class MagicModel:
block_type = BlockType.INTERLINE_EQUATION
span_type = ContentType.INTERLINE_EQUATION
+ # code 和 algorithm 类型的块,如果内容中包含行内公式,则需要将块类型切换为algorithm
+ switch_code_to_algorithm = False
+
if span_type in ["image", "table"]:
span = {
"bbox": block_bbox,
@@ -102,6 +105,8 @@ class MagicModel:
if block_content and block_content.count("\\(") == block_content.count("\\)") and block_content.count("\\(") > 0:
+ switch_code_to_algorithm = True
+
# 生成包含文本和公式的span列表
spans = []
last_end = 0
@@ -160,7 +165,9 @@ class MagicModel:
# 构造line对象
if block_type in [BlockType.CODE_BODY]:
- line = {"bbox": block_bbox, "spans": spans, "extra": {"type": line_type, "guess_lang": guess_lang}}
+ if switch_code_to_algorithm and code_block_sub_type == "code":
+ code_block_sub_type = "algorithm"
+ line = {"bbox": block_bbox, "spans": spans, "extra": {"type": code_block_sub_type, "guess_lang": guess_lang}}
else:
line = {"bbox": block_bbox, "spans": spans}
diff --git a/mineru/utils/table_merge.py b/mineru/utils/table_merge.py
index 6c96897c..dff0a79b 100644
--- a/mineru/utils/table_merge.py
+++ b/mineru/utils/table_merge.py
@@ -7,6 +7,9 @@ from mineru.backend.vlm.vlm_middle_json_mkcontent import merge_para_with_text
from mineru.utils.enum_class import BlockType, SplitFlag
+continuation_markers = ["(续)", "(续表)", "(continued)", "(cont.)"]
+
+
def full_to_half(text: str) -> str:
"""Convert full-width characters to half-width characters using code point manipulation.
@@ -174,8 +177,13 @@ def can_merge_tables(current_table_block, previous_table_block):
# 如果有TABLE_CAPTION类型的块,检查是否至少有一个以"(续)"结尾
caption_blocks = [block for block in current_table_block["blocks"] if block["type"] == BlockType.TABLE_CAPTION]
if caption_blocks:
- # 如果所有caption都不以"(续)"结尾,则不合并
- if not any(full_to_half(merge_para_with_text(block).strip()).endswith("(续)") for block in caption_blocks):
+ # 如果所有caption都不以"(续)"、"(续表)"、"(continued)"或"(cont.)"结尾,则不合并
+
+ if not any(
+ any(full_to_half(merge_para_with_text(block).strip()).lower().endswith(marker)
+ for marker in continuation_markers)
+ for block in caption_blocks
+ ):
return False, None, None, None, None
if any(block["type"] == BlockType.TABLE_FOOTNOTE for block in previous_table_block["blocks"]):