grobid-client-python 0.0.8__py3-none-any.whl → 0.0.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- grobid_client/grobid_client.py +42 -3
- grobid_client_python-0.0.11.dist-info/METADATA +431 -0
- grobid_client_python-0.0.11.dist-info/RECORD +8 -0
- {grobid_client_python-0.0.8.dist-info → grobid_client_python-0.0.11.dist-info}/WHEEL +1 -1
- {grobid_client_python-0.0.8.dist-info → grobid_client_python-0.0.11.dist-info}/entry_points.txt +0 -1
- grobid_client_python-0.0.8.dist-info/LICENSE +0 -203
- grobid_client_python-0.0.8.dist-info/METADATA +0 -200
- grobid_client_python-0.0.8.dist-info/RECORD +0 -9
- {grobid_client_python-0.0.8.dist-info → grobid_client_python-0.0.11.dist-info}/top_level.txt +0 -0
grobid_client/grobid_client.py
CHANGED
|
@@ -71,8 +71,10 @@ class GrobidClient(ApiClient):
|
|
|
71
71
|
|
|
72
72
|
if status != 200:
|
|
73
73
|
print("GROBID server does not appear up and running " + str(status))
|
|
74
|
+
return False, status
|
|
74
75
|
else:
|
|
75
76
|
print("GROBID server is up and running")
|
|
77
|
+
return True, status
|
|
76
78
|
|
|
77
79
|
def _output_file_name(self, input_file, input_path, output):
|
|
78
80
|
# we use ntpath here to be sure it will work on Windows too
|
|
@@ -90,6 +92,13 @@ class GrobidClient(ApiClient):
|
|
|
90
92
|
|
|
91
93
|
return filename
|
|
92
94
|
|
|
95
|
+
def ping(self) -> (bool, int):
|
|
96
|
+
"""
|
|
97
|
+
Check the Grobid service. Returns True if the service is up.
|
|
98
|
+
In addition, returns also the status code.
|
|
99
|
+
"""
|
|
100
|
+
return self._test_server_connection()
|
|
101
|
+
|
|
93
102
|
def process(
|
|
94
103
|
self,
|
|
95
104
|
service,
|
|
@@ -105,6 +114,7 @@ class GrobidClient(ApiClient):
|
|
|
105
114
|
segment_sentences=False,
|
|
106
115
|
force=True,
|
|
107
116
|
verbose=False,
|
|
117
|
+
flavor=None
|
|
108
118
|
):
|
|
109
119
|
batch_size_pdf = self.config["batch_size"]
|
|
110
120
|
input_files = []
|
|
@@ -138,6 +148,7 @@ class GrobidClient(ApiClient):
|
|
|
138
148
|
segment_sentences,
|
|
139
149
|
force,
|
|
140
150
|
verbose,
|
|
151
|
+
flavor
|
|
141
152
|
)
|
|
142
153
|
input_files = []
|
|
143
154
|
|
|
@@ -176,6 +187,7 @@ class GrobidClient(ApiClient):
|
|
|
176
187
|
segment_sentences,
|
|
177
188
|
force,
|
|
178
189
|
verbose=False,
|
|
190
|
+
flavor=None
|
|
179
191
|
):
|
|
180
192
|
if verbose:
|
|
181
193
|
print(len(input_files), "files to process in current batch")
|
|
@@ -194,6 +206,9 @@ class GrobidClient(ApiClient):
|
|
|
194
206
|
selected_process = self.process_pdf
|
|
195
207
|
if service == 'processCitationList':
|
|
196
208
|
selected_process = self.process_txt
|
|
209
|
+
|
|
210
|
+
if verbose:
|
|
211
|
+
print(f"Adding {input_file} to the queue.")
|
|
197
212
|
|
|
198
213
|
r = executor.submit(
|
|
199
214
|
selected_process,
|
|
@@ -205,7 +220,10 @@ class GrobidClient(ApiClient):
|
|
|
205
220
|
include_raw_citations,
|
|
206
221
|
include_raw_affiliations,
|
|
207
222
|
tei_coordinates,
|
|
208
|
-
segment_sentences
|
|
223
|
+
segment_sentences,
|
|
224
|
+
flavor,
|
|
225
|
+
-1,
|
|
226
|
+
-1)
|
|
209
227
|
|
|
210
228
|
results.append(r)
|
|
211
229
|
|
|
@@ -244,7 +262,10 @@ class GrobidClient(ApiClient):
|
|
|
244
262
|
include_raw_citations,
|
|
245
263
|
include_raw_affiliations,
|
|
246
264
|
tei_coordinates,
|
|
247
|
-
segment_sentences
|
|
265
|
+
segment_sentences,
|
|
266
|
+
flavor=None,
|
|
267
|
+
start=-1,
|
|
268
|
+
end=-1
|
|
248
269
|
):
|
|
249
270
|
pdf_handle = open(pdf_file, "rb")
|
|
250
271
|
files = {
|
|
@@ -274,6 +295,12 @@ class GrobidClient(ApiClient):
|
|
|
274
295
|
the_data["teiCoordinates"] = self.config["coordinates"]
|
|
275
296
|
if segment_sentences:
|
|
276
297
|
the_data["segmentSentences"] = "1"
|
|
298
|
+
if flavor:
|
|
299
|
+
the_data["flavor"] = flavor
|
|
300
|
+
if start and start > 0:
|
|
301
|
+
the_data["start"] = str(start)
|
|
302
|
+
if end and end > 0:
|
|
303
|
+
the_data["end"] = str(end)
|
|
277
304
|
|
|
278
305
|
try:
|
|
279
306
|
res, status = self.post(
|
|
@@ -291,7 +318,10 @@ class GrobidClient(ApiClient):
|
|
|
291
318
|
include_raw_citations,
|
|
292
319
|
include_raw_affiliations,
|
|
293
320
|
tei_coordinates,
|
|
294
|
-
segment_sentences
|
|
321
|
+
segment_sentences,
|
|
322
|
+
start,
|
|
323
|
+
end,
|
|
324
|
+
flavor
|
|
295
325
|
)
|
|
296
326
|
except requests.exceptions.ReadTimeout:
|
|
297
327
|
pdf_handle.close()
|
|
@@ -351,6 +381,7 @@ class GrobidClient(ApiClient):
|
|
|
351
381
|
|
|
352
382
|
def main():
|
|
353
383
|
valid_services = [
|
|
384
|
+
"processFulltextDocumentBlank",
|
|
354
385
|
"processFulltextDocument",
|
|
355
386
|
"processHeaderDocument",
|
|
356
387
|
"processReferences",
|
|
@@ -424,11 +455,18 @@ def main():
|
|
|
424
455
|
help="print information about processed files in the console",
|
|
425
456
|
)
|
|
426
457
|
|
|
458
|
+
parser.add_argument(
|
|
459
|
+
"--flavor",
|
|
460
|
+
default=None,
|
|
461
|
+
help="Define the flavor to be used for the fulltext extraction",
|
|
462
|
+
)
|
|
463
|
+
|
|
427
464
|
args = parser.parse_args()
|
|
428
465
|
|
|
429
466
|
input_path = args.input
|
|
430
467
|
config_path = args.config
|
|
431
468
|
output_path = args.output
|
|
469
|
+
flavor = args.flavor
|
|
432
470
|
|
|
433
471
|
if args.n is not None:
|
|
434
472
|
try:
|
|
@@ -483,6 +521,7 @@ def main():
|
|
|
483
521
|
segment_sentences=segment_sentences,
|
|
484
522
|
force=force,
|
|
485
523
|
verbose=verbose,
|
|
524
|
+
flavor=flavor
|
|
486
525
|
)
|
|
487
526
|
|
|
488
527
|
runtime = round(time.time() - start_time, 3)
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: grobid-client-python
|
|
3
|
+
Version: 0.0.11
|
|
4
|
+
Summary: Simple python client for GROBID REST services
|
|
5
|
+
Author-email: Patrice Lopez <patrice.lopez@science-miner.com>
|
|
6
|
+
Maintainer-email: Patrice Lopez <patrice.lopez@science-miner.com>, Luca Foppiano <lucanoro@duck.com>
|
|
7
|
+
License:
|
|
8
|
+
Apache License
|
|
9
|
+
Version 2.0, January 2004
|
|
10
|
+
http://www.apache.org/licenses/
|
|
11
|
+
|
|
12
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
13
|
+
|
|
14
|
+
1. Definitions.
|
|
15
|
+
|
|
16
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
17
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
18
|
+
|
|
19
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
20
|
+
the copyright owner that is granting the License.
|
|
21
|
+
|
|
22
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
23
|
+
other entities that control, are controlled by, or are under common
|
|
24
|
+
control with that entity. For the purposes of this definition,
|
|
25
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
26
|
+
direction or management of such entity, whether by contract or
|
|
27
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
28
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
29
|
+
|
|
30
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
31
|
+
exercising permissions granted by this License.
|
|
32
|
+
|
|
33
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
34
|
+
including but not limited to software source code, documentation
|
|
35
|
+
source, and configuration files.
|
|
36
|
+
|
|
37
|
+
"Object" form shall mean any form resulting from mechanical
|
|
38
|
+
transformation or translation of a Source form, including but
|
|
39
|
+
not limited to compiled object code, generated documentation,
|
|
40
|
+
and conversions to other media types.
|
|
41
|
+
|
|
42
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
43
|
+
Object form, made available under the License, as indicated by a
|
|
44
|
+
copyright notice that is included in or attached to the work
|
|
45
|
+
(an example is provided in the Appendix below).
|
|
46
|
+
|
|
47
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
48
|
+
form, that is based on (or derived from) the Work and for which the
|
|
49
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
50
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
51
|
+
of this License, Derivative Works shall not include works that remain
|
|
52
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
53
|
+
the Work and Derivative Works thereof.
|
|
54
|
+
|
|
55
|
+
"Contribution" shall mean any work of authorship, including
|
|
56
|
+
the original version of the Work and any modifications or additions
|
|
57
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
58
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
59
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
60
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
61
|
+
means any form of electronic, verbal, or written communication sent
|
|
62
|
+
to the Licensor or its representatives, including but not limited to
|
|
63
|
+
communication on electronic mailing lists, source code control systems,
|
|
64
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
65
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
66
|
+
excluding communication that is conspicuously marked or otherwise
|
|
67
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
68
|
+
|
|
69
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
70
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
71
|
+
subsequently incorporated within the Work.
|
|
72
|
+
|
|
73
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
77
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
78
|
+
Work and such Derivative Works in Source or Object form.
|
|
79
|
+
|
|
80
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
(except as stated in this section) patent license to make, have made,
|
|
84
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
85
|
+
where such license applies only to those patent claims licensable
|
|
86
|
+
by such Contributor that are necessarily infringed by their
|
|
87
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
88
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
89
|
+
institute patent litigation against any entity (including a
|
|
90
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
91
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
92
|
+
or contributory patent infringement, then any patent licenses
|
|
93
|
+
granted to You under this License for that Work shall terminate
|
|
94
|
+
as of the date such litigation is filed.
|
|
95
|
+
|
|
96
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
97
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
98
|
+
modifications, and in Source or Object form, provided that You
|
|
99
|
+
meet the following conditions:
|
|
100
|
+
|
|
101
|
+
(a) You must give any other recipients of the Work or
|
|
102
|
+
Derivative Works a copy of this License; and
|
|
103
|
+
|
|
104
|
+
(b) You must cause any modified files to carry prominent notices
|
|
105
|
+
stating that You changed the files; and
|
|
106
|
+
|
|
107
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
108
|
+
that You distribute, all copyright, patent, trademark, and
|
|
109
|
+
attribution notices from the Source form of the Work,
|
|
110
|
+
excluding those notices that do not pertain to any part of
|
|
111
|
+
the Derivative Works; and
|
|
112
|
+
|
|
113
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
114
|
+
distribution, then any Derivative Works that You distribute must
|
|
115
|
+
include a readable copy of the attribution notices contained
|
|
116
|
+
within such NOTICE file, excluding those notices that do not
|
|
117
|
+
pertain to any part of the Derivative Works, in at least one
|
|
118
|
+
of the following places: within a NOTICE text file distributed
|
|
119
|
+
as part of the Derivative Works; within the Source form or
|
|
120
|
+
documentation, if provided along with the Derivative Works; or,
|
|
121
|
+
within a display generated by the Derivative Works, if and
|
|
122
|
+
wherever such third-party notices normally appear. The contents
|
|
123
|
+
of the NOTICE file are for informational purposes only and
|
|
124
|
+
do not modify the License. You may add Your own attribution
|
|
125
|
+
notices within Derivative Works that You distribute, alongside
|
|
126
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
127
|
+
that such additional attribution notices cannot be construed
|
|
128
|
+
as modifying the License.
|
|
129
|
+
|
|
130
|
+
You may add Your own copyright statement to Your modifications and
|
|
131
|
+
may provide additional or different license terms and conditions
|
|
132
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
133
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
134
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
135
|
+
the conditions stated in this License.
|
|
136
|
+
|
|
137
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
138
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
139
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
140
|
+
this License, without any additional terms or conditions.
|
|
141
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
142
|
+
the terms of any separate license agreement you may have executed
|
|
143
|
+
with Licensor regarding such Contributions.
|
|
144
|
+
|
|
145
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
146
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
147
|
+
except as required for reasonable and customary use in describing the
|
|
148
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
149
|
+
|
|
150
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
151
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
152
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
153
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
154
|
+
implied, including, without limitation, any warranties or conditions
|
|
155
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
156
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
157
|
+
appropriateness of using or redistributing the Work and assume any
|
|
158
|
+
risks associated with Your exercise of permissions under this License.
|
|
159
|
+
|
|
160
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
161
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
162
|
+
unless required by applicable law (such as deliberate and grossly
|
|
163
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
164
|
+
liable to You for damages, including any direct, indirect, special,
|
|
165
|
+
incidental, or consequential damages of any character arising as a
|
|
166
|
+
result of this License or out of the use or inability to use the
|
|
167
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
168
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
169
|
+
other commercial damages or losses), even if such Contributor
|
|
170
|
+
has been advised of the possibility of such damages.
|
|
171
|
+
|
|
172
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
173
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
174
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
175
|
+
or other liability obligations and/or rights consistent with this
|
|
176
|
+
License. However, in accepting such obligations, You may act only
|
|
177
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
178
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
179
|
+
defend, and hold each Contributor harmless for any liability
|
|
180
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
181
|
+
of your accepting any such warranty or additional liability.
|
|
182
|
+
|
|
183
|
+
END OF TERMS AND CONDITIONS
|
|
184
|
+
|
|
185
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
186
|
+
|
|
187
|
+
To apply the Apache License to your work, attach the following
|
|
188
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
189
|
+
replaced with your own identifying information. (Don't include
|
|
190
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
191
|
+
comment syntax for the file format. We also recommend that a
|
|
192
|
+
file or class name and description of purpose be included on the
|
|
193
|
+
same "printed page" as the copyright notice for easier
|
|
194
|
+
identification within third-party archives.
|
|
195
|
+
|
|
196
|
+
Copyright 2018-2024 The Contributors
|
|
197
|
+
|
|
198
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
199
|
+
you may not use this file except in compliance with the License.
|
|
200
|
+
You may obtain a copy of the License at
|
|
201
|
+
|
|
202
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
203
|
+
|
|
204
|
+
Unless required by applicable law or agreed to in writing, software
|
|
205
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
206
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
207
|
+
See the License for the specific language governing permissions and
|
|
208
|
+
limitations under the License.
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
Project-URL: Homepage, https://github.com/kermitt2/grobid_client_python
|
|
212
|
+
Project-URL: Repository, https://github.com/kermitt2/grobid_client_python
|
|
213
|
+
Project-URL: Changelog, https://github.com/kermitt2/grobid_client_python
|
|
214
|
+
Description-Content-Type: text/markdown
|
|
215
|
+
Requires-Dist: requests
|
|
216
|
+
|
|
217
|
+
[](https://badge.fury.io/py/grobid_client_python)
|
|
218
|
+
[](https://archive.softwareheritage.org/browse/origin/https://github.com/kermitt2/grobid_client_python/)
|
|
219
|
+
[](http://www.apache.org/licenses/LICENSE-2.0.html)
|
|
220
|
+
|
|
221
|
+
# Simple python client for GROBID REST services
|
|
222
|
+
|
|
223
|
+
This Python client can be used to process in an efficient concurrent manner a set of PDF in a given directory by the [GROBID](https://github.com/kermitt2/grobid) service. It includes a command line for processing PDF on a file system and write results in a given output directory and a library for import in other python scripts. The client can also process similarly a list of files with reference strings (one per line) and patents in XML ST36 formats.
|
|
224
|
+
|
|
225
|
+
## Before you start
|
|
226
|
+
|
|
227
|
+
Please be aware that, at the moment, [grobid does not support Windows](https://grobid.readthedocs.io/en/latest/Troubleshooting/#windows-related-issues).
|
|
228
|
+
If you are a Windows user, don't worry. You can still [run grobid
|
|
229
|
+
via Docker](https://grobid.readthedocs.io/en/latest/Grobid-docker/).
|
|
230
|
+
|
|
231
|
+
## Build and run
|
|
232
|
+
|
|
233
|
+
You need first a running *grobid* service, latest stable version, see the [documentation](http://grobid.readthedocs.io/) for installation.
|
|
234
|
+
By default, it is assumed that the server will run on the address `http://localhost:8070`.
|
|
235
|
+
You can change the server address by editing the file `config.json`, see below.
|
|
236
|
+
|
|
237
|
+
## Requirements
|
|
238
|
+
|
|
239
|
+
This client has been developed and was tested with Python `3.8`-`3.13` and should work with any higher `3.*` versions.
|
|
240
|
+
It uses `requests` as dependency beyond the Standard Python Library.
|
|
241
|
+
|
|
242
|
+
## Install
|
|
243
|
+
|
|
244
|
+
The client can be installed with any of the following ways:
|
|
245
|
+
|
|
246
|
+
* Install *latest stable release* from PyPI:
|
|
247
|
+
|
|
248
|
+
```console
|
|
249
|
+
python3 -m pip install grobid-client-python
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
* Install *current master development version* from GitHub:
|
|
253
|
+
|
|
254
|
+
```console
|
|
255
|
+
python3 -m pip install git+https://github.com/kermitt2/grobid_client_python.git
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
* Install and build from a clone of the repo (*current master development version*):
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
git clone https://github.com/kermitt2/grobid_client_python
|
|
262
|
+
cd grobid_client_python
|
|
263
|
+
pip install -e .
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
There is nothing more needed to start using the python command lines, see the next section.
|
|
267
|
+
|
|
268
|
+
## Usage and options
|
|
269
|
+
|
|
270
|
+
The call to the script can normally be realized interchangeably with `python3 -m grobid_client.grobid_client` or simply `grobid_client`.
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
usage: grobid_client [-h] [--input INPUT] [--output OUTPUT] [--config CONFIG]
|
|
274
|
+
[--n N] [--generateIDs] [--consolidate_header]
|
|
275
|
+
[--consolidate_citations] [--include_raw_citations]
|
|
276
|
+
[--include_raw_affiliations] [--force] [--teiCoordinates]
|
|
277
|
+
[--verbose]
|
|
278
|
+
service
|
|
279
|
+
|
|
280
|
+
Client for GROBID services
|
|
281
|
+
|
|
282
|
+
positional arguments:
|
|
283
|
+
service one of ['processFulltextDocument',
|
|
284
|
+
'processHeaderDocument', 'processReferences',
|
|
285
|
+
'processCitationList','processCitationPatentST36',
|
|
286
|
+
'processCitationPatentPDF']
|
|
287
|
+
|
|
288
|
+
optional arguments:
|
|
289
|
+
-h, --help show this help message and exit
|
|
290
|
+
--input INPUT path to the directory containing PDF files or .txt
|
|
291
|
+
(for processCitationList only, one reference per line)
|
|
292
|
+
to process
|
|
293
|
+
--output OUTPUT path to the directory where to put the results
|
|
294
|
+
(optional)
|
|
295
|
+
--config CONFIG path to the config file, default is ./config.json
|
|
296
|
+
--n N concurrency for service usage
|
|
297
|
+
--generateIDs generate random xml:id to textual XML elements of the
|
|
298
|
+
result files
|
|
299
|
+
--consolidate_header call GROBID with consolidation of the metadata
|
|
300
|
+
extracted from the header
|
|
301
|
+
--consolidate_citations
|
|
302
|
+
call GROBID with consolidation of the extracted
|
|
303
|
+
bibliographical references
|
|
304
|
+
--include_raw_citations
|
|
305
|
+
call GROBID requesting the extraction of raw citations
|
|
306
|
+
--include_raw_affiliations
|
|
307
|
+
call GROBID requestiong the extraciton of raw
|
|
308
|
+
affiliations
|
|
309
|
+
--force force re-processing pdf input files when tei output
|
|
310
|
+
files already exist
|
|
311
|
+
--teiCoordinates add the original PDF coordinates (bounding boxes) to
|
|
312
|
+
the extracted elements
|
|
313
|
+
--segmentSentences segment sentences in the text content of the document
|
|
314
|
+
with additional <s> elements
|
|
315
|
+
--verbose print information about processed files in the console
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Examples:
|
|
321
|
+
|
|
322
|
+
```console
|
|
323
|
+
> grobid_client --input ~/tmp/in2 --output ~/tmp/out processFulltextDocument
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
This command will process all the PDF files present under the input directory recursively (files with extension `.pdf` only) with the `processFulltextDocument` service of GROBID, and write the resulting XML TEI files under the output directory, reusing the file name with a different file extension (`.grobid.tei.xml`), using the default `10` concurrent workers.
|
|
327
|
+
|
|
328
|
+
If `--output` is omitted, the resulting XML TEI documents will be produced alongside the PDF in the `--input` directory.
|
|
329
|
+
|
|
330
|
+
```console
|
|
331
|
+
> grobid_client --input ~/tmp/in2 --output ~/tmp/out --n 20 processHeaderDocument
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
This command will process all the PDF files present in the input directory (files with extension `.pdf` only) with the `processHeaderDocument` service of GROBID, and write the resulting XML TEI files under the output directory, reusing the file name with a different file extension (`.grobid.tei.xml`), using `20` concurrent workers.
|
|
335
|
+
|
|
336
|
+
By default if an existing `.grobid.tei.xml` file is present in the output directory corresponding to a PDF in the input directory, this PDF will be skipped to avoid reprocessing several times the same PDF. To force the processing of PDF and over-write of existing TEI files, use the parameter `--force`.
|
|
337
|
+
|
|
338
|
+
`processCitationList` does not take a repertory of PDF as input, but a repertory of `.txt` files, with one reference raw string per line, for example:
|
|
339
|
+
|
|
340
|
+
```console
|
|
341
|
+
> grobid_client --input resources/test_txt/ --output resources/test_out/ --n 20 processCitationList
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
The following command example will process all the PDF files present in the input directory and add bounding box coordinates (`--teiCoordinates`) relative to the original PDFs for the elements listed in the config file. It will also segment the sentences (`--segmentSentences`, this is a "layout aware" sentence segmentation) in the identified paragraphs with bounding box coordinates for the sentences.
|
|
345
|
+
|
|
346
|
+
```console
|
|
347
|
+
> grobid_client --input ~/tmp/in2 --output ~/tmp/out --teiCoordinates --segmentSentences processFulltextDocument
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
The file `example.py` gives an example of usage as a library, from a another python script.
|
|
351
|
+
|
|
352
|
+
## Using the client in your python
|
|
353
|
+
|
|
354
|
+
Import and call the client as follow:
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
from grobid_client.grobid_client import GrobidClient
|
|
358
|
+
|
|
359
|
+
client = GrobidClient(config_path="./config.json")
|
|
360
|
+
client.process("processFulltextDocument", "/mnt/data/covid/pdfs", n=20)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
See also `example.py`.
|
|
364
|
+
|
|
365
|
+
## Configuration of the client
|
|
366
|
+
|
|
367
|
+
There are a few parameters that can be set with the `config.json` file.
|
|
368
|
+
|
|
369
|
+
- `grobid_server` indicates the URL of the GROBID server to be used by the client.
|
|
370
|
+
|
|
371
|
+
- `batch_size` is the the size of the pool of threads used by ThreadPoolExecutor, you normally don't want to change this. This should be a high number (default 1000) - but not too high to protect the memory on the machine running the client. This should not be confused with the concurrency parameter `n` which indicates how many parallel requests can be send to GROBID.
|
|
372
|
+
|
|
373
|
+
- `sleep_time` indicates in seconds the time to wait for sending a new request to GROBID when the server indicates that all its threads are currently used. The client need to re-send the query after a wait time that will allow the server to free some threads. This wait time usually depends on the service and the capacities of the server, we suggest 5-10 seconds for the `processFulltextDocument` service and 2 seconds for `processHeaderDocument` service.
|
|
374
|
+
|
|
375
|
+
- `timeout` is a client side timeout - the process on server side will still be running until the server finished the task or the server timeout is reached.
|
|
376
|
+
|
|
377
|
+
- `coordinates` indicates the structure XML elements that should contains PDF coordinates when the parameters `--teiCoordinates` is used see [here](https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/) for more details.
|
|
378
|
+
|
|
379
|
+
Here is the default `config.json` file for the client:
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
{
|
|
383
|
+
"grobid_server": "http://localhost:8070",
|
|
384
|
+
"batch_size": 1000,
|
|
385
|
+
"sleep_time": 5,
|
|
386
|
+
"timeout": 60,
|
|
387
|
+
"coordinates": [ "persName", "figure", "ref", "biblStruct", "formula", "s" ]
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Benchmarking
|
|
392
|
+
|
|
393
|
+
Full text processing of __136 PDF__ (total 3443 pages, in average 25 pages per PDF) on Intel Core i7-4790K CPU 4.00GHz, 4 cores (8 threads), 16GB memory, `n` being the concurrency parameter:
|
|
394
|
+
|
|
395
|
+
| n | runtime (s)| s/PDF | PDF/s |
|
|
396
|
+
|----|------------|-------|-------|
|
|
397
|
+
| 1 | 209.0 | 1.54 | 0.65 |
|
|
398
|
+
| 2 | 112.0 | 0.82 | 1.21 |
|
|
399
|
+
| 3 | 80.4 | 0.59 | 1.69 |
|
|
400
|
+
| 5 | 62.9 | 0.46 | 2.16 |
|
|
401
|
+
| 8 | 55.7 | 0.41 | 2.44 |
|
|
402
|
+
| 10 | 55.3 | 0.40 | 2.45 |
|
|
403
|
+
|
|
404
|
+

|
|
405
|
+
|
|
406
|
+
As complementary info, GROBID processing of header of the 136 PDF and with `n=10` takes 3.74 s (15 times faster than the complete full text processing because only the two first pages of the PDF are considered), 36 PDF/s.
|
|
407
|
+
|
|
408
|
+
In similar conditions, extraction and structuring of bibliographical references takes 26.9 s (5.1 PDF/s).
|
|
409
|
+
|
|
410
|
+
Processing of 3500 raw bibliographical take 4.3 s with `n=10` (814 references parsed per second).
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
## Developer notes
|
|
414
|
+
|
|
415
|
+
### New release
|
|
416
|
+
|
|
417
|
+
New releases can be published by using `bump-my-version`:
|
|
418
|
+
|
|
419
|
+
```shell
|
|
420
|
+
pip install bump-my-version
|
|
421
|
+
bump-my-version bump patch
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Use of `major`, `minor`, or `patch` or will increment the first, second or the third digit of the version, respectively.
|
|
425
|
+
The release will be published automatically on pypy.
|
|
426
|
+
|
|
427
|
+
## License and contact
|
|
428
|
+
|
|
429
|
+
Distributed under [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0).
|
|
430
|
+
|
|
431
|
+
Main author and contact: Patrice Lopez (<patrice.lopez@science-miner.com>)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
grobid_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
grobid_client/client.py,sha256=crvUiVnnkn6tFwO4lKQg2cTxAHZxCBAmeNSVtuL4ZA0,6009
|
|
3
|
+
grobid_client/grobid_client.py,sha256=bt5gdmUEkhKVojI0y5yO9bW1BLT1Mf8EZ2ZKZmjfkII,18071
|
|
4
|
+
grobid_client_python-0.0.11.dist-info/METADATA,sha256=bKQKYkH4mstcREl7H3fe5QztGgxuwDAaF7B4MX_dg84,23921
|
|
5
|
+
grobid_client_python-0.0.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
grobid_client_python-0.0.11.dist-info/entry_points.txt,sha256=-WwPi8D8eXEbDB6QvitvHjxSGBeyLCyFvAoZcaDGswQ,67
|
|
7
|
+
grobid_client_python-0.0.11.dist-info/top_level.txt,sha256=HnjgWxdJNKTLIN86XkgRAfVeEK4C71fc9X4fe7qdMvA,14
|
|
8
|
+
grobid_client_python-0.0.11.dist-info/RECORD,,
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Apache License
|
|
3
|
-
Version 2.0, January 2004
|
|
4
|
-
http://www.apache.org/licenses/
|
|
5
|
-
|
|
6
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
-
|
|
8
|
-
1. Definitions.
|
|
9
|
-
|
|
10
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
-
|
|
13
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
-
the copyright owner that is granting the License.
|
|
15
|
-
|
|
16
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
-
other entities that control, are controlled by, or are under common
|
|
18
|
-
control with that entity. For the purposes of this definition,
|
|
19
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
-
direction or management of such entity, whether by contract or
|
|
21
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
-
|
|
24
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
-
exercising permissions granted by this License.
|
|
26
|
-
|
|
27
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
-
including but not limited to software source code, documentation
|
|
29
|
-
source, and configuration files.
|
|
30
|
-
|
|
31
|
-
"Object" form shall mean any form resulting from mechanical
|
|
32
|
-
transformation or translation of a Source form, including but
|
|
33
|
-
not limited to compiled object code, generated documentation,
|
|
34
|
-
and conversions to other media types.
|
|
35
|
-
|
|
36
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
-
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
39
|
-
(an example is provided in the Appendix below).
|
|
40
|
-
|
|
41
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
-
form, that is based on (or derived from) the Work and for which the
|
|
43
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
-
of this License, Derivative Works shall not include works that remain
|
|
46
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
-
the Work and Derivative Works thereof.
|
|
48
|
-
|
|
49
|
-
"Contribution" shall mean any work of authorship, including
|
|
50
|
-
the original version of the Work and any modifications or additions
|
|
51
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
-
means any form of electronic, verbal, or written communication sent
|
|
56
|
-
to the Licensor or its representatives, including but not limited to
|
|
57
|
-
communication on electronic mailing lists, source code control systems,
|
|
58
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
-
excluding communication that is conspicuously marked or otherwise
|
|
61
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
-
|
|
63
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
-
subsequently incorporated within the Work.
|
|
66
|
-
|
|
67
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
-
Work and such Derivative Works in Source or Object form.
|
|
73
|
-
|
|
74
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
-
(except as stated in this section) patent license to make, have made,
|
|
78
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
-
where such license applies only to those patent claims licensable
|
|
80
|
-
by such Contributor that are necessarily infringed by their
|
|
81
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
-
institute patent litigation against any entity (including a
|
|
84
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
-
or contributory patent infringement, then any patent licenses
|
|
87
|
-
granted to You under this License for that Work shall terminate
|
|
88
|
-
as of the date such litigation is filed.
|
|
89
|
-
|
|
90
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding those notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
-
|
|
181
|
-
To apply the Apache License to your work, attach the following
|
|
182
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
-
replaced with your own identifying information. (Don't include
|
|
184
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
-
comment syntax for the file format. We also recommend that a
|
|
186
|
-
file or class name and description of purpose be included on the
|
|
187
|
-
same "printed page" as the copyright notice for easier
|
|
188
|
-
identification within third-party archives.
|
|
189
|
-
|
|
190
|
-
Copyright 2018-2024 The Contributors
|
|
191
|
-
|
|
192
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
-
you may not use this file except in compliance with the License.
|
|
194
|
-
You may obtain a copy of the License at
|
|
195
|
-
|
|
196
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
-
|
|
198
|
-
Unless required by applicable law or agreed to in writing, software
|
|
199
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
-
See the License for the specific language governing permissions and
|
|
202
|
-
limitations under the License.
|
|
203
|
-
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: grobid-client-python
|
|
3
|
-
Version: 0.0.8
|
|
4
|
-
Summary: Simple python client for GROBID REST services
|
|
5
|
-
Home-page: https://github.com/kermitt2/grobid_client_python
|
|
6
|
-
Author: kermitt2
|
|
7
|
-
License: LICENSE
|
|
8
|
-
Platform: UNKNOWN
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: requests
|
|
12
|
-
|
|
13
|
-
[](https://badge.fury.io/py/grobid_client_python)
|
|
14
|
-
[](https://archive.softwareheritage.org/browse/origin/https://github.com/kermitt2/grobid_client_python/)
|
|
15
|
-
[](http://www.apache.org/licenses/LICENSE-2.0.html)
|
|
16
|
-
|
|
17
|
-
# Simple python client for GROBID REST services
|
|
18
|
-
|
|
19
|
-
This Python client can be used to process in an efficient concurrent manner a set of PDF in a given directory by the [GROBID](https://github.com/kermitt2/grobid) service. It includes a command line for processing PDF on a file system and write results in a given output directory and a library for import in other python scripts. The client can also process similarly a list of files with reference strings (one per line) and patents in XML ST36 formats.
|
|
20
|
-
|
|
21
|
-
## Before you start
|
|
22
|
-
|
|
23
|
-
Please be aware that, at the moment, [grobid does not support Windows](https://grobid.readthedocs.io/en/latest/Troubleshooting/#windows-related-issues).
|
|
24
|
-
If you are a Windows user, don't worry. You can still [run grobid
|
|
25
|
-
via Docker](https://grobid.readthedocs.io/en/latest/Grobid-docker/).
|
|
26
|
-
|
|
27
|
-
## Build and run
|
|
28
|
-
|
|
29
|
-
You need first a running *grobid* service, latest stable version, see the [documentation](http://grobid.readthedocs.io/) for installation.
|
|
30
|
-
By default, it is assumed that the server will run on the address `http://localhost:8070`.
|
|
31
|
-
You can change the server address by editing the file `config.json`, see below.
|
|
32
|
-
|
|
33
|
-
## Requirements
|
|
34
|
-
|
|
35
|
-
This client has been developed and was tested with Python `3.5`-`3.9` and should work with any higher `3.*` versions. It uses `requests` as dependency beyond the Standard Python Library.
|
|
36
|
-
|
|
37
|
-
## Install
|
|
38
|
-
|
|
39
|
-
Get the github repo:
|
|
40
|
-
|
|
41
|
-
```console
|
|
42
|
-
git clone https://github.com/kermitt2/grobid_client_python
|
|
43
|
-
cd grobid_client_python
|
|
44
|
-
python3 setup.py install
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
There is nothing more needed to start using the python command lines, see the next section.
|
|
48
|
-
|
|
49
|
-
## Usage and options
|
|
50
|
-
|
|
51
|
-
The call to the script can normally be realized interchangeably with `python3 -m grobid_client.grobid_client` or simply `grobid_client`.
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
usage: grobid_client [-h] [--input INPUT] [--output OUTPUT] [--config CONFIG]
|
|
55
|
-
[--n N] [--generateIDs] [--consolidate_header]
|
|
56
|
-
[--consolidate_citations] [--include_raw_citations]
|
|
57
|
-
[--include_raw_affiliations] [--force] [--teiCoordinates]
|
|
58
|
-
[--verbose]
|
|
59
|
-
service
|
|
60
|
-
|
|
61
|
-
Client for GROBID services
|
|
62
|
-
|
|
63
|
-
positional arguments:
|
|
64
|
-
service one of ['processFulltextDocument',
|
|
65
|
-
'processHeaderDocument', 'processReferences',
|
|
66
|
-
'processCitationList','processCitationPatentST36',
|
|
67
|
-
'processCitationPatentPDF']
|
|
68
|
-
|
|
69
|
-
optional arguments:
|
|
70
|
-
-h, --help show this help message and exit
|
|
71
|
-
--input INPUT path to the directory containing PDF files or .txt
|
|
72
|
-
(for processCitationList only, one reference per line)
|
|
73
|
-
to process
|
|
74
|
-
--output OUTPUT path to the directory where to put the results
|
|
75
|
-
(optional)
|
|
76
|
-
--config CONFIG path to the config file, default is ./config.json
|
|
77
|
-
--n N concurrency for service usage
|
|
78
|
-
--generateIDs generate random xml:id to textual XML elements of the
|
|
79
|
-
result files
|
|
80
|
-
--consolidate_header call GROBID with consolidation of the metadata
|
|
81
|
-
extracted from the header
|
|
82
|
-
--consolidate_citations
|
|
83
|
-
call GROBID with consolidation of the extracted
|
|
84
|
-
bibliographical references
|
|
85
|
-
--include_raw_citations
|
|
86
|
-
call GROBID requesting the extraction of raw citations
|
|
87
|
-
--include_raw_affiliations
|
|
88
|
-
call GROBID requestiong the extraciton of raw
|
|
89
|
-
affiliations
|
|
90
|
-
--force force re-processing pdf input files when tei output
|
|
91
|
-
files already exist
|
|
92
|
-
--teiCoordinates add the original PDF coordinates (bounding boxes) to
|
|
93
|
-
the extracted elements
|
|
94
|
-
--segmentSentences segment sentences in the text content of the document
|
|
95
|
-
with additional <s> elements
|
|
96
|
-
--verbose print information about processed files in the console
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Examples:
|
|
102
|
-
|
|
103
|
-
```console
|
|
104
|
-
> grobid_client --input ~/tmp/in2 --output ~/tmp/out processFulltextDocument
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
This command will process all the PDF files present under the input directory recursively (files with extension `.pdf` only) with the `processFulltextDocument` service of GROBID, and write the resulting XML TEI files under the output directory, reusing the file name with a different file extension (`.grobid.tei.xml`), using the default `10` concurrent workers.
|
|
108
|
-
|
|
109
|
-
If `--output` is omitted, the resulting XML TEI documents will be produced alongside the PDF in the `--input` directory.
|
|
110
|
-
|
|
111
|
-
```console
|
|
112
|
-
> grobid_client --input ~/tmp/in2 --output ~/tmp/out --n 20 processHeaderDocument
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
This command will process all the PDF files present in the input directory (files with extension `.pdf` only) with the `processHeaderDocument` service of GROBID, and write the resulting XML TEI files under the output directory, reusing the file name with a different file extension (`.grobid.tei.xml`), using `20` concurrent workers.
|
|
116
|
-
|
|
117
|
-
By default if an existing `.grobid.tei.xml` file is present in the output directory corresponding to a PDF in the input directory, this PDF will be skipped to avoid reprocessing several times the same PDF. To force the processing of PDF and over-write of existing TEI files, use the parameter `--force`.
|
|
118
|
-
|
|
119
|
-
`processCitationList` does not take a repertory of PDF as input, but a repertory of `.txt` files, with one reference raw string per line, for example:
|
|
120
|
-
|
|
121
|
-
```console
|
|
122
|
-
> grobid_client --input resources/test_txt/ --output resources/test_out/ --n 20 processCitationList
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
The following command example will process all the PDF files present in the input directory and add bounding box coordinates (`--teiCoordinates`) relative to the original PDFs for the elements listed in the config file. It will also segment the sentences (`--segmentSentences`, this is a "layout aware" sentence segmentation) in the identified paragraphs with bounding box coordinates for the sentences.
|
|
126
|
-
|
|
127
|
-
```console
|
|
128
|
-
> grobid_client --input ~/tmp/in2 --output ~/tmp/out --teiCoordinates --segmentSentences processFulltextDocument
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
The file `example.py` gives an example of usage as a library, from a another python script.
|
|
132
|
-
|
|
133
|
-
## Using the client in your python
|
|
134
|
-
|
|
135
|
-
Import and call the client as follow:
|
|
136
|
-
|
|
137
|
-
```python
|
|
138
|
-
from grobid_client.grobid_client import GrobidClient
|
|
139
|
-
|
|
140
|
-
client = GrobidClient(config_path="./config.json")
|
|
141
|
-
client.process("processFulltextDocument", "/mnt/data/covid/pdfs", n=20)
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
See also `example.py`.
|
|
145
|
-
|
|
146
|
-
## Configuration of the client
|
|
147
|
-
|
|
148
|
-
There are a few parameters that can be set with the `config.json` file.
|
|
149
|
-
|
|
150
|
-
- `grobid_server` indicates the URL of the GROBID server to be used by the client.
|
|
151
|
-
|
|
152
|
-
- `batch_size` is the the size of the pool of threads used by ThreadPoolExecutor, you normally don't want to change this. This should be a high number (default 1000) - but not too high to protect the memory on the machine running the client. This should not be confused with the concurrency parameter `n` which indicates how many parallel requests can be send to GROBID.
|
|
153
|
-
|
|
154
|
-
- `sleep_time` indicates in seconds the time to wait for sending a new request to GROBID when the server indicates that all its threads are currently used. The client need to re-send the query after a wait time that will allow the server to free some threads. This wait time usually depends on the service and the capacities of the server, we suggest 5-10 seconds for the `processFulltextDocument` service and 2 seconds for `processHeaderDocument` service.
|
|
155
|
-
|
|
156
|
-
- `timeout` is a client side timeout - the process on server side will still be running until the server finished the task or the server timeout is reached.
|
|
157
|
-
|
|
158
|
-
- `coordinates` indicates the structure XML elements that should contains PDF coordinates when the parameters `--teiCoordinates` is used see [here](https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/) for more details.
|
|
159
|
-
|
|
160
|
-
Here is the default `config.json` file for the client:
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
{
|
|
164
|
-
"grobid_server": "http://localhost:8070",
|
|
165
|
-
"batch_size": 1000,
|
|
166
|
-
"sleep_time": 5,
|
|
167
|
-
"timeout": 60,
|
|
168
|
-
"coordinates": [ "persName", "figure", "ref", "biblStruct", "formula", "s" ]
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
## Benchmarking
|
|
173
|
-
|
|
174
|
-
Full text processing of __136 PDF__ (total 3443 pages, in average 25 pages per PDF) on Intel Core i7-4790K CPU 4.00GHz, 4 cores (8 threads), 16GB memory, `n` being the concurrency parameter:
|
|
175
|
-
|
|
176
|
-
| n | runtime (s)| s/PDF | PDF/s |
|
|
177
|
-
|----|------------|-------|-------|
|
|
178
|
-
| 1 | 209.0 | 1.54 | 0.65 |
|
|
179
|
-
| 2 | 112.0 | 0.82 | 1.21 |
|
|
180
|
-
| 3 | 80.4 | 0.59 | 1.69 |
|
|
181
|
-
| 5 | 62.9 | 0.46 | 2.16 |
|
|
182
|
-
| 8 | 55.7 | 0.41 | 2.44 |
|
|
183
|
-
| 10 | 55.3 | 0.40 | 2.45 |
|
|
184
|
-
|
|
185
|
-

|
|
186
|
-
|
|
187
|
-
As complementary info, GROBID processing of header of the 136 PDF and with `n=10` takes 3.74 s (15 times faster than the complete full text processing because only the two first pages of the PDF are considered), 36 PDF/s.
|
|
188
|
-
|
|
189
|
-
In similar conditions, extraction and structuring of bibliographical references takes 26.9 s (5.1 PDF/s).
|
|
190
|
-
|
|
191
|
-
Processing of 3500 raw bibliographical take 4.3 s with `n=10` (814 references parsed per second).
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
## License and contact
|
|
195
|
-
|
|
196
|
-
Distributed under [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0).
|
|
197
|
-
|
|
198
|
-
Main author and contact: Patrice Lopez (<patrice.lopez@science-miner.com>)
|
|
199
|
-
|
|
200
|
-
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
grobid_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
grobid_client/client.py,sha256=crvUiVnnkn6tFwO4lKQg2cTxAHZxCBAmeNSVtuL4ZA0,6009
|
|
3
|
-
grobid_client/grobid_client.py,sha256=DtZmkT-gOI4fTofJVRGmE3IPAf_atfJuNbJ5UsrbRWI,16966
|
|
4
|
-
grobid_client_python-0.0.8.dist-info/LICENSE,sha256=vQwwkhTEk9pIuT-iHOHva75JqcvJRnDLEnmQiolD4g8,11184
|
|
5
|
-
grobid_client_python-0.0.8.dist-info/METADATA,sha256=ZeSbBtlQx3DGz1KCu7-4fAxOujF3ah1nwVP4ayPMmo0,10131
|
|
6
|
-
grobid_client_python-0.0.8.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
7
|
-
grobid_client_python-0.0.8.dist-info/entry_points.txt,sha256=IfhMcY5YhUem5uQ4ku1HbfAWjNLvptr0wJbMUubrdCs,68
|
|
8
|
-
grobid_client_python-0.0.8.dist-info/top_level.txt,sha256=HnjgWxdJNKTLIN86XkgRAfVeEK4C71fc9X4fe7qdMvA,14
|
|
9
|
-
grobid_client_python-0.0.8.dist-info/RECORD,,
|
{grobid_client_python-0.0.8.dist-info → grobid_client_python-0.0.11.dist-info}/top_level.txt
RENAMED
|
File without changes
|