From b728885347fd02ddbf05bb5c48745b3bf1c43598 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 14 May 2020 14:13:35 +0200 Subject: [PATCH] Update ocrd_models/ocrd_page_user_methods.py Co-authored-by: Robert Sachunsky <38561704+bertsky@users.noreply.github.com> --- ocrd_models/ocrd_page_user_methods.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ocrd_models/ocrd_page_user_methods.py b/ocrd_models/ocrd_page_user_methods.py index 7a49908fa..da77ad7f5 100644 --- a/ocrd_models/ocrd_page_user_methods.py +++ b/ocrd_models/ocrd_page_user_methods.py @@ -100,7 +100,26 @@ def get_AllRegions(self, regions=None, reading_order=False): 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)$') #