monarch-initiative / ontogpt

LLM-based ontological extraction tools, including SPIRES
https://monarch-initiative.github.io/ontogpt/
BSD 3-Clause "New" or "Revised" License
589 stars 74 forks source link

UnboundLocalError: local variable 'normalized_id' referenced before assignment #383

Closed caufieldjh closed 4 months ago

caufieldjh commented 4 months ago

When an extraction encounters an entity it cannot normalize, it isn't normally an issue - it just gets assigned the AUTO prefix or equivalent default. This currently raises an error, though:

INFO:ontogpt.engines.knowledge_engine:Could not ground and normalize N/A to Unit
Traceback (most recent call last):
  File "/home/harry/ontogpt/.venv/bin/ontogpt", line 6, in <module>
    sys.exit(main())
  File "/home/harry/ontogpt/.venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/harry/ontogpt/.venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/harry/ontogpt/.venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/harry/ontogpt/.venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/harry/ontogpt/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/harry/ontogpt/src/ontogpt/cli.py", line 388, in extract
    results = ke.extract_from_text(
  File "/home/harry/ontogpt/src/ontogpt/engines/spires_engine.py", line 97, in extract_from_text
    extracted_object = self.parse_completion_payload(
  File "/home/harry/ontogpt/src/ontogpt/engines/spires_engine.py", line 563, in parse_completion_payload
    return self.ground_annotation_object(raw, cls)
  File "/home/harry/ontogpt/src/ontogpt/engines/spires_engine.py", line 633, in ground_annotation_object
    obj = self.ground_annotation_object(val, rng_cls)
  File "/home/harry/ontogpt/src/ontogpt/engines/spires_engine.py", line 635, in ground_annotation_object
    obj = self.normalize_named_entity(val, slot.range)  # type: ignore
  File "/home/harry/ontogpt/src/ontogpt/engines/knowledge_engine.py", line 350, in normalize_named_entity
    ne = NamedEntity(id=normalized_id, label=text)
UnboundLocalError: local variable 'normalized_id' referenced before assignment
caufieldjh commented 4 months ago

Oops, pushed fix to main (befcafe8655d296f787c7860eb689cecf1b0fbd1)