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
b7652171
Commit
b7652171
authored
Mar 26, 2024
by
赵小蒙
Browse files
make_standard_format_with_para逻辑更新
parent
3d2fcc9d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
10 deletions
+32
-10
magic_pdf/dict2md/ocr_mkcontent.py
magic_pdf/dict2md/ocr_mkcontent.py
+32
-10
No files found.
magic_pdf/dict2md/ocr_mkcontent.py
View file @
b7652171
...
@@ -109,12 +109,11 @@ def ocr_mk_mm_markdown_with_para_core(paras_of_layout, mode):
...
@@ -109,12 +109,11 @@ def ocr_mk_mm_markdown_with_para_core(paras_of_layout, mode):
span_type
=
span
.
get
(
'type'
)
span_type
=
span
.
get
(
'type'
)
content
=
''
content
=
''
if
span_type
==
ContentType
.
Text
:
if
span_type
==
ContentType
.
Text
:
content
=
split_long_words
(
span
[
'content'
])
content
=
ocr_escape_special_markdown_char
(
split_long_words
(
span
[
'content'
]))
# content = span['content']
elif
span_type
==
ContentType
.
InlineEquation
:
elif
span_type
==
ContentType
.
InlineEquation
:
content
=
f
"$
{
span
[
'content'
]
}
$"
content
=
f
"$
{
ocr_escape_special_markdown_char
(
span
[
'content'
]
)
}
$"
elif
span_type
==
ContentType
.
InterlineEquation
:
elif
span_type
==
ContentType
.
InterlineEquation
:
content
=
f
"
\n
$$
\n
{
span
[
'content'
]
}
\n
$$
\n
"
content
=
f
"
\n
$$
\n
{
ocr_escape_special_markdown_char
(
span
[
'content'
]
)
}
\n
$$
\n
"
elif
span_type
in
[
ContentType
.
Image
,
ContentType
.
Table
]:
elif
span_type
in
[
ContentType
.
Image
,
ContentType
.
Table
]:
if
mode
==
'mm'
:
if
mode
==
'mm'
:
content
=
f
"
\n

}
)
\n
"
content
=
f
"
\n

}
)
\n
"
...
@@ -129,16 +128,39 @@ def ocr_mk_mm_markdown_with_para_core(paras_of_layout, mode):
...
@@ -129,16 +128,39 @@ def ocr_mk_mm_markdown_with_para_core(paras_of_layout, mode):
return
page_markdown
return
page_markdown
def
para_to_standard_format
(
para
):
para_content
=
{}
if
len
(
para
)
==
1
:
para_content
=
line_to_standard_format
(
para
[
0
])
elif
len
(
para
)
>
1
:
para_text
=
''
inline_equation_num
=
0
for
line
in
para
:
for
span
in
line
[
'spans'
]:
span_type
=
span
.
get
(
'type'
)
if
span_type
==
ContentType
.
Text
:
content
=
ocr_escape_special_markdown_char
(
split_long_words
(
span
[
'content'
]))
elif
span_type
==
ContentType
.
InlineEquation
:
content
=
f
"$
{
ocr_escape_special_markdown_char
(
span
[
'content'
])
}
$"
inline_equation_num
+=
1
para_text
+=
content
+
' '
para_content
=
{
'type'
:
'text'
,
'text'
:
para_text
,
'inline_equation_num'
:
inline_equation_num
}
return
para_content
def
make_standard_format_with_para
(
pdf_info_dict
:
dict
):
def
make_standard_format_with_para
(
pdf_info_dict
:
dict
):
content_list
=
[]
content_list
=
[]
for
_
,
page_info
in
pdf_info_dict
.
items
():
for
_
,
page_info
in
pdf_info_dict
.
items
():
paras
=
page_info
.
get
(
"para_blocks"
)
paras
_of_layout
=
page_info
.
get
(
"para_blocks"
)
if
not
paras
:
if
not
paras
_of_layout
:
continue
continue
for
paras
in
paras_of_layout
:
for
para
in
paras
:
for
para
in
paras
:
for
line
in
para
:
para_content
=
para_to_standard_format
(
para
)
content
=
line_to_standard_format
(
line
)
content_list
.
append
(
para_content
)
content_list
.
append
(
content
)
return
content_list
return
content_list
...
...
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