Skip to content

Commit

Permalink
Update ocrd_models/ocrd_page_user_methods.py
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Sachunsky <38561704+bertsky@users.noreply.github.com>
  • Loading branch information
bertsky authored and kba committed May 14, 2020
1 parent abef352 commit 3445f87
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions ocrd_models/ocrd_page_user_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,32 @@ def get_AllRegions(self, regions=None, reading_order=False):
Returned in random order unless ``reading_order`` is set (NOT CURRENTLY IMPLEMENTED)
"""
if reading_order:
raise NotImplementedError("Ordering of regions by Reading Order not currently Implemented :(")
reading_order = self.get_ReadingOrder()
if not regions:
regions = ['Advert', 'Chart', 'Chem', 'Custom', 'Graphic', 'Image', 'LineDrawing', 'Map', 'Maths', 'Music', 'Noise', 'Table', 'Text']
regions = ['Advert', 'Chart', 'Chem', 'Custom', 'Graphic', 'Image', 'LineDrawing', 'Map', 'Maths', 'Music', 'Noise', 'Separator', 'Table', 'Text', 'Unknown']
ret = []
for region in regions:
ret += getattr(self, 'get_{}Region'.format(region))()
return ret
if reading_order:
reading_order = reading_order.get_OrderedGroup() or reading_order.get_UnorderedGroup()
if reading_order:
def get_recursive_reading_order(rogroup):
if isinstance(rogroup, (OrderedGroupType, OrderedGroupIndexedType)):
elements = rogroup.get_AllIndexed()
if isinstance(rogroup, (UnorderedGroupType, UnorderedGroupIndexedType)):
elements = (rogroup.get_RegionRef() + rogroup.get_OrderedGroup() + rogroup.get_UnorderedGroup())
regionrefs = list()
for elem in elements:
regionrefs.append(elem.get_regionRef())
if not isinstance(elem, (RegionRefType, RegionRefIndexedType)):
regionrefs.extend(get_recursive_reading_order(elem))
return regionrefs
reading_order = get_recursive_reading_order(reading_order)
if reading_order:
ret = dict([(region.id, region) for region in ret])
return [ret[region_id] for region_id in reading_order if region_id in ret]
else:
return ret
''', class_names=r'^(PageType)$')

#
Expand Down

0 comments on commit 3445f87

Please sign in to comment.