medkit.core.annotation_container#
Classes#
Manage a list of annotations belonging to a document. |
Module Contents#
- class medkit.core.annotation_container.AnnotationContainer(doc_id: str)#
Bases:
Generic
[medkit.core.annotation.AnnotationType
]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.
- Parameters:
- doc_idstr
The identifier of the document which annotations belong to.
- _store: medkit.core.store.Store#
- _doc_id#
- _ann_ids: list[str] = []#
- _ann_ids_by_label: dict[str, list[str]]#
- _ann_ids_by_key: dict[str, list[str]]#
- add(ann: medkit.core.annotation.AnnotationType)#
Attach an annotation to the document.
- Parameters:
- annAnnotationType
Annotation to add.
- Raises:
- ValueError
If the annotation is already attached to the document (based on annotation.uid)
- __len__() int #
Add support for calling len().
- __iter__() Iterator[medkit.core.annotation.AnnotationType] #
Add support for iterating over each attribute.
- __getitem__(key: int | slice) medkit.core.annotation.AnnotationType | list[medkit.core.annotation.AnnotationType] #
Add support for subscript access.
- get(*, label: str | None = None, key: str | None = None) list[medkit.core.annotation.AnnotationType] #
Return a list of the annotations of the document.
- Parameters:
- labelstr, optional
Label to use to filter annotations.
- keystr, optional
Key to use to filter annotations.
- get_ids(*, label: str | None = None, key: str | None = None) Iterator[str] #
Return an iterator of the identifiers of the annotations of the document.
This method is provided to facilitate additional filtering by subclasses.
- Parameters:
- labelstr, optional
Label to use to filter annotations.
- keystr, optional
Key to use to filter annotations.
- get_by_id(uid: str) medkit.core.annotation.AnnotationType #
Return the annotation corresponding to a specific identifier.
- Parameters:
- uidstr
Identifier of the annotation to return.
- __eq__(other: object) bool #
- __repr__() str #