ie-schema 0.1.5

A flexible schema specification and parser for information extraction tasks.
Documentation
# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401, F403, F405

import builtins
import typing
__all__ = [
    "ClassificationTask",
    "EntityExtractionTask",
    "IESchema",
    "JSONStructureTask",
    "RelationExtractionTask",
    "StructureChild",
    "Task",
]

@typing.final
class ClassificationTask(Task):
    r"""
    Classification task definition with labels and threshold metadata.
    """
    @property
    def task(self) -> builtins.str:
        r"""
        Classification task name.
        """
    @property
    def labels(self) -> builtins.list[builtins.str]:
        r"""
        Ordered list of class labels.
        """
    @property
    def threshold(self) -> typing.Optional[builtins.float]:
        r"""
        Optional confidence threshold for the classification.
        """
    @property
    def multi_label(self) -> builtins.bool:
        r"""
        Whether multiple labels may be assigned.
        """

@typing.final
class EntityExtractionTask(Task):
    r"""
    Entity extraction task definition.
    """
    @property
    def entities(self) -> builtins.list[builtins.str]:
        r"""
        Entity labels that should be extracted.
        """

@typing.final
class IESchema:
    r"""
    Information-extraction schema loaded from JSON (or from a dataclass / Pydantic model type).
    
    Build an `IESchema` from a JSON string with `loads()` (IE ingest JSON or a root JSON Schema
    object), from a path with `load()`, or from a stdlib dataclass / Pydantic v2 `BaseModel` by
    passing the class (or an instance) to `loads()`. Iterating over the object yields task instances
    in schema order.
    
    Example:
    >>> import ie_schema
    >>> _j = '{"json_structures":[{"name":"Business","business_name":{"dtype":"str"}}]}'
    >>> schema = ie_schema.IESchema.loads(_j)
    >>> isinstance(schema, ie_schema.IESchema)
    True
    >>> len(list(schema))
    1
    """
    @classmethod
    def loads(cls, input: typing.Any) -> IESchema:
        r"""
        Parse an `IESchema` from a JSON string or from a dataclass / Pydantic v2 `BaseModel` type.
        
        String input must be either IE ingest JSON (top-level keys such as `json_structures`,
        `entities`, …) or a root JSON Schema object (`type`, `properties`, …). Unknown top-level
        keys are rejected for the IE shape so JSON Schema is not misread as an empty ingest.
        
        For a dataclass or `BaseModel` type (or instance), Pydantic v2 builds JSON Schema
        (`TypeAdapter` for dataclasses, `model_json_schema()` for `BaseModel` subclasses), which is
        then parsed like JSON Schema string input.
        
        Example:
        >>> import ie_schema
        >>> schema = ie_schema.IESchema.loads('{"json_structures":[{"name":"Business","business_name":{"dtype":"str"}}]}')
        >>> len(list(schema))
        1
        """
    @classmethod
    def load(cls, path: builtins.str) -> IESchema:
        r"""
        Parse an `IESchema` from a JSON file path.
        """
    def __iter__(self) -> IESchema:
        r"""
        Return an iterator over planned extraction tasks.
        """
    def __next__(self) -> typing.Optional[typing.Any]:
        r"""
        Return the next planned task, or `None` at the end.
        """
    def prompt(self) -> builtins.str:
        r"""
        Render the generated extraction prompt as a debug string.
        
        Example:
        >>> import ie_schema
        >>> schema = ie_schema.IESchema.loads('{"json_structures":[{"name":"Business","business_name":{"dtype":"str"}}]}')
        >>> s = schema.prompt()
        >>> ("[P]" in s) and ("business_name" in s)
        True
        """

@typing.final
class JSONStructureTask(Task):
    r"""
    Structured JSON extraction task with named children.
    """
    @property
    def name(self) -> builtins.str:
        r"""
        Structure name.
        """
    @property
    def children(self) -> builtins.list[StructureChild]:
        r"""
        Child fields that belong to this structure.
        """

@typing.final
class RelationExtractionTask(Task):
    r"""
    Relation extraction task between head and tail entity types.
    """
    @property
    def name(self) -> builtins.str:
        r"""
        Relation name.
        """
    @property
    def head(self) -> builtins.str:
        r"""
        Head entity type.
        """
    @property
    def tail(self) -> builtins.str:
        r"""
        Tail entity type.
        """
    @property
    def description(self) -> typing.Optional[builtins.str]:
        r"""
        Optional human-readable relation description.
        """

@typing.final
class StructureChild:
    r"""
    Child field in a `JSONStructureTask`.
    """
    @property
    def property(self) -> builtins.str:
        r"""
        Property name for this child field.
        """
    @property
    def choices(self) -> builtins.list[builtins.str]:
        r"""
        Allowed string choices for this property.
        """
    @property
    def description(self) -> typing.Optional[builtins.str]:
        r"""
        Optional child-field description.
        """

class Task:
    r"""
    Base class for all extraction tasks yielded by `IESchema`.
    """
    ...