Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
bd3a7b37
Unverified
Commit
bd3a7b37
authored
Feb 24, 2025
by
Xiaomeng Zhao
Committed by
GitHub
Feb 24, 2025
Browse files
Merge pull request #1757 from myhloli/dev
feat(pre_proc): add block type compatibility check for span allocation
parents
9fd10b66
19916856
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
2 deletions
+14
-2
magic_pdf/pre_proc/ocr_dict_merge.py
magic_pdf/pre_proc/ocr_dict_merge.py
+14
-2
No files found.
magic_pdf/pre_proc/ocr_dict_merge.py
View file @
bd3a7b37
...
@@ -60,6 +60,19 @@ def merge_spans_to_line(spans, threshold=0.6):
...
@@ -60,6 +60,19 @@ def merge_spans_to_line(spans, threshold=0.6):
return
lines
return
lines
def
span_block_type_compatible
(
span_type
,
block_type
):
if
span_type
in
[
ContentType
.
Text
,
ContentType
.
InlineEquation
]:
return
block_type
in
[
BlockType
.
Text
,
BlockType
.
Title
,
BlockType
.
ImageCaption
,
BlockType
.
ImageFootnote
,
BlockType
.
TableCaption
,
BlockType
.
TableFootnote
]
elif
span_type
==
ContentType
.
InterlineEquation
:
return
block_type
in
[
BlockType
.
InterlineEquation
]
elif
span_type
==
ContentType
.
Image
:
return
block_type
in
[
BlockType
.
ImageBody
]
elif
span_type
==
ContentType
.
Table
:
return
block_type
in
[
BlockType
.
TableBody
]
else
:
return
False
def
fill_spans_in_blocks
(
blocks
,
spans
,
radio
):
def
fill_spans_in_blocks
(
blocks
,
spans
,
radio
):
"""将allspans中的span按位置关系,放入blocks中."""
"""将allspans中的span按位置关系,放入blocks中."""
block_with_spans
=
[]
block_with_spans
=
[]
...
@@ -78,8 +91,7 @@ def fill_spans_in_blocks(blocks, spans, radio):
...
@@ -78,8 +91,7 @@ def fill_spans_in_blocks(blocks, spans, radio):
block_spans
=
[]
block_spans
=
[]
for
span
in
spans
:
for
span
in
spans
:
span_bbox
=
span
[
'bbox'
]
span_bbox
=
span
[
'bbox'
]
if
calculate_overlap_area_in_bbox1_area_ratio
(
if
calculate_overlap_area_in_bbox1_area_ratio
(
span_bbox
,
block_bbox
)
>
radio
and
span_block_type_compatible
(
span
[
'type'
],
block_type
):
span_bbox
,
block_bbox
)
>
radio
:
block_spans
.
append
(
span
)
block_spans
.
append
(
span
)
block_dict
[
'spans'
]
=
block_spans
block_dict
[
'spans'
]
=
block_spans
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment