medkit.core.text.annotation#

Classes#

TextAnnotation

Base abstract class for all text annotations.

Segment

Text segment referencing part of an TextDocument.

Entity

Text entity referencing part of an TextDocument.

Relation

Relation between two text entities.

Module Contents#

class medkit.core.text.annotation.TextAnnotation(label: str, attrs: list[medkit.core.attribute.Attribute] | None = None, metadata: dict[str, Any] | None = None, uid: str | None = None, attr_container_class: type[medkit.core.attribute_container.AttributeContainer] = AttributeContainer)#

Bases: abc.ABC, medkit.core.dict_conv.SubclassMapping

Base abstract class for all text annotations.

Attributes:
uidstr

Unique identifier of the annotation.

labelstr

The label for this annotation (e.g., SENTENCE)

attrsAttributeContainer

Attributes of the annotation. Stored in a :class:{~medkit.core.AttributeContainer} but can be passed as a list at init.

metadatadict of str to Any

The metadata of the annotation

keysset of str

Pipeline output keys to which the annotation belongs to.

uid: str#
label: str#
attrs: medkit.core.attribute_container.AttributeContainer#
metadata: dict[str, Any]#
keys: set[str]#
classmethod __init_subclass__()#
classmethod from_dict(ann_dict: dict[str, Any]) typing_extensions.Self#
abstract to_dict() dict[str, Any]#
class medkit.core.text.annotation.Segment(label: str, text: str, spans: list[medkit.core.text.span.AnySpan], attrs: list[medkit.core.attribute.Attribute] | None = None, metadata: dict[str, Any] | None = None, uid: str | None = None, store: medkit.core.store.Store | None = None, attr_container_class: type[medkit.core.attribute_container.AttributeContainer] = AttributeContainer)#

Bases: TextAnnotation

Text segment referencing part of an TextDocument.

Attributes:
uidstr

The segment identifier.

labelstr

The label for this segment (e.g., SENTENCE)

textstr

Text of the segment.

spanslist of AnySpan

List of spans indicating which parts of the segment text correspond to which part of the document’s full text.

attrsAttributeContainer

Attributes of the segment. Stored in a :class:{~medkit.core.AttributeContainer} but can be passed as a list at init.

metadatadict of str to Any

The metadata of the segment

keysset of str

Pipeline output keys to which the segment belongs to.

spans: list[medkit.core.text.span.AnySpan]#
text: str#
length#
to_dict() dict[str, Any]#
classmethod from_dict(segment_dict: dict[str, Any]) typing_extensions.Self#

Create a Segment from a dict.

Parameters:
segment_dictdict of str to Any

A dictionary from a serialized segment as generated by to_dict()

class medkit.core.text.annotation.Entity(label: str, text: str, spans: list[medkit.core.text.span.AnySpan], attrs: list[medkit.core.attribute.Attribute] | None = None, metadata: dict[str, Any] | None = None, uid: str | None = None, store: medkit.core.store.Store | None = None, attr_container_class: type[medkit.core.text.entity_attribute_container.EntityAttributeContainer] = EntityAttributeContainer)#

Bases: Segment

Text entity referencing part of an TextDocument.

Attributes:
uidstr

The entity identifier.

labelstr

The label for this entity (e.g., DISEASE)

textstr

Text of the entity.

spanslist of AnySpan

List of spans indicating which parts of the entity text correspond to which part of the document’s full text.

attrsEntityAttributeContainer

Attributes of the entity. Stored in a :class:{~medkit.core.EntityAttributeContainer} but can be passed as a list at init.

metadatadict of str to Any

The metadata of the entity

keysset of str

Pipeline output keys to which the entity belongs to.

attrs: medkit.core.text.entity_attribute_container.EntityAttributeContainer#
class medkit.core.text.annotation.Relation(label: str, source_id: str, target_id: str, attrs: list[medkit.core.attribute.Attribute] | None = None, metadata: dict[str, Any] | None = None, uid: str | None = None, store: medkit.core.store.Store | None = None, attr_container_class: type[medkit.core.attribute_container.AttributeContainer] = AttributeContainer)#

Bases: TextAnnotation

Relation between two text entities.

Attributes:
uidstr

The identifier of the relation

labelstr

The relation label

source_idstr

The identifier of the entity from which the relation is defined

target_idstr

The identifier of the entity to which the relation is defined

attrsAttributeContainer

The attributes of the relation

metadatadict of str to Any

The metadata of the relation

keysset of str

Pipeline output keys to which the relation belongs to

source_id: str#
target_id: str#
to_dict() dict[str, Any]#
classmethod from_dict(relation_dict: dict[str, Any]) typing_extensions.Self#

Create a Relation from a dict.

Parameters:
relation_dictdict of str to Any

A dictionary from a serialized relation as generated by to_dict()