medkit.core.text.annotation_container
medkit.core.text.annotation_container#
Classes:
|
Manage a list of text annotations belonging to a text document. |
- class TextAnnotationContainer(doc_id, raw_segment)[source]#
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.
Instantiate the annotation container
- Parameters
doc_id (
str
) – The identifier of the document which annotations belong to.
Attributes:
Return the list of entities
Return the list of relations
Return the list of segments
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_entities
(*[, label, key])Return a list of the entities of the document, optionally filtering by label or key.
get_ids
(*[, label, key])Return an iterator of the identifiers of the annotations of the document, optionally filtering by label or key.
get_relations
(*[, label, key, source_id])Return a list of the relations of the document, optionally filtering by label, key or source entity.
get_segments
(*[, label, key])Return a list of the segments of the document (not including entities), optionally filtering by label or key.
- property segments: List[medkit.core.text.annotation.Segment]#
Return the list of segments
- Return type
List
[Segment
]
- property entities: List[medkit.core.text.annotation.Entity]#
Return the list of entities
- Return type
List
[Entity
]
- property relations: List[medkit.core.text.annotation.Relation]#
Return the list of relations
- Return type
List
[Relation
]
- add(ann)[source]#
Attach an annotation to the document.
- Parameters
ann (
TextAnnotation
) – 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
[TextAnnotation
]
- get_by_id(uid)[source]#
Return the annotation corresponding to a specific identifier.
- Parameters
uid – Identifier of the annotation to return.
- Return type
- get_segments(*, label=None, key=None)[source]#
Return a list of the segments of the document (not including entities), optionally filtering by label or key.
- Parameters
label (
Optional
[str
]) – Label to use to filter segments.key (
Optional
[str
]) – Key to use to filter segments.
- Return type
List
[Segment
]
- get_entities(*, label=None, key=None)[source]#
Return a list of the entities of the document, optionally filtering by label or key.
- Parameters
label (
Optional
[str
]) – Label to use to filter entities.key (
Optional
[str
]) – Key to use to filter entities.
- Return type
List
[Entity
]
- get_relations(*, label=None, key=None, source_id=None)[source]#
Return a list of the relations of the document, optionally filtering by label, key or source entity.
- Parameters
label (
Optional
[str
]) – Label to use to filter relations.key (
Optional
[str
]) – Key to use to filter relations.source_id (
Optional
[str
]) – Identifier of the source entity to use to filter relations.
- Return type
List
[Relation
]
- get_ids(*, label=None, key=None)#
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
]