Skip to main content

get_data_items

FunctionSource

items: [AnnoItem] = get_data_items(
data: Annotations | [AnnoItem],
comment: str | None = None,
n: int | None = None,
)

Get one or several annotation items by exactly matching the comment.

Note that this method will not validate the format of each returned annotation items. Not well-formatted items will STILL be returned.

Aliases

This function can be acquired by

import dash_picture_annotation as dpa


dpa.get_data_items
dpa.utilities.get_data_items

Arguments

Requires

ArgumentTypeRequired
Description
dataAnnotations | [AnnoItem]The annotation data that is queried.
commentstr | None

The comment of the annoatations to be selected. This value will be exactly matched in the data, which means that it is space- and case-sensitive.

If using None, will return the annotations without comments.

nint | None

Limit the maximal number of the items to be found. If not provided, will try to return all annotation items with a specified comment.

Specifying a non-positive value will cause this number to be ignored.

Returns

ArgumentType
Description
items[AnnoItem]The located annotation items. Modifying the content of these items will cause the data to be modified.

Examples

Get an annotation item by quering the comment

get_anno_items_by_comment.py
import pprint
import dash_picture_annotation as dpa


mark = lambda pos: {"x": pos, "y": pos, "width": 0, "height": 0, "type": "RECT"}

data = [
{"id": "a", "mark": mark(0)},
{"id": "b", "mark": mark(1)},
{"id": "c", "mark": mark(2), "comment": "type-1"},
{"id": "d", "mark": mark(3), "comment": "type-2"},
{"id": "d", "mark": mark(4), "comment": "type-2"},
]

data_wrapped = {"timestamp": 0, "data": data}

pprint.pprint(dpa.get_data_items(data))
pprint.pprint(dpa.get_data_items(data_wrapped))
pprint.pprint(dpa.get_data_items(data, "type-1"))
pprint.pprint(dpa.get_data_items(data_wrapped, "type-1"))
pprint.pprint(dpa.get_data_items(data, "type-2"))
pprint.pprint(dpa.get_data_items(data_wrapped, "type-2"))
pprint.pprint(dpa.get_data_items(data, "type-2", 1))
pprint.pprint(dpa.get_data_items(data_wrapped, "type-2", 1))
try:
pprint.pprint(dpa.get_data_item(data, "type-3"))
except KeyError as e:
print(e)