"""Public document intelligence facade."""
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
from ..models import ParsedDocument
from .classification import classify_document
from .entities import extract_entities
from .extraction import RuleBasedSchemaExtractor, SchemaExtractionBackend
from .models import DocumentClassification, ExtractedEntity, StructuredExtraction
[docs]
class DocumentIntelligence:
"""Classify documents and extract entities or schema-shaped data.
The default backend is deterministic and dependency-free. A custom backend
can implement ``SchemaExtractionBackend`` to integrate an LLM or domain model
while preserving the same evidence-aware result contract.
"""
[docs]
def __init__(self, schema_extractor: SchemaExtractionBackend | None = None) -> None:
self.schema_extractor = schema_extractor or RuleBasedSchemaExtractor()
[docs]
def classify(
self, document: ParsedDocument, *, top_k: int = 3
) -> DocumentClassification:
"""Return ranked document type hypotheses."""
return classify_document(document, top_k=top_k)