anyformat 2.0.0__tar.gz → 2.1.0__tar.gz
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.
- {anyformat-2.0.0 → anyformat-2.1.0}/PKG-INFO +1 -1
- {anyformat-2.0.0 → anyformat-2.1.0}/pyproject.toml +1 -1
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/nodes.py +3 -3
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/results.py +80 -14
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/topology.py +13 -14
- {anyformat-2.0.0 → anyformat-2.1.0}/README.md +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/__init__.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/_banner.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/_http.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/_source.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/_viz.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/builder.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/cli.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/client.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/errors.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/handles.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/result.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/sdk/views.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/__init__.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/builder.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/checks.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/definition.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/fields.py +0 -0
- {anyformat-2.0.0 → anyformat-2.1.0}/src/anyformat/workflow/schema.py +0 -0
|
@@ -184,9 +184,9 @@ class ParseNode(BaseNode):
|
|
|
184
184
|
|
|
185
185
|
@classmethod
|
|
186
186
|
def accepts(cls, predecessor: type["BaseNode"]) -> bool:
|
|
187
|
-
# A branch Parse re-reads the document on a Classify/If-Else arm
|
|
188
|
-
#
|
|
189
|
-
return predecessor in (ClassifyNode, IfElseNode)
|
|
187
|
+
# A branch Parse re-reads the document on a Classify/If-Else arm, or only
|
|
188
|
+
# the pages of a splitter partition.
|
|
189
|
+
return predecessor in (ClassifyNode, IfElseNode, SplitterNode)
|
|
190
190
|
|
|
191
191
|
@classmethod
|
|
192
192
|
def builder_verb(cls) -> str:
|
|
@@ -33,6 +33,14 @@ def _drop_unset_file_refs(data: dict[str, Any]) -> dict[str, Any]:
|
|
|
33
33
|
return data
|
|
34
34
|
|
|
35
35
|
|
|
36
|
+
class _OmitsUnsetFileRefs(BaseModel):
|
|
37
|
+
"""A model whose ``file_id``, ``file_name`` and ``file_page`` are omitted when unset, never ``null``."""
|
|
38
|
+
|
|
39
|
+
@model_serializer(mode="wrap")
|
|
40
|
+
def _omit_unset_file_refs(self, handler: SerializerFunctionWrapHandler): # noqa: ANN202 — pydantic reads a return annotation as the serialization schema
|
|
41
|
+
return _drop_unset_file_refs(handler(self))
|
|
42
|
+
|
|
43
|
+
|
|
36
44
|
class Evidence(BaseModel):
|
|
37
45
|
"""A snippet of source text supporting an extracted value, with the page it came from.
|
|
38
46
|
|
|
@@ -201,7 +209,7 @@ class Detection(BaseModel):
|
|
|
201
209
|
text: str = Field(description="The words the page prints inside this box.")
|
|
202
210
|
|
|
203
211
|
|
|
204
|
-
class Block(
|
|
212
|
+
class Block(_OmitsUnsetFileRefs):
|
|
205
213
|
"""One semantic block of a parsed document — a structured alternative to
|
|
206
214
|
walking `<a id></a>` anchors in `markdown`.
|
|
207
215
|
|
|
@@ -273,10 +281,6 @@ class Block(BaseModel):
|
|
|
273
281
|
),
|
|
274
282
|
)
|
|
275
283
|
|
|
276
|
-
@model_serializer(mode="wrap")
|
|
277
|
-
def _omit_unset_file_refs(self, handler: SerializerFunctionWrapHandler): # noqa: ANN202 — pydantic reads a return annotation as the serialization schema
|
|
278
|
-
return _drop_unset_file_refs(handler(self))
|
|
279
|
-
|
|
280
284
|
|
|
281
285
|
class ParseResult(BaseModel):
|
|
282
286
|
"""Parsed markdown for a file."""
|
|
@@ -344,7 +348,7 @@ class RunParsePageStatus(BaseModel):
|
|
|
344
348
|
reason: Optional[str] = Field(description="Why the fallback was taken; `null` when `kind` is `ok`.")
|
|
345
349
|
|
|
346
350
|
|
|
347
|
-
class RunParsePage(
|
|
351
|
+
class RunParsePage(_OmitsUnsetFileRefs):
|
|
348
352
|
"""One page a parse read, as it recorded the page, whether or not the page holds a block.
|
|
349
353
|
|
|
350
354
|
A value is `null` where the parse did not record it: a parse stored before page facts were, or a file without pages.
|
|
@@ -368,9 +372,56 @@ class RunParsePage(BaseModel):
|
|
|
368
372
|
default=None, description="Where the page's text came from: `embedded`, `ocr`, `mixed` or `none`."
|
|
369
373
|
)
|
|
370
374
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
375
|
+
|
|
376
|
+
class RunParseLayerAbsence(BaseModel):
|
|
377
|
+
"""Why a parse answers one of its layers without the layer's records."""
|
|
378
|
+
|
|
379
|
+
absent: str = Field(
|
|
380
|
+
description=(
|
|
381
|
+
"The stored reason, such as `build_failed`, or why a read could not serve a stored layer: `too_large` "
|
|
382
|
+
"above the inline limit, `unreadable` when its object cannot be read back. The public API words each as "
|
|
383
|
+
"its own."
|
|
384
|
+
)
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
class RunParseSequenceConfidence(BaseModel):
|
|
389
|
+
mean: float = Field(description="The mean confidence of the sequence's elements, 0-1, as core measured it.")
|
|
390
|
+
min: float = Field(description="The lowest confidence of the sequence's elements, 0-1, as core measured it.")
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
class RunParseSequence(_OmitsUnsetFileRefs):
|
|
394
|
+
"""A run of elements the parse grouped by horizontal proximity inside one block: often a line, never guaranteed."""
|
|
395
|
+
|
|
396
|
+
id: str = Field(description="`p<page>_s<index>`, numbered by the packet page `page`.")
|
|
397
|
+
block_id: str = Field(description="The `blocks[].id` of the block that holds it.")
|
|
398
|
+
page: int = Field(description="1-indexed page number, counted across the packet's files in packet order.")
|
|
399
|
+
file_id: Optional[str] = Field(default=None, description="The file this page belongs to.")
|
|
400
|
+
file_page: Optional[int] = Field(default=None, description="1-indexed page of that file.")
|
|
401
|
+
text: str = Field(description="The sequence's text, as core read it.")
|
|
402
|
+
bbox: dict[str, float] = Field(
|
|
403
|
+
description="Normalised bounding box in [0, 1] page coordinates with keys `x0`/`y0`/`x1`/`y1`.",
|
|
404
|
+
)
|
|
405
|
+
confidence: Optional[RunParseSequenceConfidence] = Field(
|
|
406
|
+
description="`null` when nothing scored it: a model's reading of handwriting."
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
class RunParseElement(_OmitsUnsetFileRefs):
|
|
411
|
+
"""One piece of text as read: a word, or a whole line when the OCR engine boxed it as one."""
|
|
412
|
+
|
|
413
|
+
id: str = Field(description="`p<page>_e<index>`, numbered by the packet page `page`.")
|
|
414
|
+
block_id: str = Field(description="The `blocks[].id` of the block that owns it.")
|
|
415
|
+
sequence_id: Optional[str] = Field(description="The sequence of its block that holds it; `null` when none does.")
|
|
416
|
+
page: int = Field(description="1-indexed page number, counted across the packet's files in packet order.")
|
|
417
|
+
file_id: Optional[str] = Field(default=None, description="The file this page belongs to.")
|
|
418
|
+
file_page: Optional[int] = Field(default=None, description="1-indexed page of that file.")
|
|
419
|
+
text: str = Field(description="The element's text, as core read it.")
|
|
420
|
+
bbox: dict[str, float] = Field(
|
|
421
|
+
description="Normalised bounding box in [0, 1] page coordinates with keys `x0`/`y0`/`x1`/`y1`.",
|
|
422
|
+
)
|
|
423
|
+
confidence: Optional[float] = Field(description="0-1, as core measured it; `null` when nothing scored it.")
|
|
424
|
+
source: str = Field(description="Where its text came from: `embedded`, `ocr` or `transcribed`.")
|
|
374
425
|
|
|
375
426
|
|
|
376
427
|
class RunParseV3(ParseResult):
|
|
@@ -402,9 +453,25 @@ class RunParseV3(ParseResult):
|
|
|
402
453
|
read_by_extraction: bool = Field(
|
|
403
454
|
description="Whether an extraction of the run read this parse: the nearest parse upstream of its extract node.",
|
|
404
455
|
)
|
|
456
|
+
layers: Optional[dict[str, RunParseLayerAbsence]] = Field(
|
|
457
|
+
default=None,
|
|
458
|
+
description=(
|
|
459
|
+
"Each layer the parse stored without its object, by name, with the reason, and each layer asked for that "
|
|
460
|
+
"the read could not serve; any other stored layer is not listed. `null` when the run stored no listing of this node's packet parse, as for a parse stored before "
|
|
461
|
+
"listings were."
|
|
462
|
+
),
|
|
463
|
+
)
|
|
464
|
+
sequences: Optional[list[RunParseSequence]] = Field(
|
|
465
|
+
default=None,
|
|
466
|
+
description="Each sequence, in packet page and reading order, when asked for and served; else `null`.",
|
|
467
|
+
)
|
|
468
|
+
elements: Optional[list[RunParseElement]] = Field(
|
|
469
|
+
default=None,
|
|
470
|
+
description="Each element, in packet page and reading order, when asked for and served; else `null`.",
|
|
471
|
+
)
|
|
405
472
|
|
|
406
473
|
|
|
407
|
-
class ParsePage(
|
|
474
|
+
class ParsePage(_OmitsUnsetFileRefs):
|
|
408
475
|
"""One page of a parse as its blocks, in reading order."""
|
|
409
476
|
|
|
410
477
|
page: int = Field(description="1-indexed page number, counted across the packet's files in packet order.")
|
|
@@ -413,10 +480,6 @@ class ParsePage(BaseModel):
|
|
|
413
480
|
file_page: Optional[int] = Field(default=None, description="1-indexed page of that file.")
|
|
414
481
|
blocks: list[Block] = Field(description="The page's blocks in reading order, each with its `content`.")
|
|
415
482
|
|
|
416
|
-
@model_serializer(mode="wrap")
|
|
417
|
-
def _omit_unset_file_refs(self, handler: SerializerFunctionWrapHandler): # noqa: ANN202 — pydantic reads a return annotation as the serialization schema
|
|
418
|
-
return _drop_unset_file_refs(handler(self))
|
|
419
|
-
|
|
420
483
|
|
|
421
484
|
class ParseBlocksResultV3(BaseModel):
|
|
422
485
|
"""The parse as pages of blocks, each block with its text, and no markdown: `parse_format=blocks`.
|
|
@@ -862,8 +925,11 @@ __all__ = [
|
|
|
862
925
|
"ResultsResponse",
|
|
863
926
|
"ResultsResponseV3",
|
|
864
927
|
"CodeOutput",
|
|
928
|
+
"RunParseElement",
|
|
929
|
+
"RunParseLayerAbsence",
|
|
865
930
|
"RunParsePage",
|
|
866
931
|
"RunParsePageStatus",
|
|
932
|
+
"RunParseSequence",
|
|
867
933
|
"RunParseV3",
|
|
868
934
|
"SplitPartition",
|
|
869
935
|
"SplitResult",
|
|
@@ -27,6 +27,7 @@ from anyformat.workflow.nodes import (
|
|
|
27
27
|
ClassifyNode,
|
|
28
28
|
CodeNode,
|
|
29
29
|
ExtractNode,
|
|
30
|
+
FilterNode,
|
|
30
31
|
IfElseNode,
|
|
31
32
|
KnowledgeNode,
|
|
32
33
|
ParseNode,
|
|
@@ -81,7 +82,7 @@ class ExactlyOneParseNode:
|
|
|
81
82
|
|
|
82
83
|
class ExactlyOneEntryParseNode:
|
|
83
84
|
"""One entry Parse (no incoming edge); every other Parse fed by a single
|
|
84
|
-
edge from a branching node (classify / if_else). Silent below two Parses.
|
|
85
|
+
edge from a branching node (classify / if_else / splitter). Silent below two Parses.
|
|
85
86
|
"""
|
|
86
87
|
|
|
87
88
|
name = "exactly_one_entry_parse_node"
|
|
@@ -136,16 +137,14 @@ class ExactlyOneEntryParseNode:
|
|
|
136
137
|
)
|
|
137
138
|
]
|
|
138
139
|
source = nodes_by_id.get(sources[0])
|
|
139
|
-
|
|
140
|
-
# sub-document, not a Parse feeder.
|
|
141
|
-
if type(source) in (ClassifyNode, IfElseNode):
|
|
140
|
+
if type(source) in (ClassifyNode, IfElseNode, SplitterNode):
|
|
142
141
|
return []
|
|
143
142
|
found = source.type if source else "unknown"
|
|
144
143
|
return [
|
|
145
144
|
Violation(
|
|
146
145
|
rule=self.name,
|
|
147
146
|
message=f"branch `parse` node {parse.id!r} must be fed by a branching "
|
|
148
|
-
f"node (classify / if_else), not by {found!r}",
|
|
147
|
+
f"node (classify / if_else / splitter), not by {found!r}",
|
|
149
148
|
node_ids=[parse.id],
|
|
150
149
|
)
|
|
151
150
|
]
|
|
@@ -673,11 +672,11 @@ class NoParseAsBranchTarget:
|
|
|
673
672
|
]
|
|
674
673
|
|
|
675
674
|
|
|
676
|
-
class
|
|
677
|
-
"""Reject a
|
|
678
|
-
|
|
675
|
+
class NoRouterUnderSplitter:
|
|
676
|
+
"""Reject a Classify, Splitter or Filter reachable from a Splitter, however deep. A partition is
|
|
677
|
+
re-read by a Parse at most, never classified, split or discarded on its own (ADR platform/0106)."""
|
|
679
678
|
|
|
680
|
-
name = "
|
|
679
|
+
name = "no_router_under_splitter"
|
|
681
680
|
|
|
682
681
|
def check(self, graph: "WorkflowDefinition") -> list[Violation]:
|
|
683
682
|
successors: dict[str, list[str]] = {}
|
|
@@ -693,12 +692,12 @@ class NoParseUnderSplitter:
|
|
|
693
692
|
return [
|
|
694
693
|
Violation(
|
|
695
694
|
rule=self.name,
|
|
696
|
-
message=f"
|
|
697
|
-
"cannot
|
|
695
|
+
message=f"{node.type} node {node.id!r} sits downstream of a splitter; a partition "
|
|
696
|
+
"cannot be classified, split or filtered again.",
|
|
698
697
|
node_ids=[node.id],
|
|
699
698
|
)
|
|
700
699
|
for node in graph.nodes
|
|
701
|
-
if isinstance(node,
|
|
700
|
+
if isinstance(node, (ClassifyNode, SplitterNode, FilterNode)) and node.id in downstream_of_splitter
|
|
702
701
|
]
|
|
703
702
|
|
|
704
703
|
|
|
@@ -906,7 +905,7 @@ RULES: list[TopologyRule] = [
|
|
|
906
905
|
EveryExtractNodeHasFields(),
|
|
907
906
|
EveryIfElseHasTrueBranch(),
|
|
908
907
|
NoParseAsBranchTarget(),
|
|
909
|
-
|
|
908
|
+
NoRouterUnderSplitter(),
|
|
910
909
|
NoCodeInstructions(),
|
|
911
910
|
ValidationRuleIdReferencesExist(),
|
|
912
911
|
NoCycles(),
|
|
@@ -1052,7 +1051,7 @@ __all__ = [
|
|
|
1052
1051
|
"NoCycles",
|
|
1053
1052
|
"NodeAdjacency",
|
|
1054
1053
|
"NoParseAsBranchTarget",
|
|
1055
|
-
"
|
|
1054
|
+
"NoRouterUnderSplitter",
|
|
1056
1055
|
"NonBranchingNodeHasAtMostOneOutgoing",
|
|
1057
1056
|
"RULES",
|
|
1058
1057
|
"SingleUpstreamNodeHasOneIncoming",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|