grobid-client-python 0.0.6__tar.gz → 0.0.7__tar.gz
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_python-0.0.7/MANIFEST.in +1 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/PKG-INFO +1 -1
- grobid_client_python-0.0.7/Readme.md +184 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client_python.egg-info/PKG-INFO +1 -1
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client_python.egg-info/SOURCES.txt +2 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/setup.py +1 -1
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/LICENSE +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client/__init__.py +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client/client.py +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client/grobid_client.py +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client_python.egg-info/dependency_links.txt +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client_python.egg-info/entry_points.txt +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client_python.egg-info/requires.txt +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client_python.egg-info/top_level.txt +0 -0
- {grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include Readme.md
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
[](https://badge.fury.io/py/grobid_client_python)
|
|
2
|
+
[](https://archive.softwareheritage.org/browse/origin/https://github.com/kermitt2/grobid_client_python/)
|
|
3
|
+
[](http://www.apache.org/licenses/LICENSE-2.0.html)
|
|
4
|
+
|
|
5
|
+
# Simple python client for GROBID REST services
|
|
6
|
+
|
|
7
|
+
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).
|
|
8
|
+
|
|
9
|
+
## Before you start
|
|
10
|
+
|
|
11
|
+
Please be aware that, at the moment, [grobid does not support Windows](https://grobid.readthedocs.io/en/latest/Troubleshooting/#windows-related-issues).
|
|
12
|
+
If you are a Windows user, don't worry. You can still [run grobid
|
|
13
|
+
via Docker](https://grobid.readthedocs.io/en/latest/Grobid-docker/).
|
|
14
|
+
|
|
15
|
+
## Build and run
|
|
16
|
+
|
|
17
|
+
You need first a running *grobid* service, latest stable version, see the [documentation](http://grobid.readthedocs.io/) for installation.
|
|
18
|
+
By default, it is assumed that the server will run on the address `http://localhost:8070`.
|
|
19
|
+
You can change the server address by editing the file `config.json`, see below.
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
This client has been developed and was tested with Python `3.5`-`3.8` and should work with any higher `3.*` versions. It does not require any dependencies beyond the standard Python ones.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
Get the github repo:
|
|
28
|
+
|
|
29
|
+
```console
|
|
30
|
+
git clone https://github.com/kermitt2/grobid_client_python
|
|
31
|
+
cd grobid_client_python
|
|
32
|
+
python3 setup.py install
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
There is nothing more needed to start using the python command lines, see the next section.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Usage and options
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
usage: grobid_client [-h] [--input INPUT] [--output OUTPUT] [--config CONFIG]
|
|
42
|
+
[--n N] [--generateIDs] [--consolidate_header]
|
|
43
|
+
[--consolidate_citations] [--include_raw_citations]
|
|
44
|
+
[--include_raw_affiliations] [--force] [--teiCoordinates]
|
|
45
|
+
[--verbose]
|
|
46
|
+
service
|
|
47
|
+
|
|
48
|
+
Client for GROBID services
|
|
49
|
+
|
|
50
|
+
positional arguments:
|
|
51
|
+
service one of ['processFulltextDocument',
|
|
52
|
+
'processHeaderDocument', 'processReferences',
|
|
53
|
+
'processCitationList']
|
|
54
|
+
|
|
55
|
+
optional arguments:
|
|
56
|
+
-h, --help show this help message and exit
|
|
57
|
+
--input INPUT path to the directory containing PDF files or .txt
|
|
58
|
+
(for processCitationList only, one reference per line)
|
|
59
|
+
to process
|
|
60
|
+
--output OUTPUT path to the directory where to put the results
|
|
61
|
+
(optional)
|
|
62
|
+
--config CONFIG path to the config file, default is ./config.json
|
|
63
|
+
--n N concurrency for service usage
|
|
64
|
+
--generateIDs generate random xml:id to textual XML elements of the
|
|
65
|
+
result files
|
|
66
|
+
--consolidate_header call GROBID with consolidation of the metadata
|
|
67
|
+
extracted from the header
|
|
68
|
+
--consolidate_citations
|
|
69
|
+
call GROBID with consolidation of the extracted
|
|
70
|
+
bibliographical references
|
|
71
|
+
--include_raw_citations
|
|
72
|
+
call GROBID requesting the extraction of raw citations
|
|
73
|
+
--include_raw_affiliations
|
|
74
|
+
call GROBID requestiong the extraciton of raw
|
|
75
|
+
affiliations
|
|
76
|
+
--force force re-processing pdf input files when tei output
|
|
77
|
+
files already exist
|
|
78
|
+
--teiCoordinates add the original PDF coordinates (bounding boxes) to
|
|
79
|
+
the extracted elements
|
|
80
|
+
--segmentSentences segment sentences in the text content of the document
|
|
81
|
+
with additional <s> elements
|
|
82
|
+
--verbose print information about processed files in the console
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Examples:
|
|
88
|
+
|
|
89
|
+
```console
|
|
90
|
+
> grobid_client --input ~/tmp/in2 --output ~/tmp/out processFulltextDocument
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
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.
|
|
94
|
+
|
|
95
|
+
If `--output` is omitted, the resulting XML TEI documents will be produced alongside the PDF in the `--input` directory.
|
|
96
|
+
|
|
97
|
+
```console
|
|
98
|
+
> grobid_client --input ~/tmp/in2 --output ~/tmp/out --n 20 processHeaderDocument
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
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.
|
|
102
|
+
|
|
103
|
+
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`.
|
|
104
|
+
|
|
105
|
+
`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:
|
|
106
|
+
|
|
107
|
+
```console
|
|
108
|
+
> grobid_client --input resources/test_txt/ --output resources/test_out/ --n 20 processCitationList
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
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.
|
|
112
|
+
|
|
113
|
+
```console
|
|
114
|
+
> grobid_client --input ~/tmp/in2 --output ~/tmp/out --teiCoordinates --segmentSentences processFulltextDocument
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The file `example.py` gives an example of usage as a library, from a another python script.
|
|
118
|
+
|
|
119
|
+
## Using the client in your python
|
|
120
|
+
|
|
121
|
+
Import and call the client as follow:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from grobid_client.grobid_client import GrobidClient
|
|
125
|
+
|
|
126
|
+
client = GrobidClient(config_path="./config.json")
|
|
127
|
+
client.process("processFulltextDocument", "/mnt/data/covid/pdfs", n=20)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
See also `example.py`.
|
|
131
|
+
|
|
132
|
+
## Configuration of the client
|
|
133
|
+
|
|
134
|
+
There are a few parameters that can be set with the `config.json` file.
|
|
135
|
+
|
|
136
|
+
- `grobid_server` indicates the URL of the GROBID server to be used by the client.
|
|
137
|
+
|
|
138
|
+
- `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.
|
|
139
|
+
|
|
140
|
+
- `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.
|
|
141
|
+
|
|
142
|
+
- `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.
|
|
143
|
+
|
|
144
|
+
- `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.
|
|
145
|
+
|
|
146
|
+
Here is the default `config.json` file for the client:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
{
|
|
150
|
+
"grobid_server": "http://localhost:8070",
|
|
151
|
+
"batch_size": 1000,
|
|
152
|
+
"sleep_time": 5,
|
|
153
|
+
"timeout": 60,
|
|
154
|
+
"coordinates": [ "persName", "figure", "ref", "biblStruct", "formula", "s" ]
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Benchmarking
|
|
159
|
+
|
|
160
|
+
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:
|
|
161
|
+
|
|
162
|
+
| n | runtime (s)| s/PDF | PDF/s |
|
|
163
|
+
|----|------------|-------|-------|
|
|
164
|
+
| 1 | 209.0 | 1.54 | 0.65 |
|
|
165
|
+
| 2 | 112.0 | 0.82 | 1.21 |
|
|
166
|
+
| 3 | 80.4 | 0.59 | 1.69 |
|
|
167
|
+
| 5 | 62.9 | 0.46 | 2.16 |
|
|
168
|
+
| 8 | 55.7 | 0.41 | 2.44 |
|
|
169
|
+
| 10 | 55.3 | 0.40 | 2.45 |
|
|
170
|
+
|
|
171
|
+

|
|
172
|
+
|
|
173
|
+
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.
|
|
174
|
+
|
|
175
|
+
In similar conditions, extraction and structuring of bibliographical references takes 26.9 s (5.1 PDF/s).
|
|
176
|
+
|
|
177
|
+
Processing of 3500 raw bibliographical take 4.3 s with `n=10` (814 references parsed per second).
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## License and contact
|
|
181
|
+
|
|
182
|
+
Distributed under [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0).
|
|
183
|
+
|
|
184
|
+
Main author and contact: Patrice Lopez (<patrice.lopez@science-miner.com>)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from setuptools import setup, find_packages
|
|
4
4
|
|
|
5
5
|
setup(name='grobid_client_python',
|
|
6
|
-
version='0.0.
|
|
6
|
+
version='0.0.7',
|
|
7
7
|
description='Simple python client for GROBID REST services',
|
|
8
8
|
author='kermitt2',
|
|
9
9
|
long_description=open("Readme.md", encoding='utf-8').read(),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{grobid_client_python-0.0.6 → grobid_client_python-0.0.7}/grobid_client_python.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|