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
1f186f5f
Commit
1f186f5f
authored
Apr 15, 2024
by
赵小蒙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix pdf_info_dict dict->list
parent
cf3e8519
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
ocr_mkcontent.py
magic_pdf/dict2md/ocr_mkcontent.py
+14
-12
No files found.
magic_pdf/dict2md/ocr_mkcontent.py
View file @
1f186f5f
...
@@ -17,10 +17,10 @@ def split_long_words(text):
...
@@ -17,10 +17,10 @@ def split_long_words(text):
return
' '
.
join
(
segments
)
return
' '
.
join
(
segments
)
def
ocr_mk_nlp_markdown
(
pdf_info_dict
:
dic
t
):
def
ocr_mk_nlp_markdown
(
pdf_info_dict
:
lis
t
):
markdown
=
[]
markdown
=
[]
for
_
,
page_info
in
pdf_info_dict
.
items
()
:
for
page_info
in
pdf_info_dict
:
blocks
=
page_info
.
get
(
"preproc_blocks"
)
blocks
=
page_info
.
get
(
"preproc_blocks"
)
if
not
blocks
:
if
not
blocks
:
continue
continue
...
@@ -41,10 +41,10 @@ def ocr_mk_nlp_markdown(pdf_info_dict: dict):
...
@@ -41,10 +41,10 @@ def ocr_mk_nlp_markdown(pdf_info_dict: dict):
return
'
\n
'
.
join
(
markdown
)
return
'
\n
'
.
join
(
markdown
)
def
ocr_mk_mm_markdown
(
pdf_info_dict
:
dic
t
):
def
ocr_mk_mm_markdown
(
pdf_info_dict
:
lis
t
):
markdown
=
[]
markdown
=
[]
for
_
,
page_info
in
pdf_info_dict
.
items
()
:
for
page_info
in
pdf_info_dict
:
blocks
=
page_info
.
get
(
"preproc_blocks"
)
blocks
=
page_info
.
get
(
"preproc_blocks"
)
if
not
blocks
:
if
not
blocks
:
continue
continue
...
@@ -78,17 +78,18 @@ def ocr_mk_mm_markdown_with_para(pdf_info_list: list, img_buket_path):
...
@@ -78,17 +78,18 @@ def ocr_mk_mm_markdown_with_para(pdf_info_list: list, img_buket_path):
return
'
\n\n
'
.
join
(
markdown
)
return
'
\n\n
'
.
join
(
markdown
)
def
ocr_mk_nlp_markdown_with_para
(
pdf_info_dict
:
dic
t
):
def
ocr_mk_nlp_markdown_with_para
(
pdf_info_dict
:
lis
t
):
markdown
=
[]
markdown
=
[]
for
_
,
page_info
in
pdf_info_dict
.
items
()
:
for
page_info
in
pdf_info_dict
:
paras_of_layout
=
page_info
.
get
(
"para_blocks"
)
paras_of_layout
=
page_info
.
get
(
"para_blocks"
)
page_markdown
=
ocr_mk_markdown_with_para_core
(
paras_of_layout
,
"nlp"
)
page_markdown
=
ocr_mk_markdown_with_para_core
(
paras_of_layout
,
"nlp"
)
markdown
.
extend
(
page_markdown
)
markdown
.
extend
(
page_markdown
)
return
'
\n\n
'
.
join
(
markdown
)
return
'
\n\n
'
.
join
(
markdown
)
def
ocr_mk_mm_markdown_with_para_and_pagination
(
pdf_info_dict
:
dic
t
):
def
ocr_mk_mm_markdown_with_para_and_pagination
(
pdf_info_dict
:
lis
t
):
markdown_with_para_and_pagination
=
[]
markdown_with_para_and_pagination
=
[]
for
page_no
,
page_info
in
pdf_info_dict
.
items
():
page_no
=
0
for
page_info
in
pdf_info_dict
:
paras_of_layout
=
page_info
.
get
(
"para_blocks"
)
paras_of_layout
=
page_info
.
get
(
"para_blocks"
)
if
not
paras_of_layout
:
if
not
paras_of_layout
:
continue
continue
...
@@ -97,6 +98,7 @@ def ocr_mk_mm_markdown_with_para_and_pagination(pdf_info_dict: dict):
...
@@ -97,6 +98,7 @@ def ocr_mk_mm_markdown_with_para_and_pagination(pdf_info_dict: dict):
'page_no'
:
page_no
,
'page_no'
:
page_no
,
'md_content'
:
'
\n\n
'
.
join
(
page_markdown
)
'md_content'
:
'
\n\n
'
.
join
(
page_markdown
)
})
})
page_no
+=
1
return
markdown_with_para_and_pagination
return
markdown_with_para_and_pagination
...
@@ -171,9 +173,9 @@ def para_to_standard_format(para, img_buket_path):
...
@@ -171,9 +173,9 @@ def para_to_standard_format(para, img_buket_path):
}
}
return
para_content
return
para_content
def
make_standard_format_with_para
(
pdf_info_dict
:
dic
t
,
img_buket_path
:
str
):
def
make_standard_format_with_para
(
pdf_info_dict
:
lis
t
,
img_buket_path
:
str
):
content_list
=
[]
content_list
=
[]
for
_
,
page_info
in
pdf_info_dict
.
items
()
:
for
page_info
in
pdf_info_dict
:
paras_of_layout
=
page_info
.
get
(
"para_blocks"
)
paras_of_layout
=
page_info
.
get
(
"para_blocks"
)
if
not
paras_of_layout
:
if
not
paras_of_layout
:
continue
continue
...
@@ -227,7 +229,7 @@ def line_to_standard_format(line, img_buket_path):
...
@@ -227,7 +229,7 @@ def line_to_standard_format(line, img_buket_path):
return
content
return
content
def
ocr_mk_mm_standard_format
(
pdf_info_dict
:
dic
t
):
def
ocr_mk_mm_standard_format
(
pdf_info_dict
:
lis
t
):
"""
"""
content_list
content_list
type string image/text/table/equation(行间的单独拿出来,行内的和text合并)
type string image/text/table/equation(行间的单独拿出来,行内的和text合并)
...
@@ -237,7 +239,7 @@ def ocr_mk_mm_standard_format(pdf_info_dict: dict):
...
@@ -237,7 +239,7 @@ def ocr_mk_mm_standard_format(pdf_info_dict: dict):
img_path string s3://full/path/to/img.jpg
img_path string s3://full/path/to/img.jpg
"""
"""
content_list
=
[]
content_list
=
[]
for
_
,
page_info
in
pdf_info_dict
.
items
()
:
for
page_info
in
pdf_info_dict
:
blocks
=
page_info
.
get
(
"preproc_blocks"
)
blocks
=
page_info
.
get
(
"preproc_blocks"
)
if
not
blocks
:
if
not
blocks
:
continue
continue
...
...
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