You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MMIF annotation getter doesn't work on short ids #279
When using the native MMIF annotation getter mmif[anno.id], the SDK throws a KeyError. When using view-scoped long ids (mmif[anno.long_id]), it works as expected.
Reproduction steps
Using a MMIF file (version 1.0.4), try to access a given annotation via mmif[id], where id is a short annotation ID.
Expected behavior
>>> for anno in mmif["v_0"].annotations:
... anno = mmif[anno.id]
Should successfully access a MMIF Annotation object in each iteration
Log output
>>> with open("spacy1.mmif", "r") as f:
... mmif = Mmif(f.read())
...
>>> forannoin mmif["v_0"].annotations:
... anno = mmif[anno.id]
...
Traceback (most recent call last):
File "<stdin>", line 2, in<module>
File "/home/hmccormick/.local/lib/python3.9/site-packages/mmif/serialize/mmif.py", line 590, in __getitem__
raise KeyError("ID not found: %s" % item)
KeyError: 'ID not found: to_1'
>>> forannoin mmif["v_0"].annotations:
... anno = mmif[anno.long_id]
>>> # Works without error on long IDs
raiseKeyError("Tried to subscript into a view that doesn't exist")
ifview_resultanddocument_result:
raiseKeyError("Ambiguous ID search result")
ifnot (view_resultordocument_result):
raiseKeyError("ID not found: %s"%item)
considering
it says it expects a view-scoped annotation ID (short ID)
it raises error when two objects with the same ID (when a document and a view have the same id, line 588)
annotation IDs are only scoped within a view, so it's much more likely to have ID conflict by querying annotation ID only.
I think an error when querying with a short ID is somewhat expected behavior. Easy workaround this limitation in the downstream is probably just using anno.long_id instead of anno.id.
Activity
keighrim commentedon Jun 6, 2024
Not sure this is actually a bug. Although the documentation isn't super clear,
mmif-python/mmif/serialize/mmif.py
Lines 564 to 590 in 2a5bffc
considering
I think an error when querying with a short ID is somewhat expected behavior. Easy workaround this limitation in the downstream is probably just using
anno.long_idinstead ofanno.id.mmif-python/mmif/serialize/annotation.py
Lines 131 to 135 in 693972a