Skip to content

Models

aana.storage.models

BaseEntity

Bases: DeclarativeBase, InheritanceReuseMixin

Base for all ORM classes.

from_parent

from_parent(parent_instance, **kwargs)

Create a new instance of the child class, reusing attributes from the parent instance.

PARAMETER DESCRIPTION
parent_instance

An instance of the parent class

TYPE: Any

kwargs

Additional keyword arguments to set on the new instance

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
T

A new instance of the child class

TYPE: T

Source code in aana/storage/models/base.py
@classmethod
def from_parent(cls: type[T], parent_instance: Any, **kwargs: Any) -> T:
    """Create a new instance of the child class, reusing attributes from the parent instance.

    Args:
        parent_instance (Any): An instance of the parent class
        kwargs (Any): Additional keyword arguments to set on the new instance

    Returns:
        T: A new instance of the child class
    """
    # Get the mapped attributes of the parent class
    mapper = object_mapper(parent_instance)
    attributes = {
        prop.key: getattr(parent_instance, prop.key)
        for prop in mapper.iterate_properties
        if hasattr(parent_instance, prop.key)
        and prop.key
        != mapper.polymorphic_on.name  # don't copy the polymorphic_on attribute from the parent
    }

    # Update attributes with any additional kwargs
    attributes.update(kwargs)

    # Create and return a new instance of the child class
    return cls(**attributes)

CaptionEntity

Bases: BaseEntity, TimeStampEntity

ORM model for video captions.

ATTRIBUTE DESCRIPTION
id

Unique identifier for the caption.

TYPE: int

model

Name of the model used to generate the caption.

TYPE: str

frame_id

The 0-based frame id of video for caption.

TYPE: int

caption

Frame caption.

TYPE: str

timestamp

Frame timestamp in seconds.

TYPE: float

caption_type

The type of caption (populated automatically by ORM based on polymorphic_identity of subclass).

TYPE: str

from_parent

from_parent(parent_instance, **kwargs)

Create a new instance of the child class, reusing attributes from the parent instance.

PARAMETER DESCRIPTION
parent_instance

An instance of the parent class

TYPE: Any

kwargs

Additional keyword arguments to set on the new instance

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
T

A new instance of the child class

TYPE: T

Source code in aana/storage/models/base.py
@classmethod
def from_parent(cls: type[T], parent_instance: Any, **kwargs: Any) -> T:
    """Create a new instance of the child class, reusing attributes from the parent instance.

    Args:
        parent_instance (Any): An instance of the parent class
        kwargs (Any): Additional keyword arguments to set on the new instance

    Returns:
        T: A new instance of the child class
    """
    # Get the mapped attributes of the parent class
    mapper = object_mapper(parent_instance)
    attributes = {
        prop.key: getattr(parent_instance, prop.key)
        for prop in mapper.iterate_properties
        if hasattr(parent_instance, prop.key)
        and prop.key
        != mapper.polymorphic_on.name  # don't copy the polymorphic_on attribute from the parent
    }

    # Update attributes with any additional kwargs
    attributes.update(kwargs)

    # Create and return a new instance of the child class
    return cls(**attributes)

from_caption_output

from_caption_output(model_name, caption, frame_id, timestamp)

Converts a Caption pydantic model to a CaptionEntity.

PARAMETER DESCRIPTION
model_name

Name of the model used to generate the caption.

TYPE: str

caption

Caption pydantic model.

TYPE: Caption

frame_id

The 0-based frame id of video for caption.

TYPE: int

timestamp

Frame timestamp in seconds.

TYPE: float

RETURNS DESCRIPTION
CaptionEntity

ORM model for video captions.

TYPE: CaptionEntity

Source code in aana/storage/models/caption.py
@classmethod
def from_caption_output(
    cls,
    model_name: str,
    caption: Caption,
    frame_id: int,
    timestamp: float,
) -> CaptionEntity:
    """Converts a Caption pydantic model to a CaptionEntity.

    Args:
        model_name (str): Name of the model used to generate the caption.
        caption (Caption): Caption pydantic model.
        frame_id (int): The 0-based frame id of video for caption.
        timestamp (float): Frame timestamp in seconds.

    Returns:
        CaptionEntity: ORM model for video captions.
    """
    return CaptionEntity(
        model=model_name,
        frame_id=frame_id,
        caption=str(caption),
        timestamp=timestamp,
    )

MediaEntity

Bases: BaseEntity, TimeStampEntity

Base ORM class for media (e.g. videos, images, etc.).

This class is meant to be subclassed by other media types.

ATTRIBUTE DESCRIPTION
id

Unique identifier for the media.

TYPE: MediaId

media_type

The type of media (populated automatically by ORM based on polymorphic_identity of subclass).

TYPE: str

from_parent

from_parent(parent_instance, **kwargs)

Create a new instance of the child class, reusing attributes from the parent instance.

PARAMETER DESCRIPTION
parent_instance

An instance of the parent class

TYPE: Any

kwargs

Additional keyword arguments to set on the new instance

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
T

A new instance of the child class

TYPE: T

Source code in aana/storage/models/base.py
@classmethod
def from_parent(cls: type[T], parent_instance: Any, **kwargs: Any) -> T:
    """Create a new instance of the child class, reusing attributes from the parent instance.

    Args:
        parent_instance (Any): An instance of the parent class
        kwargs (Any): Additional keyword arguments to set on the new instance

    Returns:
        T: A new instance of the child class
    """
    # Get the mapped attributes of the parent class
    mapper = object_mapper(parent_instance)
    attributes = {
        prop.key: getattr(parent_instance, prop.key)
        for prop in mapper.iterate_properties
        if hasattr(parent_instance, prop.key)
        and prop.key
        != mapper.polymorphic_on.name  # don't copy the polymorphic_on attribute from the parent
    }

    # Update attributes with any additional kwargs
    attributes.update(kwargs)

    # Create and return a new instance of the child class
    return cls(**attributes)

TranscriptEntity

Bases: BaseEntity, TimeStampEntity

ORM class for media transcripts generated by a model.

ATTRIBUTE DESCRIPTION
id

Unique identifier for the transcript.

TYPE: int

model

Name of the model used to generate the transcript.

TYPE: str

transcript

Full text transcript of the media.

TYPE: str

segments

Segments of the transcript.

TYPE: dict

language

Language of the transcript as predicted by the model.

TYPE: str

language_confidence

Confidence score of language prediction.

TYPE: float

transcript_type

The type of transcript (populated automatically by ORM based on polymorphic_identity of subclass).

TYPE: str

from_parent

from_parent(parent_instance, **kwargs)

Create a new instance of the child class, reusing attributes from the parent instance.

PARAMETER DESCRIPTION
parent_instance

An instance of the parent class

TYPE: Any

kwargs

Additional keyword arguments to set on the new instance

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
T

A new instance of the child class

TYPE: T

Source code in aana/storage/models/base.py
@classmethod
def from_parent(cls: type[T], parent_instance: Any, **kwargs: Any) -> T:
    """Create a new instance of the child class, reusing attributes from the parent instance.

    Args:
        parent_instance (Any): An instance of the parent class
        kwargs (Any): Additional keyword arguments to set on the new instance

    Returns:
        T: A new instance of the child class
    """
    # Get the mapped attributes of the parent class
    mapper = object_mapper(parent_instance)
    attributes = {
        prop.key: getattr(parent_instance, prop.key)
        for prop in mapper.iterate_properties
        if hasattr(parent_instance, prop.key)
        and prop.key
        != mapper.polymorphic_on.name  # don't copy the polymorphic_on attribute from the parent
    }

    # Update attributes with any additional kwargs
    attributes.update(kwargs)

    # Create and return a new instance of the child class
    return cls(**attributes)

from_asr_output

from_asr_output(model_name, info, transcription, segments)

Converts an AsrTranscriptionInfo and AsrTranscription to a single Transcript entity.

PARAMETER DESCRIPTION
model_name

Name of the model used to generate the transcript.

TYPE: str

info

Information about the transcription.

TYPE: AsrTranscriptionInfo

transcription

The full transcription.

TYPE: AsrTranscription

segments

Segments of the transcription.

TYPE: AsrSegments

RETURNS DESCRIPTION
TranscriptEntity

A new instance of the TranscriptEntity class.

TYPE: TranscriptEntity

Source code in aana/storage/models/transcript.py
@classmethod
def from_asr_output(
    cls,
    model_name: str,
    info: AsrTranscriptionInfo,
    transcription: AsrTranscription,
    segments: AsrSegments,
) -> TranscriptEntity:
    """Converts an AsrTranscriptionInfo and AsrTranscription to a single Transcript entity.

    Args:
        model_name (str): Name of the model used to generate the transcript.
        info (AsrTranscriptionInfo): Information about the transcription.
        transcription (AsrTranscription): The full transcription.
        segments (AsrSegments): Segments of the transcription.

    Returns:
        TranscriptEntity: A new instance of the TranscriptEntity class.
    """
    return TranscriptEntity(
        model=model_name,
        language=info.language,
        language_confidence=info.language_confidence,
        transcript=transcription.text,
        segments=[s.model_dump() for s in segments],
    )

VideoEntity

Bases: MediaEntity

Base ORM class for videos.

ATTRIBUTE DESCRIPTION
id

Unique identifier for the video.

TYPE: MediaId

path

Path to the video file.

TYPE: str

url

URL to the video file.

TYPE: str

title

Title of the video.

TYPE: str

description

Description of the video.

TYPE: str

from_parent

from_parent(parent_instance, **kwargs)

Create a new instance of the child class, reusing attributes from the parent instance.

PARAMETER DESCRIPTION
parent_instance

An instance of the parent class

TYPE: Any

kwargs

Additional keyword arguments to set on the new instance

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
T

A new instance of the child class

TYPE: T

Source code in aana/storage/models/base.py
@classmethod
def from_parent(cls: type[T], parent_instance: Any, **kwargs: Any) -> T:
    """Create a new instance of the child class, reusing attributes from the parent instance.

    Args:
        parent_instance (Any): An instance of the parent class
        kwargs (Any): Additional keyword arguments to set on the new instance

    Returns:
        T: A new instance of the child class
    """
    # Get the mapped attributes of the parent class
    mapper = object_mapper(parent_instance)
    attributes = {
        prop.key: getattr(parent_instance, prop.key)
        for prop in mapper.iterate_properties
        if hasattr(parent_instance, prop.key)
        and prop.key
        != mapper.polymorphic_on.name  # don't copy the polymorphic_on attribute from the parent
    }

    # Update attributes with any additional kwargs
    attributes.update(kwargs)

    # Create and return a new instance of the child class
    return cls(**attributes)