medkit.core.text.annotation_container#

Classes#

TextAnnotationContainer

Manage a list of text annotations belonging to a text document.

Module Contents#

class medkit.core.text.annotation_container.TextAnnotationContainer(doc_id: str, raw_segment: medkit.core.text.annotation.Segment)#

Bases: medkit.core.annotation_container.AnnotationContainer[medkit.core.text.annotation.TextAnnotation]

Manage a list of text annotations belonging to a text document.

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

Also provides retrieval of entities, segments, relations, and handling of raw segment.

raw_segment#
_segment_ids: list[str] = []#
_entity_ids: list[str] = []#
_relation_ids: list[str] = []#
_relation_ids_by_source_id: dict[str, list[str]]#
property segments: list[medkit.core.text.annotation.Segment]#

Return the list of segments.

property entities: list[medkit.core.text.annotation.Entity]#

Return the list of entities.

property relations: list[medkit.core.text.annotation.Relation]#

Return the list of relations.

add(ann: medkit.core.text.annotation.TextAnnotation)#

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)

get(*, label: str | None = None, key: str | None = None) list[medkit.core.text.annotation.TextAnnotation]#

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_by_id(uid) medkit.core.text.annotation.TextAnnotation#

Return the annotation corresponding to a specific identifier.

Parameters:
uidstr

Identifier of the annotation to return.

get_segments(*, label: str | None = None, key: str | None = None) list[medkit.core.text.annotation.Segment]#

Return a list of the segments of the document (not including entities).

Parameters:
labelstr, optional

Label to use to filter segments.

keystr, optional

Key to use to filter segments.

get_entities(*, label: str | None = None, key: str | None = None) list[medkit.core.text.annotation.Entity]#

Return a list of the entities of the document.

Parameters:
labelstr, optional

Label to use to filter entities.

keystr, optional

Key to use to filter entities.

get_relations(*, label: str | None = None, key: str | None = None, source_id: str | None = None) list[medkit.core.text.annotation.Relation]#

Return a list of the relations of the document.

Parameters:
labelstr, optional

Label to use to filter relations.

keystr, optional

Key to use to filter relations.

source_idstr, optional

Identifier of the source entity to use to filter relations.