Skip to content

Commit 93d7367

Browse files
committed
if JSON output does not exist, create it even if the TEI was not produced because already existing
1 parent 9c1b2ee commit 93d7367

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

grobid_client/grobid_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,25 @@ def process_batch(
450450
if not force and os.path.isfile(filename):
451451
self.logger.info(
452452
f"{filename} already exists, skipping... (use --force to reprocess pdf input files)")
453+
454+
# Check if JSON output is needed but JSON file doesn't exist
455+
if json_output:
456+
json_filename = filename.replace('.grobid.tei.xml', '.json')
457+
if not os.path.isfile(json_filename):
458+
self.logger.info(f"JSON file {json_filename} does not exist, generating JSON from existing TEI...")
459+
try:
460+
converter = TEI2LossyJSONConverter()
461+
json_data = converter.convert_tei_file(filename, stream=False)
462+
463+
if json_data:
464+
with open(json_filename, 'w', encoding='utf8') as json_file:
465+
json.dump(json_data, json_file, indent=2, ensure_ascii=False)
466+
self.logger.debug(f"Successfully created JSON file: {json_filename}")
467+
else:
468+
self.logger.warning(f"Failed to convert TEI to JSON for {filename}")
469+
except Exception as e:
470+
self.logger.error(f"Failed to convert TEI to JSON for {filename}: {str(e)}")
471+
453472
continue
454473

455474
selected_process = self.process_pdf

0 commit comments

Comments
 (0)