grobid-client-python 0.0.16__py3-none-any.whl → 0.0.18__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.
@@ -41,7 +41,7 @@ class GrobidClient(ApiClient):
41
41
  # Default configuration values
42
42
  DEFAULT_CONFIG = {
43
43
  'grobid_server': 'http://localhost:8070',
44
- 'batch_size': 1000,
44
+ 'batch_size': 10,
45
45
  'sleep_time': 5,
46
46
  'timeout': 180,
47
47
  'coordinates': [
@@ -60,7 +60,7 @@ class GrobidClient(ApiClient):
60
60
  ],
61
61
  'logging': {
62
62
  'level': 'INFO',
63
- 'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
63
+ 'format': '%(asctime)s - %(levelname)s - %(message)s',
64
64
  'console': True,
65
65
  'file': None, # Disabled by default
66
66
  'max_file_size': '10MB',
@@ -133,7 +133,7 @@ class GrobidClient(ApiClient):
133
133
  log_level = getattr(logging, log_level_str, logging.INFO)
134
134
 
135
135
  # Parse log format
136
- log_format = log_config.get('format', '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
136
+ log_format = log_config.get('format', '%(asctime)s - %(levelname)s - %(message)s')
137
137
 
138
138
  # Create formatter
139
139
  formatter = logging.Formatter(log_format)
@@ -347,6 +347,7 @@ class GrobidClient(ApiClient):
347
347
 
348
348
  # Counter for actually processed files
349
349
  processed_files_count = 0
350
+ errors_files_count = 0
350
351
  input_files = []
351
352
 
352
353
  for input_file in all_input_files:
@@ -363,7 +364,7 @@ class GrobidClient(ApiClient):
363
364
  input_files.append(input_file)
364
365
 
365
366
  if len(input_files) == batch_size_pdf:
366
- batch_processed = self.process_batch(
367
+ batch_processed, batch_errors = self.process_batch(
367
368
  service,
368
369
  input_files,
369
370
  input_path,
@@ -381,11 +382,12 @@ class GrobidClient(ApiClient):
381
382
  flavor
382
383
  )
383
384
  processed_files_count += batch_processed
385
+ errors_files_count += batch_errors
384
386
  input_files = []
385
387
 
386
388
  # last batch
387
389
  if len(input_files) > 0:
388
- batch_processed = self.process_batch(
390
+ batch_processed, batch_errors = self.process_batch(
389
391
  service,
390
392
  input_files,
391
393
  input_path,
@@ -402,9 +404,11 @@ class GrobidClient(ApiClient):
402
404
  verbose,
403
405
  )
404
406
  processed_files_count += batch_processed
407
+ errors_files_count += batch_errors
405
408
 
406
409
  # Log final statistics
407
410
  self.logger.info(f"Processing completed: {processed_files_count} out of {total_files} files processed")
411
+ self.logger.info(f"Errors: {errors_files_count} out of {total_files} files processed")
408
412
 
409
413
  def process_batch(
410
414
  self,
@@ -428,6 +432,7 @@ class GrobidClient(ApiClient):
428
432
  self.logger.info(f"{len(input_files)} files to process in current batch")
429
433
 
430
434
  processed_count = 0
435
+ error_count = 0
431
436
 
432
437
  # we use ThreadPoolExecutor and not ProcessPoolExecutor because it is an I/O intensive process
433
438
  with concurrent.futures.ThreadPoolExecutor(max_workers=n) as executor:
@@ -468,10 +473,10 @@ class GrobidClient(ApiClient):
468
473
  for r in concurrent.futures.as_completed(results):
469
474
  input_file, status, text = r.result()
470
475
  filename = self._output_file_name(input_file, input_path, output)
471
- processed_count += 1
472
476
 
473
477
  if status != 200 or text is None:
474
478
  self.logger.error(f"Processing of {input_file} failed with error {status}: {text}")
479
+ error_count += 1
475
480
  # writing error file with suffixed error code
476
481
  try:
477
482
  pathlib.Path(os.path.dirname(filename)).mkdir(parents=True, exist_ok=True)
@@ -485,6 +490,7 @@ class GrobidClient(ApiClient):
485
490
  except OSError as e:
486
491
  self.logger.error(f"Failed to write error file {filename}: {str(e)}")
487
492
  else:
493
+ processed_count += 1
488
494
  # writing TEI file
489
495
  try:
490
496
  pathlib.Path(os.path.dirname(filename)).mkdir(parents=True, exist_ok=True)
@@ -494,7 +500,7 @@ class GrobidClient(ApiClient):
494
500
  except OSError as e:
495
501
  self.logger.error(f"Failed to write TEI XML file {filename}: {str(e)}")
496
502
 
497
- return processed_count
503
+ return processed_count, error_count
498
504
 
499
505
  def process_pdf(
500
506
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: grobid-client-python
3
- Version: 0.0.16
3
+ Version: 0.0.18
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>
@@ -254,7 +254,7 @@ A simple, efficient Python client for [GROBID](https://github.com/kermitt2/grobi
254
254
  - Local installation: [GROBID Documentation](http://grobid.readthedocs.io/)
255
255
  - Docker: `docker run -t --rm -p 8070:8070 lfoppiano/grobid:0.8.2`
256
256
  - Default server: `http://localhost:8070`
257
- - Online demo: https://lfoppiano-grobid.hf.space (usage limits apply)
257
+ - Online demo: https://lfoppiano-grobid.hf.space (usage limits apply), more details [here](https://grobid.readthedocs.io/en/latest/getting_started/#using-grobid-from-the-cloud).
258
258
 
259
259
  > [!IMPORTANT]
260
260
  > GROBID supports Windows only through Docker containers. See the [Docker documentation](https://grobid.readthedocs.io/en/latest/Grobid-docker/) for details.
@@ -314,39 +314,39 @@ grobid_client [OPTIONS] SERVICE
314
314
 
315
315
  #### Available Services
316
316
 
317
- | Service | Description | Input Format |
318
- |---------|-------------|--------------|
319
- | `processFulltextDocument` | Extract full document structure | PDF files |
320
- | `processHeaderDocument` | Extract document metadata | PDF files |
321
- | `processReferences` | Extract bibliographic references | PDF files |
322
- | `processCitationList` | Parse citation strings | Text files (one citation per line) |
323
- | `processCitationPatentST36` | Process patent citations | XML ST36 format |
324
- | `processCitationPatentPDF` | Process patent PDFs | PDF files |
317
+ | Service | Description | Input Format |
318
+ |-----------------------------|-----------------------------------|------------------------------------|
319
+ | `processFulltextDocument` | Extract full document structure | PDF files |
320
+ | `processHeaderDocument` | Extract document metadata | PDF files |
321
+ | `processReferences` | Extract bibliographic references | PDF files |
322
+ | `processCitationList` | Parse citation strings | Text files (one citation per line) |
323
+ | `processCitationPatentST36` | Process patent citations | XML ST36 format |
324
+ | `processCitationPatentPDF` | Process patent PDFs | PDF files |
325
325
 
326
326
  #### Common Options
327
327
 
328
- | Option | Description | Default |
329
- |--------|-------------|---------|
330
- | `--input` | Input directory path | Required |
331
- | `--output` | Output directory path | Same as input |
332
- | `--server` | GROBID server URL | `http://localhost:8070` |
333
- | `--n` | Concurrency level | 10 |
334
- | `--config` | Config file path | Optional |
335
- | `--force` | Overwrite existing files | False |
336
- | `--verbose` | Enable verbose logging | False |
328
+ | Option | Description | Default |
329
+ |-------------|--------------------------|-------------------------|
330
+ | `--input` | Input directory path | Required |
331
+ | `--output` | Output directory path | Same as input |
332
+ | `--server` | GROBID server URL | `http://localhost:8070` |
333
+ | `--n` | Concurrency level | 10 |
334
+ | `--config` | Config file path | Optional |
335
+ | `--force` | Overwrite existing files | False |
336
+ | `--verbose` | Enable verbose logging | False |
337
337
 
338
338
  #### Processing Options
339
339
 
340
- | Option | Description |
341
- |--------|-------------|
342
- | `--generateIDs` | Generate random XML IDs |
343
- | `--consolidate_header` | Consolidate header metadata |
344
- | `--consolidate_citations` | Consolidate bibliographic references |
345
- | `--include_raw_citations` | Include raw citation text |
346
- | `--include_raw_affiliations` | Include raw affiliation text |
347
- | `--teiCoordinates` | Add PDF coordinates to XML |
348
- | `--segmentSentences` | Segment sentences with coordinates |
349
- | `--flavor` | Processing flavor for fulltext extraction |
340
+ | Option | Description |
341
+ |------------------------------|-------------------------------------------|
342
+ | `--generateIDs` | Generate random XML IDs |
343
+ | `--consolidate_header` | Consolidate header metadata |
344
+ | `--consolidate_citations` | Consolidate bibliographic references |
345
+ | `--include_raw_citations` | Include raw citation text |
346
+ | `--include_raw_affiliations` | Include raw affiliation text |
347
+ | `--teiCoordinates` | Add PDF coordinates to XML |
348
+ | `--segmentSentences` | Segment sentences with coordinates |
349
+ | `--flavor` | Processing flavor for fulltext extraction |
350
350
 
351
351
  #### Examples
352
352
 
@@ -430,13 +430,13 @@ Configuration can be provided via a JSON file. When using the CLI, the `--server
430
430
 
431
431
  ### Configuration Parameters
432
432
 
433
- | Parameter | Description | Default |
434
- |-----------|-------------|---------|
435
- | `grobid_server` | GROBID server URL | `http://localhost:8070` |
436
- | `batch_size` | Thread pool size | 1000 |
437
- | `sleep_time` | Wait time when server is busy (seconds) | 5 |
438
- | `timeout` | Client-side timeout (seconds) | 60 |
439
- | `coordinates` | XML elements for coordinate extraction | See above |
433
+ | Parameter | Description | Default |
434
+ |-----------------|------------------------------------------------------------------------------------------------------------------|-------------------------|
435
+ | `grobid_server` | GROBID server URL | `http://localhost:8070` |
436
+ | `batch_size` | Thread pool size. **Tune carefully: a large batch size will result in the data being written less frequently** | 1000 |
437
+ | `sleep_time` | Wait time when server is busy (seconds) | 5 |
438
+ | `timeout` | Client-side timeout (seconds) | 180 |
439
+ | `coordinates` | XML elements for coordinate extraction | See above |
440
440
 
441
441
  > [!TIP]
442
442
  > Since version 0.0.12, the config file is optional. The client will use default localhost settings if no configuration is provided.
@@ -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=2oKtZw7UAoCqakHJo9LBMiSkQLTMpEXOfTV8h-rmcPk,31365
4
+ grobid_client_python-0.0.18.dist-info/METADATA,sha256=iJGqV8JOKyM1cbIp6meysadW4aqtoLFIi1cSqyE1H7w,26273
5
+ grobid_client_python-0.0.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ grobid_client_python-0.0.18.dist-info/entry_points.txt,sha256=-WwPi8D8eXEbDB6QvitvHjxSGBeyLCyFvAoZcaDGswQ,67
7
+ grobid_client_python-0.0.18.dist-info/top_level.txt,sha256=HnjgWxdJNKTLIN86XkgRAfVeEK4C71fc9X4fe7qdMvA,14
8
+ grobid_client_python-0.0.18.dist-info/RECORD,,
@@ -1,8 +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=3XlEXrg8v0TWeXWE1jhcYicrLOu5BOWE7l5FBO7YvjE,31063
4
- grobid_client_python-0.0.16.dist-info/METADATA,sha256=H2mnjLSnP8xjj5NN_6iONKghxMmPTfGZ-EKoDKWjNcY,24633
5
- grobid_client_python-0.0.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- grobid_client_python-0.0.16.dist-info/entry_points.txt,sha256=-WwPi8D8eXEbDB6QvitvHjxSGBeyLCyFvAoZcaDGswQ,67
7
- grobid_client_python-0.0.16.dist-info/top_level.txt,sha256=HnjgWxdJNKTLIN86XkgRAfVeEK4C71fc9X4fe7qdMvA,14
8
- grobid_client_python-0.0.16.dist-info/RECORD,,