Skip to content

Commit d321573

Browse files
committed
Add layout-only inbetween-structure
1 parent 879c043 commit d321573

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

pygexml/page.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,26 @@ def __str__(self) -> str:
8888

8989

9090
@dataclass
91-
class TextLine(DataClassJsonMixin):
91+
class LayoutLine(DataClassJsonMixin):
9292
id: ID
9393
coords: Coords
94+
95+
96+
@dataclass
97+
class LayoutRegion(DataClassJsonMixin):
98+
id: ID
99+
coords: Coords
100+
textlines: dict[ID, LayoutLine]
101+
102+
103+
@dataclass
104+
class PageLayout(DataClassJsonMixin):
105+
image: Image
106+
regions: dict[ID, LayoutRegion]
107+
108+
109+
@dataclass
110+
class TextLine(LayoutLine, DataClassJsonMixin):
94111
text: str
95112

96113
@classmethod
@@ -155,10 +172,8 @@ def words(self) -> Iterable[str]:
155172

156173

157174
@dataclass
158-
class TextRegion(DataClassJsonMixin):
159-
id: ID
160-
coords: Coords
161-
textlines: dict[ID, TextLine]
175+
class TextRegion(LayoutRegion, DataClassJsonMixin):
176+
textlines: dict[ID, TextLine] # type: ignore[assignment]
162177

163178
@classmethod
164179
def from_xml(cls, element: Element) -> "TextRegion":
@@ -225,9 +240,8 @@ def all_words(self) -> Iterable[str]:
225240

226241

227242
@dataclass
228-
class Page(DataClassJsonMixin):
229-
image: Image
230-
regions: dict[ID, TextRegion]
243+
class Page(PageLayout, DataClassJsonMixin):
244+
regions: dict[ID, TextRegion] # type: ignore[assignment]
231245

232246
@classmethod
233247
def from_xml(cls, element: Element) -> "Page":

0 commit comments

Comments
 (0)