Skip to content

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

feat: add function to identify transparent visual relation blocks in visual_magic_model_utils.py

myhloli072a71795657
diff --git a/mineru/utils/visual_magic_model_utils.py b/mineru/utils/visual_magic_model_utils.py
index 467e814a..b091fd5e 100644
--- a/mineru/utils/visual_magic_model_utils.py
+++ b/mineru/utils/visual_magic_model_utils.py
@@ -190,6 +190,17 @@ def _block_text_content(block):
)
+def is_transparent_visual_relation_block(block):
+ """判断视觉关系中可忽略的结构性空块。"""
+ if block.get("type") != BlockType.LIST:
+ return False
+
+ if block.get("blocks"):
+ return False
+
+ return not _block_text_content(block).strip()
+
+
def _is_leading_continuation_cluster_near_table(leading_blocks, table_block):
"""判断页首续表文本簇是否与后续 table 在几何上相邻。"""
next_top = table_block["bbox"][1]
@@ -370,14 +381,19 @@ def regroup_visual_blocks(blocks):
effective_blocks = [
block for block in ordered_blocks if block["index"] not in absorbed_member_indices
]
+ visual_relation_blocks = [
+ block
+ for block in effective_blocks
+ if not is_transparent_visual_relation_block(block)
+ ]
position_by_index = {
- block["index"]: pos for pos, block in enumerate(effective_blocks)
+ block["index"]: pos for pos, block in enumerate(visual_relation_blocks)
}
main_blocks = [
- block for block in effective_blocks if block["type"] in VISUAL_MAIN_TYPES
+ block for block in visual_relation_blocks if block["type"] in VISUAL_MAIN_TYPES
]
child_blocks = [
- block for block in effective_blocks if block["type"] in GENERIC_CHILD_TYPES
+ block for block in visual_relation_blocks if block["type"] in GENERIC_CHILD_TYPES
]
grouped_children = {
@@ -393,7 +409,7 @@ def regroup_visual_blocks(blocks):
parent_block = find_best_visual_parent(
child_block,
main_blocks,
- effective_blocks,
+ visual_relation_blocks,
position_by_index,
)
if parent_block is None: