Skip to content

pixano.features.schemas.schema_group

SchemaGroup

Bases: Enum

Schema group.

It defines the different schema groups to which a schema can belong.

Attributes:

Name Type Description
ANNOTATION

Annotation schema group.

EMBEDDING

Embedding schema group.

ITEM

Item schema group.

ENTITY

Entity schema group.

VIEW

View schema group.

group_to_str(group, plural=False)

Convert the schema group to a string.

Attributes:

Name Type Description
group

The schema group.

plural

Whether to use the plural form of the word.

Returns:

Type Description
str

The string for the given schema group.

Source code in pixano/features/schemas/schema_group.py
def group_to_str(group: SchemaGroup, plural: bool = False) -> str:
    """Convert the schema group to a string.

    Attributes:
        group: The schema group.
        plural: Whether to use the plural form of the word.

    Returns:
        The string for the given schema group.
    """
    if group == SchemaGroup.SOURCE:
        return "sources" if plural else "source"
    elif group == SchemaGroup.ITEM:
        return "items" if plural else "item"
    elif group == SchemaGroup.ENTITY:
        return "entities" if plural else "entity"
    elif group == SchemaGroup.VIEW:
        return "views" if plural else "view"
    elif group == SchemaGroup.ANNOTATION:
        return "annotations" if plural else "annotation"
    elif group == SchemaGroup.EMBEDDING:
        return "embeddings" if plural else "embedding"
    raise ValueError(f"Unknown schema group: {group}")

schema_to_group(schema_type)

Get the schema group of a given schema type.

Source code in pixano/features/schemas/schema_group.py
def schema_to_group(schema_type: BaseSchema | type) -> SchemaGroup:
    """Get the schema group of a given schema type."""
    try:
        issubclass(schema_type, BaseSchema)
    except TypeError:
        is_class = False
    else:
        is_class = True
    if isinstance(schema_type, Embedding) or is_class and issubclass(schema_type, Embedding):
        return SchemaGroup.EMBEDDING
    elif isinstance(schema_type, Item) or is_class and issubclass(schema_type, Item):
        return SchemaGroup.ITEM
    elif isinstance(schema_type, Entity) or is_class and issubclass(schema_type, Entity):
        return SchemaGroup.ENTITY
    elif isinstance(schema_type, Annotation) or is_class and issubclass(schema_type, Annotation):
        return SchemaGroup.ANNOTATION
    elif isinstance(schema_type, View) or is_class and issubclass(schema_type, View):
        return SchemaGroup.VIEW
    elif isinstance(schema_type, Source) or is_class and issubclass(schema_type, Source):
        return SchemaGroup.SOURCE
    else:
        raise ValueError(f"Unknown schema type: {schema_type}")