Skip to content

pixano.features.schemas.annotations.info_extraction

Relation(created_at=None, updated_at=None, **data)

Bases: Annotation

Observation of a relation between two annotations, for instance between text-spans in a text.

Attributes:

Name Type Description
predicate str

type of relation, as in semantic-web (OWL, RDF, etc)

subject_ref AnnotationRef

annotation_ref to the subject Annotation (eg TextSpan)

object_ref AnnotationRef

annotation_ref to the object Annotation (eg TextSpan)

Source code in pixano/features/schemas/base_schema.py
def __init__(self, /, created_at: datetime | None = None, updated_at: datetime | None = None, **data: Any):
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.

    Args:
        created_at: The creation date of the object.
        updated_at: The last modification date of the object.
        data: The data of the object validated by Pydantic.
    """
    created_at, updated_at = validate_and_init_create_at_and_update_at(created_at, updated_at)
    data.update({"created_at": created_at, "updated_at": updated_at})
    super().__init__(**data)

none() classmethod

Utility function to get a None equivalent. Should be removed as soon as Lance manages None value.

Returns:

Type Description
Self

"None" Relation.

Source code in pixano/features/schemas/annotations/info_extraction.py
@classmethod
def none(cls) -> Self:
    """Utility function to get a `None` equivalent.
    Should be removed as soon as Lance manages `None` value.

    Returns:
        "None" Relation.
    """
    return cls(
        id="",
        predicate="",
        item_ref=ItemRef.none(),
        view_ref=ViewRef.none(),
        entity_ref=EntityRef.none(),
        subject_ref=AnnotationRef.none(),
        object_ref=AnnotationRef.none(),
    )

TextSpan(created_at=None, updated_at=None, **data)

Bases: Annotation

Designation of a Text-Span in a text, especially in the use-case of Named-Entity Recognition on a textual annotation having a str 'content' attribute .

Attributes:

Name Type Description
mention str

text-span assembled mention.

spans_start list[int]

List of start offsets of the spans in the text.

spans_end list[int]

List of end offsets of the spans in the text.

annotation_ref AnnotationRef

Annotation reference toward an textual Annotation having a str 'content' attribute

Source code in pixano/features/schemas/base_schema.py
def __init__(self, /, created_at: datetime | None = None, updated_at: datetime | None = None, **data: Any):
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.

    Args:
        created_at: The creation date of the object.
        updated_at: The last modification date of the object.
        data: The data of the object validated by Pydantic.
    """
    created_at, updated_at = validate_and_init_create_at_and_update_at(created_at, updated_at)
    data.update({"created_at": created_at, "updated_at": updated_at})
    super().__init__(**data)

spans property

Get the list of zipped spans offsets (starts and ends).

spans_length property

Get the computed list of spans lengths.

none() classmethod

Utility function to get a None equivalent. Should be removed as soon as Lance manages None value.

Returns:

Type Description
Self

"None" TextSpan.

Source code in pixano/features/schemas/annotations/info_extraction.py
@classmethod
def none(cls) -> Self:
    """Utility function to get a `None` equivalent.
    Should be removed as soon as Lance manages `None` value.

    Returns:
        "None" TextSpan.
    """
    return cls(
        id="",
        item_ref=ItemRef.none(),
        view_ref=ViewRef.none(),
        entity_ref=EntityRef.none(),
        mention="",
        spans_start=[],
        spans_end=[],
        annotation_ref=AnnotationRef.none(),
    )

create_relation(predicate, subject_ref=AnnotationRef.none(), object_ref=AnnotationRef.none(), id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a Relation instance.

Parameters:

Name Type Description Default
predicate str

type of relation

required
subject_ref AnnotationRef

annotation_ref to the subject TextSpan

none()
object_ref AnnotationRef

annotation_ref to the object TextSpan

none()
id str

Relation ID.

''
item_ref ItemRef

Item reference.

none()
view_ref ViewRef

View reference.

none()
entity_ref EntityRef

Entity reference.

none()
source_ref SourceRef

Source reference.

none()

Returns:

Type Description
Relation

The created Relation instance.

Source code in pixano/features/schemas/annotations/info_extraction.py
def create_relation(
    predicate: str,
    subject_ref: AnnotationRef = AnnotationRef.none(),
    object_ref: AnnotationRef = AnnotationRef.none(),
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
) -> Relation:
    """Create a `Relation` instance.

    Args:
        predicate: type of relation
        subject_ref: annotation_ref to the subject TextSpan
        object_ref: annotation_ref to the object TextSpan
        id: Relation ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

    Returns:
        The created `Relation` instance.
    """
    return Relation(
        predicate=predicate,
        subject_ref=subject_ref,
        object_ref=object_ref,
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
    )

create_text_span(mention, spans_start, spans_end, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none(), annotation_ref=AnnotationRef.none())

Create a TextSpan instance.

Parameters:

Name Type Description Default
mention str

text-span observed mention.

required
spans_start list[int]

List of start offsets of the spans in the text.

required
spans_end list[int]

List of end offsets of the spans in the text.

required
id str

TextSpan ID.

''
item_ref ItemRef

Item reference.

none()
view_ref ViewRef

View reference.

none()
entity_ref EntityRef

Entity reference.

none()
source_ref SourceRef

Source reference.

none()
annotation_ref AnnotationRef

Annotation reference toward an textual Annotation having a str 'content' attribute

none()

Returns:

Type Description
TextSpan

The created TextSpan instance.

Source code in pixano/features/schemas/annotations/info_extraction.py
def create_text_span(
    mention: str,
    spans_start: list[int],
    spans_end: list[int],
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
    annotation_ref: AnnotationRef = AnnotationRef.none(),
) -> TextSpan:
    """Create a TextSpan instance.

    Args:
        mention: text-span observed mention.
        spans_start: List of start offsets of the spans in the text.
        spans_end: List of end offsets of the spans in the text.
        id: TextSpan ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.
        annotation_ref: Annotation reference toward an textual Annotation having a
          str 'content' attribute

    Returns:
        The created `TextSpan` instance.
    """
    return TextSpan(
        mention=mention,
        spans_start=spans_start,
        spans_end=spans_end,
        annotation_ref=annotation_ref,
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
    )

is_relation(cls, strict=False)

Check if a class is a Relation or subclass of Relation.

Source code in pixano/features/schemas/annotations/info_extraction.py
def is_relation(cls: type, strict: bool = False) -> bool:
    """Check if a class is a `Relation` or subclass of `Relation`."""
    return issubclass_strict(cls, Relation, strict)

is_text_span(cls, strict=False)

Check if a class is a TextSpan or subclass of TextSpan.

Source code in pixano/features/schemas/annotations/info_extraction.py
def is_text_span(cls: type, strict: bool = False) -> bool:
    """Check if a class is a TextSpan or subclass of TextSpan."""
    return issubclass_strict(cls, TextSpan, strict)