medkit.core.annotation_container#

Classes:

AnnotationContainer(doc_id)

Manage a list of annotations belonging to a document.

class AnnotationContainer(doc_id)[source]#

Manage a list of annotations belonging to a document.

This behaves more or less like a list: calling len() and iterating are supported. Additional filtering is available through the get() method.

The annotations will be stored in a Store, which can rely on a simple dict or something more complicated like a database.

This global store may be initialized using :class:~medkit.core.GlobalStore. Otherwise, a default one (i.e. dict store) is used.

Instantiate the annotation container

Parameters

doc_id (str) – The identifier of the document which annotations belong to.

Methods:

add(ann)

Attach an annotation to the document.

get(*[, label, key])

Return a list of the annotations of the document, optionally filtering by label or key.

get_by_id(uid)

Return the annotation corresponding to a specific identifier.

get_ids(*[, label, key])

Return an iterator of the identifiers of the annotations of the document, optionally filtering by label or key.

add(ann)[source]#

Attach an annotation to the document.

Parameters

ann (~AnnotationType) – Annotation to add.

Raises

ValueError – If the annotation is already attached to the document (based on annotation.uid)

get(*, label=None, key=None)[source]#

Return a list of the annotations of the document, optionally filtering by label or key.

Parameters
  • label (Optional[str]) – Label to use to filter annotations.

  • key (Optional[str]) – Key to use to filter annotations.

Return type

List[~AnnotationType]

get_ids(*, label=None, key=None)[source]#

Return an iterator of the identifiers of the annotations of the document, optionally filtering by label or key.

This method is provided, so it is easier to implement additional filtering in subclasses.

Parameters
  • label (Optional[str]) – Label to use to filter annotations.

  • key (Optional[str]) – Key to use to filter annotations.

Return type

Iterator[str]

get_by_id(uid)[source]#

Return the annotation corresponding to a specific identifier.

Parameters

uid (str) – Identifier of the annotation to return.

Return type

~AnnotationType