Skip to content

Question: How can we efficiently retrieve existing annotation data by searching based on key and value? #32

@tenzin3

Description

@tenzin3
# 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.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions