Skip to content

Commit 371ed55

Browse files
hBouananeclaude
andcommitted
feat(domain): add geometry, annotation and sample model
The contract between renderers and exporters. Immutable, pixel-free objects that can be built, reordered and serialised without touching an image. - geometry.py: BBox (ordering-normalised, with union/intersection/IoU/clip/ normalise) and Polygon for rotated or warped regions. - annotations.py: Page -> Region -> Line -> Word plus Table/TableCell. Regions are typed with layout categories used by document-layout benchmarks, carry an explicit reading order, and serialise the page back to HTML or Markdown - the supervision format document-to-markup models are trained against. Tables additionally emit OTSL for table-structure models. - sample.py: Sample = image + Page + Provenance, where provenance records the seed, font, background, renderer, shaper and degradations so any single sample can be explained and regenerated. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 5cae3c4 commit 371ed55

9 files changed

Lines changed: 1308 additions & 15 deletions

File tree

src/ocrsmith/datasets/loaders/HuggingFaceTextLoader.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ def _check_columns(self, dataset: Any) -> None:
8888
if not isinstance(columns, (list, tuple)):
8989
return # duck-typed source: validated per record instead
9090
if self.text_column not in columns:
91-
raise ValueError(
92-
f"Column '{self.text_column}' not found. Available columns: {list(columns)}"
93-
)
91+
raise ValueError(f"Column '{self.text_column}' not found. Available columns: {list(columns)}")
9492
if self.title_column and self.title_column not in columns:
9593
self.title_column = None
9694

src/ocrsmith/domain/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Domain model: geometry, annotations and generated samples.
2+
3+
These types are the contract between the renderers that produce pixels and the exporters
4+
that write datasets. They are immutable and pixel-free, so they can be built, reordered
5+
and serialised without touching an image.
6+
"""
7+
8+
from .annotations import (
9+
Line,
10+
Page,
11+
Region,
12+
RegionType,
13+
Table,
14+
TableCell,
15+
Word,
16+
assign_reading_order,
17+
)
18+
from .geometry import BBox, Point, Polygon
19+
from .sample import Provenance, Sample
20+
21+
__all__ = [
22+
"BBox",
23+
"Line",
24+
"Page",
25+
"Point",
26+
"Polygon",
27+
"Provenance",
28+
"Region",
29+
"RegionType",
30+
"Sample",
31+
"Table",
32+
"TableCell",
33+
"Word",
34+
"assign_reading_order",
35+
]

0 commit comments

Comments
 (0)