@@ 3317-3349 (lines=33) @@ | ||
3314 | ret += lines if lo in ['top-to-bottom', 'left-to-right'] else list(reversed(lines)) |
|
3315 | return ret |
|
3316 | ||
3317 | def get_ReadingOrderGroups(self) -> dict: |
|
3318 | """ |
|
3319 | Aggregate recursive ReadingOrder into a dictionary, mapping each regionRef |
|
3320 | (i.e. segment `@id`) to its referring group object (i.e one of |
|
3321 | ||
3322 | \b |
|
3323 | - :py:class:`.RegionRefType` |
|
3324 | - :py:class:`.RegionRefIndexedType` |
|
3325 | - :py:class:`.OrderedGroupType` |
|
3326 | - :py:class:`.OrderedGroupIndexedType` |
|
3327 | - :py:class:`.UnoderedGroupType` |
|
3328 | - :py:class:`.UnoderedGroupIndexedType` |
|
3329 | """ |
|
3330 | def get_groupdict(group): |
|
3331 | regionrefs = list() |
|
3332 | if isinstance(group, (OrderedGroupType, OrderedGroupIndexedType)): |
|
3333 | regionrefs = (group.get_RegionRefIndexed() + |
|
3334 | group.get_OrderedGroupIndexed() + |
|
3335 | group.get_UnorderedGroupIndexed()) |
|
3336 | if isinstance(group, (UnorderedGroupType, UnorderedGroupIndexedType)): |
|
3337 | regionrefs = (group.get_RegionRef() + |
|
3338 | group.get_OrderedGroup() + |
|
3339 | group.get_UnorderedGroup()) |
|
3340 | refdict = {} |
|
3341 | for elem in regionrefs: |
|
3342 | refdict[elem.get_regionRef()] = elem |
|
3343 | if not isinstance(elem, (RegionRefType, RegionRefIndexedType)): |
|
3344 | refdict = {**refdict, **get_groupdict(elem)} |
|
3345 | return refdict |
|
3346 | ro = self.get_ReadingOrder() |
|
3347 | if ro is None: |
|
3348 | return {} |
|
3349 | return get_groupdict(ro.get_OrderedGroup() or ro.get_UnorderedGroup()) |
|
3350 | def set_orientation(self, orientation): |
|
3351 | """ |
|
3352 | Set deskewing angle to given `orientation` number. |
@@ 1-33 (lines=33) @@ | ||
1 | def get_ReadingOrderGroups(self) -> dict: |
|
2 | """ |
|
3 | Aggregate recursive ReadingOrder into a dictionary, mapping each regionRef |
|
4 | (i.e. segment `@id`) to its referring group object (i.e one of |
|
5 | ||
6 | \b |
|
7 | - :py:class:`.RegionRefType` |
|
8 | - :py:class:`.RegionRefIndexedType` |
|
9 | - :py:class:`.OrderedGroupType` |
|
10 | - :py:class:`.OrderedGroupIndexedType` |
|
11 | - :py:class:`.UnoderedGroupType` |
|
12 | - :py:class:`.UnoderedGroupIndexedType` |
|
13 | """ |
|
14 | def get_groupdict(group): |
|
15 | regionrefs = list() |
|
16 | if isinstance(group, (OrderedGroupType, OrderedGroupIndexedType)): |
|
17 | regionrefs = (group.get_RegionRefIndexed() + |
|
18 | group.get_OrderedGroupIndexed() + |
|
19 | group.get_UnorderedGroupIndexed()) |
|
20 | if isinstance(group, (UnorderedGroupType, UnorderedGroupIndexedType)): |
|
21 | regionrefs = (group.get_RegionRef() + |
|
22 | group.get_OrderedGroup() + |
|
23 | group.get_UnorderedGroup()) |
|
24 | refdict = {} |
|
25 | for elem in regionrefs: |
|
26 | refdict[elem.get_regionRef()] = elem |
|
27 | if not isinstance(elem, (RegionRefType, RegionRefIndexedType)): |
|
28 | refdict = {**refdict, **get_groupdict(elem)} |
|
29 | return refdict |
|
30 | ro = self.get_ReadingOrder() |
|
31 | if ro is None: |
|
32 | return {} |
|
33 | return get_groupdict(ro.get_OrderedGroup() or ro.get_UnorderedGroup()) |
|
34 |