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
1d81631b
Unverified
Commit
1d81631b
authored
Apr 25, 2024
by
myhloli
Committed by
GitHub
Apr 25, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74 from myhloli/master
add para_to_standard_format logic
parents
a4b687e8
d3542f6a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
12 deletions
+55
-12
magicpdf.py
magic_pdf/cli/magicpdf.py
+7
-7
ocr_mkcontent.py
magic_pdf/dict2md/ocr_mkcontent.py
+46
-4
AbsPipe.py
magic_pdf/pipe/AbsPipe.py
+2
-1
No files found.
magic_pdf/cli/magicpdf.py
View file @
1d81631b
...
@@ -84,13 +84,13 @@ def _do_parse(pdf_file_name, pdf_bytes, model_list, parse_method, image_writer,
...
@@ -84,13 +84,13 @@ def _do_parse(pdf_file_name, pdf_bytes, model_list, parse_method, image_writer,
path
=
f
"{pdf_file_name}.json"
,
path
=
f
"{pdf_file_name}.json"
,
mode
=
AbsReaderWriter
.
MODE_TXT
,
mode
=
AbsReaderWriter
.
MODE_TXT
,
)
)
#
try:
try
:
#
content_list = pipe.pipe_mk_uni_format()
content_list
=
pipe
.
pipe_mk_uni_format
()
#
except Exception as e:
except
Exception
as
e
:
#
logger.exception(e)
logger
.
exception
(
e
)
#
md_writer.write(
md_writer
.
write
(
# str(content_list), f"{part
_file_name}.txt", AbsReaderWriter.MODE_TXT
str
(
content_list
),
f
"{pdf
_file_name}.txt"
,
AbsReaderWriter
.
MODE_TXT
#
)
)
@
click
.
group
()
@
click
.
group
()
...
...
magic_pdf/dict2md/ocr_mkcontent.py
View file @
1d81631b
...
@@ -201,15 +201,57 @@ def para_to_standard_format(para, img_buket_path):
...
@@ -201,15 +201,57 @@ def para_to_standard_format(para, img_buket_path):
return
para_content
return
para_content
def
para_to_standard_format_v2
(
para_block
,
img_buket_path
):
para_type
=
para_block
[
'type'
]
if
para_type
==
BlockType
.
Text
:
para_content
=
{
'type'
:
'text'
,
'text'
:
merge_para_with_text
(
para_block
),
}
elif
para_type
==
BlockType
.
Title
:
para_content
=
{
'type'
:
'text'
,
'text'
:
merge_para_with_text
(
para_block
),
'text_level'
:
1
}
elif
para_type
==
BlockType
.
InterlineEquation
:
para_content
=
{
'type'
:
'equation'
,
'text'
:
merge_para_with_text
(
para_block
),
'text_format'
:
"latex"
}
elif
para_type
==
BlockType
.
Image
:
para_content
=
{
'type'
:
'image'
,
}
for
block
in
para_block
[
'blocks'
]:
if
block
[
'type'
]
==
BlockType
.
ImageBody
:
para_content
[
'img_path'
]
=
join_path
(
img_buket_path
,
block
[
"lines"
][
0
][
"spans"
][
0
][
'image_path'
])
if
block
[
'type'
]
==
BlockType
.
ImageCaption
:
para_content
[
'img_caption'
]
=
merge_para_with_text
(
block
)
elif
para_type
==
BlockType
.
Table
:
para_content
=
{
'type'
:
'table'
,
}
for
block
in
para_block
[
'blocks'
]:
if
block
[
'type'
]
==
BlockType
.
TableBody
:
para_content
[
'img_path'
]
=
join_path
(
img_buket_path
,
block
[
"lines"
][
0
][
"spans"
][
0
][
'image_path'
])
if
block
[
'type'
]
==
BlockType
.
TableCaption
:
para_content
[
'table_caption'
]
=
merge_para_with_text
(
block
)
if
block
[
'type'
]
==
BlockType
.
TableFootnote
:
para_content
[
'table_footnote'
]
=
merge_para_with_text
(
block
)
return
para_content
def
make_standard_format_with_para
(
pdf_info_dict
:
list
,
img_buket_path
:
str
):
def
make_standard_format_with_para
(
pdf_info_dict
:
list
,
img_buket_path
:
str
):
content_list
=
[]
content_list
=
[]
for
page_info
in
pdf_info_dict
:
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
for
paras
in
paras_of_layout
:
for
para_block
in
paras_of_layout
:
for
para
in
paras
:
para_content
=
para_to_standard_format_v2
(
para_block
,
img_buket_path
)
para_content
=
para_to_standard_format
(
para
,
img_buket_path
)
content_list
.
append
(
para_content
)
content_list
.
append
(
para_content
)
return
content_list
return
content_list
...
...
magic_pdf/pipe/AbsPipe.py
View file @
1d81631b
...
@@ -92,7 +92,8 @@ class AbsPipe(ABC):
...
@@ -92,7 +92,8 @@ class AbsPipe(ABC):
parse_type
=
pdf_mid_data
[
"_parse_type"
]
parse_type
=
pdf_mid_data
[
"_parse_type"
]
pdf_info_list
=
pdf_mid_data
[
"pdf_info"
]
pdf_info_list
=
pdf_mid_data
[
"pdf_info"
]
if
parse_type
==
AbsPipe
.
PIP_TXT
:
if
parse_type
==
AbsPipe
.
PIP_TXT
:
content_list
=
mk_universal_format
(
pdf_info_list
,
img_buket_path
)
# content_list = mk_universal_format(pdf_info_list, img_buket_path)
content_list
=
make_standard_format_with_para
(
pdf_info_list
,
img_buket_path
)
elif
parse_type
==
AbsPipe
.
PIP_OCR
:
elif
parse_type
==
AbsPipe
.
PIP_OCR
:
content_list
=
make_standard_format_with_para
(
pdf_info_list
,
img_buket_path
)
content_list
=
make_standard_format_with_para
(
pdf_info_list
,
img_buket_path
)
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