# If ann data already exists, use it . Otherwise create a new one with new id
prepared_ann_data = []
for k, v in ann_data.items():
try:
ann_datas = list(ann_store.data(set=ann_dataset.id(), key=k, value=v))
prepared_ann_data.append(ann_datas[0])
except: # noqa
prepared_ann_data.append(
{"id": get_uuid(), "set": ann_dataset.id(), "key": k, "value": v}
)
ann_store.annotate(target=text_selector, data=prepared_ann_data, id=get_uuid())
In ann_data, we have annotation data that we want to associate with an annotation. We aim to avoid creating a new annotation data entry with a new ID if it already exists. If annotation data with the same key and value is already present, we want to link it to the incoming annotation instead of duplicating it. The current code works, but I wanted to know if there's a better solution using the STAM API.
Apparently if the key doesnt exists in the annotation data set, it throws an error.