clamsproject / clams-python

CLAMS SDK for python
http://sdk.clams.ai/
Apache License 2.0
4 stars 1 forks source link

MMIF annotation getter doesn't work on short ids #225

Closed haydenmccormick closed 3 weeks ago

haydenmccormick commented 3 weeks ago

Bug Description

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())
... 
>>> for anno in 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'

>>> for anno in mmif["v_0"].annotations:
...     anno = mmif[anno.long_id]

>>> # Works without error on long IDs

Screenshots

No response

Additional context

No response