Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pdf-miner
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Qin Kaijie
pdf-miner
Commits
433684c6
Commit
433684c6
authored
Mar 27, 2024
by
kernel.h@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实现多模态markdown拼装
parent
fffee0ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
3 deletions
+34
-3
pipeline_txt.py
magic_pdf/pipeline_txt.py
+34
-3
No files found.
magic_pdf/pipeline_txt.py
View file @
433684c6
...
...
@@ -2,17 +2,19 @@
文本型pdf转化为统一清洗格式
"""
# TODO 移动到spark/目录下
from
loguru
import
logger
from
magic_pdf.dict2md.mkcontent
import
mk_universal_format
from
magic_pdf.dict2md.mkcontent
import
mk_
mm_markdown
,
mk_
universal_format
from
magic_pdf.libs.commons
import
join_path
from
magic_pdf.libs.json_compressor
import
JsonCompressor
from
magic_pdf.spark.base
import
exception_handler
,
get_data_source
def
txt_pdf_to_standard_format
(
jso
:
dict
,
debug_mode
=
False
)
->
dict
:
"""
变成统一的标准格式
"""
if
debug_mode
:
pass
else
:
# 如果debug没开,则检测是否有needdrop字段
...
...
@@ -35,3 +37,32 @@ def txt_pdf_to_standard_format(jso: dict, debug_mode=False) -> dict:
except
Exception
as
e
:
jso
=
exception_handler
(
jso
,
e
)
return
jso
def
txt_pdf_to_mm_markdown_format
(
jso
:
dict
,
debug_mode
=
False
)
->
dict
:
"""
变成多模态的markdown格式
"""
if
debug_mode
:
pass
else
:
# 如果debug没开,则检测是否有needdrop字段
if
jso
.
get
(
"need_drop"
,
False
):
book_name
=
join_path
(
get_data_source
(
jso
),
jso
[
"file_id"
])
logger
.
info
(
f
"book_name is:{book_name} need drop"
)
jso
[
"dropped"
]
=
True
return
jso
try
:
pdf_intermediate_dict
=
jso
[
"pdf_intermediate_dict"
]
# 将 pdf_intermediate_dict 解压
pdf_intermediate_dict
=
JsonCompressor
.
decompress_json
(
pdf_intermediate_dict
)
standard_format
=
mk_universal_format
(
pdf_intermediate_dict
)
mm_content
=
mk_mm_markdown
(
standard_format
)
jso
[
"content_list"
]
=
mm_content
logger
.
info
(
f
"book_name is:{get_data_source(jso)}/{jso['file_id']},content_list length is {len(standard_format)}"
,)
# 把无用的信息清空
jso
[
"doc_layout_result"
]
=
""
jso
[
"pdf_intermediate_dict"
]
=
""
jso
[
"pdf_meta"
]
=
""
except
Exception
as
e
:
jso
=
exception_handler
(
jso
,
e
)
return
jso
\ No newline at end of file
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