Skip to content

pixano.features.schemas.annotations.info_extraction

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

Bases: Annotation

Observation of a named-entity in a text.

Attributes:

Name Type Description
concept_id str

Id of the named-entity type.

mention str

Named-entity observed 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.

Raises 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.

Parameters:

Name Type Description Default
created_at datetime | None

The creation date of the object.

None
updated_at datetime | None

The last modification date of the object.

None
data Any

The data of the object validated by Pydantic.

{}
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: list[tuple[int, int]] property

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

spans_length: list[int] 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" NamedEntity.

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" NamedEntity.
    """
    return cls(
        id="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        concept_id="",
        mention="",
        spans_start=[],
        spans_end=[],
    )

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

Bases: Annotation

Observation of a relation between two named entity in a text.

Attributes:

Name Type Description
predicate_id str

id of relation type.

subject_id AnnotationRef

annotation_id of the subject named-entity

object_id AnnotationRef

annotation_id of the object named-entity

Raises 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.

Parameters:

Name Type Description Default
created_at datetime | None

The creation date of the object.

None
updated_at datetime | None

The last modification date of the object.

None
data Any

The data of the object validated by Pydantic.

{}
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="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        predicate_id="",
        subject_id=AnnotationRef.none(),
        object_id=AnnotationRef.none(),
    )

create_named_entity(concept_id, mention, spans_start, spans_end, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a NamedEntity instance.

Parameters:

Name Type Description Default
concept_id str

Id of named-entity type.

required
mention str

Named-entity 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

NamedEntity 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
NamedEntity

The created NamedEntity instance.

Source code in pixano/features/schemas/annotations/info_extraction.py
def create_named_entity(
    concept_id: str,
    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(),
) -> NamedEntity:
    """Create a `NamedEntity` instance.

    Args:
        concept_id: Id of named-entity type.
        mention: Named-entity 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: `NamedEntity` ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

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

create_relation(predicate_id, subject_id=AnnotationRef.none(), object_id=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_id str

Id of relation type.

required
subject_id AnnotationRef

Annotation_id of the subject named-entity

none()
object_id AnnotationRef

Annotation_id of the object named-entity

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_id: str,
    subject_id: AnnotationRef = AnnotationRef.none(),
    object_id: 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_id: Id of relation type.
        subject_id: Annotation_id of the subject named-entity
        object_id: Annotation_id of the object named-entity
        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_id=predicate_id,
        subject_id=subject_id,
        object_id=object_id,
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
    )

is_named_entity(cls, strict=False)

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

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

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)