ie_schema ========= .. py:module:: ie_schema Classes ------- .. autoapisummary:: ie_schema.ClassificationTask ie_schema.EntityExtractionTask ie_schema.IESchema ie_schema.JSONStructureTask ie_schema.RelationExtractionTask ie_schema.StructureChild ie_schema.Task Module Contents --------------- .. py:class:: ClassificationTask Bases: :py:obj:`Task` Classification task definition with labels and threshold metadata. .. py:property:: labels :type: list[str] Ordered list of class labels. .. py:property:: multi_label :type: bool Whether multiple labels may be assigned. .. py:property:: task :type: str Classification task name. .. py:property:: threshold :type: Optional[float] Optional confidence threshold for the classification. .. py:class:: EntityExtractionTask Bases: :py:obj:`Task` Entity extraction task definition. .. py:property:: entities :type: list[str] Entity labels that should be extracted. .. py:class:: IESchema 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 .. py:method:: load(path: str) -> IESchema :classmethod: Parse an `IESchema` from a JSON file path. .. py:method:: loads(input: Any) -> IESchema :classmethod: 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 .. py:method:: prompt() -> str 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 .. py:class:: JSONStructureTask Bases: :py:obj:`Task` Structured JSON extraction task with named children. .. py:property:: children :type: list[StructureChild] Child fields that belong to this structure. .. py:property:: name :type: str Structure name. .. py:class:: RelationExtractionTask Bases: :py:obj:`Task` Relation extraction task between head and tail entity types. .. py:property:: description :type: Optional[str] Optional human-readable relation description. .. py:property:: head :type: str Head entity type. .. py:property:: name :type: str Relation name. .. py:property:: tail :type: str Tail entity type. .. py:class:: StructureChild Child field in a `JSONStructureTask`. .. py:property:: choices :type: list[str] Allowed string choices for this property. .. py:property:: description :type: Optional[str] Optional child-field description. .. py:property:: property :type: str Property name for this child field. .. py:class:: Task Base class for all extraction tasks yielded by `IESchema`.