structa-maestro 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- structa_maestro/__init__.py +294 -0
- structa_maestro/batch.py +564 -0
- structa_maestro/binding.py +206 -0
- structa_maestro/builder/__init__.py +0 -0
- structa_maestro/builder/result_builder.py +308 -0
- structa_maestro/cli.py +730 -0
- structa_maestro/confidence/__init__.py +49 -0
- structa_maestro/confidence/calibration.py +990 -0
- structa_maestro/confidence/normalizer.py +203 -0
- structa_maestro/config.py +111 -0
- structa_maestro/contracts/__init__.py +0 -0
- structa_maestro/contracts/enums.py +86 -0
- structa_maestro/contracts/models.py +229 -0
- structa_maestro/contracts/serialization.py +169 -0
- structa_maestro/documents/__init__.py +32 -0
- structa_maestro/documents/docx_parser.py +215 -0
- structa_maestro/documents/eml_parser.py +360 -0
- structa_maestro/documents/html_parser.py +337 -0
- structa_maestro/documents/inputs.py +277 -0
- structa_maestro/documents/loader.py +675 -0
- structa_maestro/documents/markdown_parser.py +225 -0
- structa_maestro/documents/models.py +33 -0
- structa_maestro/documents/normalization.py +24 -0
- structa_maestro/documents/pdf_parser.py +186 -0
- structa_maestro/documents/txt_parser.py +169 -0
- structa_maestro/engine.py +1201 -0
- structa_maestro/exceptions.py +38 -0
- structa_maestro/provenance/__init__.py +0 -0
- structa_maestro/provenance/associator.py +234 -0
- structa_maestro/py.typed +0 -0
- structa_maestro/review.py +1234 -0
- structa_maestro/schema/__init__.py +19 -0
- structa_maestro/schema/loader.py +616 -0
- structa_maestro/schema/models.py +269 -0
- structa_maestro/schema/pydantic_adapter.py +566 -0
- structa_maestro/schema/rules.py +526 -0
- structa_maestro/schema/serializer.py +156 -0
- structa_maestro/strategies/__init__.py +45 -0
- structa_maestro/strategies/base.py +101 -0
- structa_maestro/strategies/llm_anthropic.py +1142 -0
- structa_maestro/strategies/llm_config.py +154 -0
- structa_maestro/strategies/llm_gemini.py +1171 -0
- structa_maestro/strategies/llm_helpers.py +240 -0
- structa_maestro/strategies/llm_openai_compat.py +1183 -0
- structa_maestro/strategies/schema_compiler.py +248 -0
- structa_maestro/strategies/testing.py +71 -0
- structa_maestro/telemetry.py +800 -0
- structa_maestro/validation/__init__.py +0 -0
- structa_maestro/validation/cross_field.py +463 -0
- structa_maestro/validation/validator.py +531 -0
- structa_maestro-0.2.0.dist-info/METADATA +394 -0
- structa_maestro-0.2.0.dist-info/RECORD +55 -0
- structa_maestro-0.2.0.dist-info/WHEEL +4 -0
- structa_maestro-0.2.0.dist-info/entry_points.txt +2 -0
- structa_maestro-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Extraction strategy protocols, OpenAI/Anthropic/Gemini LLM strategies, and test doubles."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from structa_maestro.strategies.base import (
|
|
6
|
+
AsyncExtractionStrategy,
|
|
7
|
+
ExtractionStrategy,
|
|
8
|
+
ProposedEvidence,
|
|
9
|
+
ProposedField,
|
|
10
|
+
ProposedRecord,
|
|
11
|
+
StrategyOutput,
|
|
12
|
+
)
|
|
13
|
+
from structa_maestro.strategies.llm_anthropic import (
|
|
14
|
+
AnthropicLLMStrategy,
|
|
15
|
+
AsyncAnthropicLLMStrategy,
|
|
16
|
+
)
|
|
17
|
+
from structa_maestro.strategies.llm_gemini import (
|
|
18
|
+
AsyncGeminiLLMStrategy,
|
|
19
|
+
GeminiLLMStrategy,
|
|
20
|
+
)
|
|
21
|
+
from structa_maestro.strategies.llm_openai_compat import (
|
|
22
|
+
AsyncOpenAICompatibleLLMStrategy,
|
|
23
|
+
OpenAICompatibleLLMStrategy,
|
|
24
|
+
)
|
|
25
|
+
from structa_maestro.strategies.testing import (
|
|
26
|
+
AsyncDeterministicTestStrategy,
|
|
27
|
+
DeterministicTestStrategy,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"AnthropicLLMStrategy",
|
|
32
|
+
"AsyncAnthropicLLMStrategy",
|
|
33
|
+
"AsyncDeterministicTestStrategy",
|
|
34
|
+
"AsyncExtractionStrategy",
|
|
35
|
+
"AsyncGeminiLLMStrategy",
|
|
36
|
+
"AsyncOpenAICompatibleLLMStrategy",
|
|
37
|
+
"DeterministicTestStrategy",
|
|
38
|
+
"ExtractionStrategy",
|
|
39
|
+
"GeminiLLMStrategy",
|
|
40
|
+
"OpenAICompatibleLLMStrategy",
|
|
41
|
+
"ProposedEvidence",
|
|
42
|
+
"ProposedField",
|
|
43
|
+
"ProposedRecord",
|
|
44
|
+
"StrategyOutput",
|
|
45
|
+
]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Provider-independent ExtractionStrategy protocols and internal strategy DTOs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Any, Protocol, runtime_checkable
|
|
7
|
+
|
|
8
|
+
from structa_maestro.contracts.enums import FieldPresence
|
|
9
|
+
from structa_maestro.contracts.models import DiagnosticIssue
|
|
10
|
+
from structa_maestro.documents.models import PreparedDocument
|
|
11
|
+
from structa_maestro.schema.models import ExtractionSchema
|
|
12
|
+
from structa_maestro.telemetry import StrategyTelemetry
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True, slots=True)
|
|
16
|
+
class ProposedEvidence:
|
|
17
|
+
"""Raw source evidence quote proposed by an extraction strategy before verification."""
|
|
18
|
+
|
|
19
|
+
quote: str
|
|
20
|
+
source_document_id: str | None = None
|
|
21
|
+
page: int | None = None
|
|
22
|
+
paragraph: int | None = None
|
|
23
|
+
line_start: int | None = None
|
|
24
|
+
line_end: int | None = None
|
|
25
|
+
section: str | None = None
|
|
26
|
+
relationship: str = "direct"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True, slots=True)
|
|
30
|
+
class ProposedField:
|
|
31
|
+
"""Raw extracted field value and quality hints proposed by a strategy."""
|
|
32
|
+
|
|
33
|
+
presence: FieldPresence = FieldPresence.PRESENT
|
|
34
|
+
value: Any = None
|
|
35
|
+
confidence: float | None = None
|
|
36
|
+
confidence_method: str | None = None
|
|
37
|
+
confidence_scale: str = "0-1"
|
|
38
|
+
evidence: tuple[ProposedEvidence, ...] = field(default_factory=tuple)
|
|
39
|
+
ambiguous: bool = False
|
|
40
|
+
warnings: tuple[DiagnosticIssue, ...] = field(default_factory=tuple)
|
|
41
|
+
errors: tuple[DiagnosticIssue, ...] = field(default_factory=tuple)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True, slots=True)
|
|
45
|
+
class ProposedRecord:
|
|
46
|
+
"""Raw extracted record proposed by a strategy."""
|
|
47
|
+
|
|
48
|
+
fields: dict[str, ProposedField] = field(default_factory=dict)
|
|
49
|
+
partial: bool = False
|
|
50
|
+
failed: bool = False
|
|
51
|
+
errors: tuple[DiagnosticIssue, ...] = field(default_factory=tuple)
|
|
52
|
+
warnings: tuple[DiagnosticIssue, ...] = field(default_factory=tuple)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass(frozen=True, slots=True)
|
|
56
|
+
class StrategyOutput:
|
|
57
|
+
"""Provider-independent intermediate output returned by any ExtractionStrategy."""
|
|
58
|
+
|
|
59
|
+
records: tuple[ProposedRecord, ...] = field(default_factory=tuple)
|
|
60
|
+
partial: bool = False
|
|
61
|
+
failed: bool = False
|
|
62
|
+
errors: tuple[DiagnosticIssue, ...] = field(default_factory=tuple)
|
|
63
|
+
warnings: tuple[DiagnosticIssue, ...] = field(default_factory=tuple)
|
|
64
|
+
default_confidence_method: str = "extraction-assessment"
|
|
65
|
+
telemetry: StrategyTelemetry | None = None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@runtime_checkable
|
|
69
|
+
class ExtractionStrategy(Protocol):
|
|
70
|
+
"""Replaceable synchronous extraction strategy decoupled from Canonical Output Contract."""
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def name(self) -> str:
|
|
74
|
+
"""Stable human-readable name identifying this strategy."""
|
|
75
|
+
...
|
|
76
|
+
|
|
77
|
+
def extract_raw(
|
|
78
|
+
self,
|
|
79
|
+
document: PreparedDocument,
|
|
80
|
+
schema: ExtractionSchema,
|
|
81
|
+
) -> StrategyOutput:
|
|
82
|
+
"""Extract raw candidate records from a prepared document according to schema."""
|
|
83
|
+
...
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@runtime_checkable
|
|
87
|
+
class AsyncExtractionStrategy(Protocol):
|
|
88
|
+
"""Replaceable native asyncio extraction strategy decoupled from Canonical Output Contract."""
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def name(self) -> str:
|
|
92
|
+
"""Stable human-readable name identifying this strategy."""
|
|
93
|
+
...
|
|
94
|
+
|
|
95
|
+
async def aextract_raw(
|
|
96
|
+
self,
|
|
97
|
+
document: PreparedDocument,
|
|
98
|
+
schema: ExtractionSchema,
|
|
99
|
+
) -> StrategyOutput:
|
|
100
|
+
"""Asynchronously extract raw candidate records from a prepared document."""
|
|
101
|
+
...
|