@@ -83,12 +83,9 @@ def __str__(self) -> str:
8383 return " " .join (str (p ) for p in self .polygon .points )
8484
8585
86- type ID = str
87-
88-
8986@dataclass
9087class TextLine (DataClassJsonMixin ):
91- id : ID
88+ id : str
9289 coords : Coords
9390 text : str
9491
@@ -155,9 +152,9 @@ def words(self) -> Iterable[str]:
155152
156153@dataclass
157154class TextRegion (DataClassJsonMixin ):
158- id : ID
155+ id : str
159156 coords : Coords
160- textlines : dict [ID , TextLine ]
157+ textlines : dict [str , TextLine ]
161158
162159 @classmethod
163160 def from_xml (cls , element : Element ) -> "TextRegion" :
@@ -200,7 +197,7 @@ def from_alto(cls, element: Element) -> "TextRegion":
200197 )
201198 )
202199
203- textlines : dict [ID , TextLine ] = {}
200+ textlines : dict [str , TextLine ] = {}
204201 for child in element :
205202 if QName (child ).localname == "TextLine" :
206203 tl = TextLine .from_alto (child )
@@ -213,7 +210,7 @@ def from_alto(cls, element: Element) -> "TextRegion":
213210 id = str (element .attrib ["ID" ]), coords = coords , textlines = textlines
214211 )
215212
216- def lookup_textline (self , id : ID ) -> TextLine | None :
213+ def lookup_textline (self , id : str ) -> TextLine | None :
217214 return self .textlines .get (id )
218215
219216 def all_text (self ) -> Iterable [str ]:
@@ -226,7 +223,7 @@ def all_words(self) -> Iterable[str]:
226223@dataclass
227224class Page (DataClassJsonMixin ):
228225 image_filename : str
229- regions : dict [ID , TextRegion ]
226+ regions : dict [str , TextRegion ]
230227
231228 @classmethod
232229 def from_xml (cls , element : Element ) -> "Page" :
@@ -307,7 +304,7 @@ def from_alto_file(cls, file: Path | str, encoding: str = "utf-8") -> "Page":
307304 xml_string = path .read_text (encoding = encoding )
308305 return Page .from_alto_string (xml_string )
309306
310- def lookup_region (self , id : ID ) -> TextRegion | None :
307+ def lookup_region (self , id : str ) -> TextRegion | None :
311308 return self .regions .get (id )
312309
313310 def all_text (self ) -> Iterable [str ]:
0 commit comments