Skip to content

Commit

Permalink
fix: gracefully handle missing OntoGPT output files
Browse files Browse the repository at this point in the history
Implement error handling to gracefully handle cases where the OntoGPT
process fails to produce an output file. This prevents downstream
processing errors.
  • Loading branch information
clnsmth authored Nov 8, 2024
1 parent 591ed67 commit 3636672
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/spinneret/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,12 @@ def get_ontogpt_annotation(
return None

# Parse the results
with open(output_file, "r", encoding="utf-8") as f:
r = load(f)
try: # Occasionally, no file is returned. This is a bug in OntoGPT.
with open(output_file, "r", encoding="utf-8") as f:
r = load(f)
except FileNotFoundError as e:
print(f"Error reading OntoGPT output file: {e}")
return None
named_entities = r.get("named_entities")
if named_entities is None: # OntoGPT couldn't find any annotations
return None
Expand Down

0 comments on commit 3636672

Please sign in to comment.