grobid-client-python 0.1.4__py3-none-any.whl → 0.1.5__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 +54 -18
- {grobid_client_python-0.1.4.dist-info → grobid_client_python-0.1.5.dist-info}/METADATA +19 -11
- {grobid_client_python-0.1.4.dist-info → grobid_client_python-0.1.5.dist-info}/RECORD +6 -6
- {grobid_client_python-0.1.4.dist-info → grobid_client_python-0.1.5.dist-info}/WHEEL +1 -1
- {grobid_client_python-0.1.4.dist-info → grobid_client_python-0.1.5.dist-info}/entry_points.txt +0 -0
- {grobid_client_python-0.1.4.dist-info → grobid_client_python-0.1.5.dist-info}/top_level.txt +0 -0
grobid_client/grobid_client.py
CHANGED
|
@@ -20,6 +20,7 @@ import argparse
|
|
|
20
20
|
import time
|
|
21
21
|
import concurrent.futures
|
|
22
22
|
import ntpath
|
|
23
|
+
import re
|
|
23
24
|
import requests
|
|
24
25
|
import pathlib
|
|
25
26
|
import logging
|
|
@@ -39,6 +40,11 @@ class ServerUnavailableException(Exception):
|
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
class GrobidClient(ApiClient):
|
|
43
|
+
# Below this client-side timeout (in seconds) citation consolidation is
|
|
44
|
+
# likely to trigger HTTP 408 (Request Timeout) errors, so we warn the user.
|
|
45
|
+
# See https://github.com/grobidOrg/grobid-client-python/issues/54
|
|
46
|
+
CONSOLIDATE_CITATIONS_MIN_TIMEOUT = 120
|
|
47
|
+
|
|
42
48
|
# Default configuration values
|
|
43
49
|
DEFAULT_CONFIG = {
|
|
44
50
|
'grobid_server': 'http://localhost:8070',
|
|
@@ -112,6 +118,27 @@ class GrobidClient(ApiClient):
|
|
|
112
118
|
if value is not None:
|
|
113
119
|
self.config[key] = value
|
|
114
120
|
|
|
121
|
+
def _warn_on_consolidation_timeout(self, consolidate_citations):
|
|
122
|
+
"""Warn when citation consolidation is enabled with a low client timeout.
|
|
123
|
+
|
|
124
|
+
Consolidating citations makes GROBID query external services and can be
|
|
125
|
+
much slower than a plain extraction. A short client-side timeout often
|
|
126
|
+
leads to HTTP 408 errors, so we recommend at least a couple of minutes.
|
|
127
|
+
See https://github.com/grobidOrg/grobid-client-python/issues/54
|
|
128
|
+
"""
|
|
129
|
+
if not consolidate_citations:
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
timeout = self.config.get("timeout", self.DEFAULT_CONFIG["timeout"])
|
|
133
|
+
if timeout < self.CONSOLIDATE_CITATIONS_MIN_TIMEOUT:
|
|
134
|
+
self.logger.warning(
|
|
135
|
+
f"Citation consolidation is enabled but the timeout is only {timeout}s. "
|
|
136
|
+
f"Consolidation queries external services and can be slow; a low timeout "
|
|
137
|
+
f"frequently causes HTTP 408 (Request Timeout) errors. Consider increasing "
|
|
138
|
+
f"the 'timeout' setting to at least {self.CONSOLIDATE_CITATIONS_MIN_TIMEOUT}s "
|
|
139
|
+
f"(2-3 minutes is recommended)."
|
|
140
|
+
)
|
|
141
|
+
|
|
115
142
|
def _handle_server_busy_retry(self, file_path, retry_func, *args, **kwargs):
|
|
116
143
|
"""Handle server busy (503) retry logic."""
|
|
117
144
|
self.logger.warning(f"Server busy (503), retrying {file_path} after {self.config['sleep_time']} seconds")
|
|
@@ -209,7 +236,6 @@ class GrobidClient(ApiClient):
|
|
|
209
236
|
size_str = str(size_str).upper().strip()
|
|
210
237
|
|
|
211
238
|
# Extract number and unit
|
|
212
|
-
import re
|
|
213
239
|
match = re.match(r'(\d+(?:\.\d+)?)\s*([KMGT]?B?)', size_str)
|
|
214
240
|
if not match:
|
|
215
241
|
return 10 * 1024 * 1024 # Default 10MB
|
|
@@ -329,7 +355,7 @@ class GrobidClient(ApiClient):
|
|
|
329
355
|
input_path,
|
|
330
356
|
output=None,
|
|
331
357
|
n=10,
|
|
332
|
-
|
|
358
|
+
generate_ids=False,
|
|
333
359
|
consolidate_header=True,
|
|
334
360
|
consolidate_citations=False,
|
|
335
361
|
include_raw_citations=False,
|
|
@@ -345,6 +371,13 @@ class GrobidClient(ApiClient):
|
|
|
345
371
|
start_time = time.time()
|
|
346
372
|
batch_size_pdf = self.config["batch_size"]
|
|
347
373
|
|
|
374
|
+
# Warn if citation consolidation is requested with a short timeout: the
|
|
375
|
+
# consolidation step queries external services (e.g. CrossRef) and can
|
|
376
|
+
# be significantly slower, frequently resulting in HTTP 408 errors when
|
|
377
|
+
# the client-side timeout is too low.
|
|
378
|
+
# See https://github.com/grobidOrg/grobid-client-python/issues/54
|
|
379
|
+
self._warn_on_consolidation_timeout(consolidate_citations)
|
|
380
|
+
|
|
348
381
|
# First pass: count all eligible files
|
|
349
382
|
all_input_files = []
|
|
350
383
|
for (dirpath, dirnames, filenames) in os.walk(input_path):
|
|
@@ -391,7 +424,7 @@ class GrobidClient(ApiClient):
|
|
|
391
424
|
input_path,
|
|
392
425
|
output,
|
|
393
426
|
n,
|
|
394
|
-
|
|
427
|
+
generate_ids,
|
|
395
428
|
consolidate_header,
|
|
396
429
|
consolidate_citations,
|
|
397
430
|
include_raw_citations,
|
|
@@ -417,7 +450,7 @@ class GrobidClient(ApiClient):
|
|
|
417
450
|
input_path,
|
|
418
451
|
output,
|
|
419
452
|
n,
|
|
420
|
-
|
|
453
|
+
generate_ids,
|
|
421
454
|
consolidate_header,
|
|
422
455
|
consolidate_citations,
|
|
423
456
|
include_raw_citations,
|
|
@@ -455,7 +488,7 @@ class GrobidClient(ApiClient):
|
|
|
455
488
|
input_path,
|
|
456
489
|
output,
|
|
457
490
|
n,
|
|
458
|
-
|
|
491
|
+
generate_ids,
|
|
459
492
|
consolidate_header,
|
|
460
493
|
consolidate_citations,
|
|
461
494
|
include_raw_citations,
|
|
@@ -542,7 +575,7 @@ class GrobidClient(ApiClient):
|
|
|
542
575
|
selected_process,
|
|
543
576
|
service,
|
|
544
577
|
input_file,
|
|
545
|
-
|
|
578
|
+
generate_ids,
|
|
546
579
|
consolidate_header,
|
|
547
580
|
consolidate_citations,
|
|
548
581
|
include_raw_citations,
|
|
@@ -639,7 +672,7 @@ class GrobidClient(ApiClient):
|
|
|
639
672
|
self,
|
|
640
673
|
service,
|
|
641
674
|
pdf_file,
|
|
642
|
-
|
|
675
|
+
generate_ids,
|
|
643
676
|
consolidate_header,
|
|
644
677
|
consolidate_citations,
|
|
645
678
|
include_raw_citations,
|
|
@@ -667,7 +700,7 @@ class GrobidClient(ApiClient):
|
|
|
667
700
|
|
|
668
701
|
# set the GROBID parameters
|
|
669
702
|
the_data = {}
|
|
670
|
-
if
|
|
703
|
+
if generate_ids:
|
|
671
704
|
the_data["generateIDs"] = "1"
|
|
672
705
|
if consolidate_header:
|
|
673
706
|
the_data["consolidateHeader"] = "1"
|
|
@@ -699,7 +732,7 @@ class GrobidClient(ApiClient):
|
|
|
699
732
|
self.process_pdf,
|
|
700
733
|
service,
|
|
701
734
|
pdf_file,
|
|
702
|
-
|
|
735
|
+
generate_ids,
|
|
703
736
|
consolidate_header,
|
|
704
737
|
consolidate_citations,
|
|
705
738
|
include_raw_citations,
|
|
@@ -734,7 +767,7 @@ class GrobidClient(ApiClient):
|
|
|
734
767
|
self,
|
|
735
768
|
service,
|
|
736
769
|
txt_file,
|
|
737
|
-
|
|
770
|
+
generate_ids,
|
|
738
771
|
consolidate_header,
|
|
739
772
|
consolidate_citations,
|
|
740
773
|
include_raw_citations,
|
|
@@ -777,7 +810,7 @@ class GrobidClient(ApiClient):
|
|
|
777
810
|
self.process_txt,
|
|
778
811
|
service,
|
|
779
812
|
txt_file,
|
|
780
|
-
|
|
813
|
+
generate_ids,
|
|
781
814
|
consolidate_header,
|
|
782
815
|
consolidate_citations,
|
|
783
816
|
include_raw_citations,
|
|
@@ -840,7 +873,8 @@ def main():
|
|
|
840
873
|
help="concurrency for service usage"
|
|
841
874
|
)
|
|
842
875
|
parser.add_argument(
|
|
843
|
-
"--generateIDs",
|
|
876
|
+
"--generate_ids", "--generateIDs",
|
|
877
|
+
dest="generate_ids",
|
|
844
878
|
action="store_true",
|
|
845
879
|
help="generate random xml:id to textual XML elements of the result files",
|
|
846
880
|
)
|
|
@@ -870,12 +904,14 @@ def main():
|
|
|
870
904
|
help="force re-processing pdf input files when tei output files already exist",
|
|
871
905
|
)
|
|
872
906
|
parser.add_argument(
|
|
873
|
-
"--teiCoordinates",
|
|
907
|
+
"--tei_coordinates", "--teiCoordinates",
|
|
908
|
+
dest="tei_coordinates",
|
|
874
909
|
action="store_true",
|
|
875
910
|
help="add the original PDF coordinates (bounding boxes) to the extracted elements",
|
|
876
911
|
)
|
|
877
912
|
parser.add_argument(
|
|
878
|
-
"--segmentSentences",
|
|
913
|
+
"--segment_sentences", "--segmentSentences",
|
|
914
|
+
dest="segment_sentences",
|
|
879
915
|
action="store_true",
|
|
880
916
|
help="segment sentences in the text content of the document with additional <s> elements",
|
|
881
917
|
)
|
|
@@ -951,14 +987,14 @@ def main():
|
|
|
951
987
|
exit(1)
|
|
952
988
|
|
|
953
989
|
service = args.service
|
|
954
|
-
|
|
990
|
+
generate_ids = args.generate_ids
|
|
955
991
|
consolidate_header = args.consolidate_header
|
|
956
992
|
consolidate_citations = args.consolidate_citations
|
|
957
993
|
include_raw_citations = args.include_raw_citations
|
|
958
994
|
include_raw_affiliations = args.include_raw_affiliations
|
|
959
995
|
force = args.force
|
|
960
|
-
tei_coordinates = args.
|
|
961
|
-
segment_sentences = args.
|
|
996
|
+
tei_coordinates = args.tei_coordinates
|
|
997
|
+
segment_sentences = args.segment_sentences
|
|
962
998
|
verbose = args.verbose
|
|
963
999
|
|
|
964
1000
|
if service is None or service not in valid_services:
|
|
@@ -973,7 +1009,7 @@ def main():
|
|
|
973
1009
|
input_path,
|
|
974
1010
|
output=output_path,
|
|
975
1011
|
n=n,
|
|
976
|
-
|
|
1012
|
+
generate_ids=generate_ids,
|
|
977
1013
|
consolidate_header=consolidate_header,
|
|
978
1014
|
consolidate_citations=consolidate_citations,
|
|
979
1015
|
include_raw_citations=include_raw_citations,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: grobid-client-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Simple python client for GROBID REST services
|
|
5
5
|
Author-email: Patrice Lopez <patrice.lopez@science-miner.com>
|
|
6
6
|
Maintainer-email: Patrice Lopez <patrice.lopez@science-miner.com>, Luca Foppiano <lucanoro@duck.com>
|
|
@@ -353,13 +353,13 @@ grobid_client [OPTIONS] SERVICE
|
|
|
353
353
|
|
|
354
354
|
| Option | Description |
|
|
355
355
|
|------------------------------|-------------------------------------------|
|
|
356
|
-
| `--
|
|
356
|
+
| `--generate_ids` | Generate random XML IDs |
|
|
357
357
|
| `--consolidate_header` | Consolidate header metadata |
|
|
358
358
|
| `--consolidate_citations` | Consolidate bibliographic references |
|
|
359
359
|
| `--include_raw_citations` | Include raw citation text |
|
|
360
360
|
| `--include_raw_affiliations` | Include raw affiliation text |
|
|
361
|
-
| `--
|
|
362
|
-
| `--
|
|
361
|
+
| `--tei_coordinates` | Add PDF coordinates to XML |
|
|
362
|
+
| `--segment_sentences` | Segment sentences with coordinates |
|
|
363
363
|
| `--flavor` | Processing flavor for fulltext extraction |
|
|
364
364
|
| `--json` | Convert TEI output to JSON format |
|
|
365
365
|
| `--markdown` | Convert TEI output to Markdown format |
|
|
@@ -372,7 +372,7 @@ grobid_client [OPTIONS] SERVICE
|
|
|
372
372
|
grobid_client --input ~/documents --output ~/results processFulltextDocument
|
|
373
373
|
|
|
374
374
|
# High concurrency with coordinates
|
|
375
|
-
grobid_client --input ~/pdfs --output ~/tei --n 20 --
|
|
375
|
+
grobid_client --input ~/pdfs --output ~/tei --n 20 --tei_coordinates processFulltextDocument
|
|
376
376
|
|
|
377
377
|
# Process with JSON output
|
|
378
378
|
grobid_client --input ~/pdfs --output ~/results --json processFulltextDocument
|
|
@@ -384,7 +384,7 @@ grobid_client --input ~/pdfs --output ~/results --markdown processFulltextDocume
|
|
|
384
384
|
grobid_client --server https://grobid.example.com --input ~/citations.txt processCitationList
|
|
385
385
|
|
|
386
386
|
# Force reprocessing with sentence segmentation and JSON output
|
|
387
|
-
grobid_client --input ~/docs --force --
|
|
387
|
+
grobid_client --input ~/docs --force --segment_sentences --json processFulltextDocument
|
|
388
388
|
```
|
|
389
389
|
|
|
390
390
|
### Python Library
|
|
@@ -421,10 +421,10 @@ client.process(
|
|
|
421
421
|
input_path="/path/to/pdfs",
|
|
422
422
|
output_path="/path/to/output",
|
|
423
423
|
n=10,
|
|
424
|
-
|
|
424
|
+
generate_ids=True,
|
|
425
425
|
consolidate_header=True,
|
|
426
|
-
|
|
427
|
-
|
|
426
|
+
tei_coordinates=True,
|
|
427
|
+
segment_sentences=True
|
|
428
428
|
)
|
|
429
429
|
|
|
430
430
|
# Process with JSON output
|
|
@@ -517,6 +517,14 @@ settings.
|
|
|
517
517
|
> Since version 0.0.12, the config file is optional. The client will use default localhost settings if no configuration
|
|
518
518
|
> is provided.
|
|
519
519
|
|
|
520
|
+
> [!WARNING]
|
|
521
|
+
> **Citation consolidation and the `timeout` setting.** When `--consolidate_citations` (or `consolidate_citations=True`)
|
|
522
|
+
> is enabled, GROBID queries external services (e.g. CrossRef) to enrich the extracted references. This is considerably
|
|
523
|
+
> slower than a plain extraction, and a low `timeout` frequently causes `HTTP 408 (Request Timeout)` errors.
|
|
524
|
+
> Set the `timeout` to at least **120 seconds (2-3 minutes recommended)** when consolidating citations. The client emits
|
|
525
|
+
> a warning when consolidation is requested with a timeout below 120 seconds.
|
|
526
|
+
> See [issue #54](https://github.com/grobidOrg/grobid-client-python/issues/54).
|
|
527
|
+
|
|
520
528
|
### Logging Configuration
|
|
521
529
|
|
|
522
530
|
The client provides configurable logging with different verbosity levels. By default, only essential statistics and warnings are shown.
|
|
@@ -673,7 +681,7 @@ When using the `--json` flag, the client converts TEI XML output to a structured
|
|
|
673
681
|
grobid_client --input pdfs/ --output results/ --json processFulltextDocument
|
|
674
682
|
|
|
675
683
|
# JSON output with coordinates and sentence segmentation
|
|
676
|
-
grobid_client --input pdfs/ --output results/ --json --
|
|
684
|
+
grobid_client --input pdfs/ --output results/ --json --tei_coordinates --segment_sentences processFulltextDocument
|
|
677
685
|
```
|
|
678
686
|
|
|
679
687
|
```python
|
|
@@ -754,7 +762,7 @@ Competing interests statement...
|
|
|
754
762
|
grobid_client --input pdfs/ --output results/ --markdown processFulltextDocument
|
|
755
763
|
|
|
756
764
|
# Markdown output with coordinates and sentence segmentation
|
|
757
|
-
grobid_client --input pdfs/ --output results/ --markdown --
|
|
765
|
+
grobid_client --input pdfs/ --output results/ --markdown --tei_coordinates --segment_sentences processFulltextDocument
|
|
758
766
|
```
|
|
759
767
|
|
|
760
768
|
```python
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
grobid_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
grobid_client/client.py,sha256=crvUiVnnkn6tFwO4lKQg2cTxAHZxCBAmeNSVtuL4ZA0,6009
|
|
3
|
-
grobid_client/grobid_client.py,sha256=
|
|
3
|
+
grobid_client/grobid_client.py,sha256=sEBvP-lpL079SWqHLV7wxGt9N4lmdgWr-RzNcz8sDqc,42548
|
|
4
4
|
grobid_client/format/TEI2LossyJSON.py,sha256=1Ew2Y3zbLtWfz2LEyqAVRPu66850Nney9JHjwoTyI3Y,49162
|
|
5
5
|
grobid_client/format/TEI2LossyJSON_cli.py,sha256=6l5nNVc7m03TGI19eIqhN6cxYMH5mZT4K9aK1P0g3So,3796
|
|
6
6
|
grobid_client/format/TEI2Markdown.py,sha256=7HTLuuy8OJFhA58BZ1cxKKF4GGIXIWuxTMRd1tg9PdQ,29505
|
|
@@ -8,8 +8,8 @@ grobid_client/format/TEI2Markdown_cli.py,sha256=wVaMIXfDQUW8Fqu9b5Gj0Q-MbZ2Gv1jC
|
|
|
8
8
|
grobid_client/format/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
grobid_client/format/__main__.py,sha256=jBiiNtyhn7Ys6RC6ynUD4cv1YWXHmpZw4rHmnYfVybI,1804
|
|
10
10
|
grobid_client/format/validate_json_refs.py,sha256=_ieADmrHD77EFwblTNH1_i0x3P7SCmsaTi-PZ6SI79M,14842
|
|
11
|
-
grobid_client_python-0.1.
|
|
12
|
-
grobid_client_python-0.1.
|
|
13
|
-
grobid_client_python-0.1.
|
|
14
|
-
grobid_client_python-0.1.
|
|
15
|
-
grobid_client_python-0.1.
|
|
11
|
+
grobid_client_python-0.1.5.dist-info/METADATA,sha256=Rq2Ac6aIlIW7NACByuIYQW-Ohuz9l555XTBk3eMFxZ0,35066
|
|
12
|
+
grobid_client_python-0.1.5.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
13
|
+
grobid_client_python-0.1.5.dist-info/entry_points.txt,sha256=-WwPi8D8eXEbDB6QvitvHjxSGBeyLCyFvAoZcaDGswQ,67
|
|
14
|
+
grobid_client_python-0.1.5.dist-info/top_level.txt,sha256=HnjgWxdJNKTLIN86XkgRAfVeEK4C71fc9X4fe7qdMvA,14
|
|
15
|
+
grobid_client_python-0.1.5.dist-info/RECORD,,
|
{grobid_client_python-0.1.4.dist-info → grobid_client_python-0.1.5.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|