From a3465ca1a017e6d198ea4851f76dda0734e950f2 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 11 Mar 2021 19:44:42 +0100 Subject: [PATCH] eliminate id_of_texts from xml_reading_order, fix plus one error --- qurator/eynollah/utils/counter.py | 6 +++--- qurator/eynollah/utils/xml.py | 4 ++-- qurator/eynollah/writer.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qurator/eynollah/utils/counter.py b/qurator/eynollah/utils/counter.py index 5280c6f..6bd9d7d 100644 --- a/qurator/eynollah/utils/counter.py +++ b/qurator/eynollah/utils/counter.py @@ -20,14 +20,14 @@ class EynollahIdCounter(): self._counter[name] = val def region_id(self, region_idx=None): - if not region_idx: + if region_idx is None: region_idx = self._counter['region'] return REGION_ID_TEMPLATE % region_idx def line_id(self, region_idx=None, line_idx=None): - if not region_idx: + if region_idx is None: region_idx = self._counter['region'] - if not line_idx: + if line_idx is None: line_idx = self._counter['line'] return LINE_ID_TEMPLATE % (region_idx, line_idx) diff --git a/qurator/eynollah/utils/xml.py b/qurator/eynollah/utils/xml.py index b5c5ce3..e972218 100644 --- a/qurator/eynollah/utils/xml.py +++ b/qurator/eynollah/utils/xml.py @@ -41,7 +41,7 @@ def add_textequiv(parent, text=''): unireg = ET.SubElement(textequiv, 'Unicode') unireg.text = text -def xml_reading_order(page, order_of_texts, id_of_texts, id_of_marginalia): +def xml_reading_order(page, order_of_texts, id_of_marginalia): region_order = ET.SubElement(page, 'ReadingOrder') region_order_sub = ET.SubElement(region_order, 'OrderedGroup') region_order_sub.set('id', "ro357564684568544579089") @@ -49,7 +49,7 @@ def xml_reading_order(page, order_of_texts, id_of_texts, id_of_marginalia): for idx_textregion, _ in enumerate(order_of_texts): name = ET.SubElement(region_order_sub, 'RegionRefIndexed') name.set('index', str(region_counter.get('region'))) - name.set('regionRef', region_counter.region_id(order_of_texts[idx_textregion])) + name.set('regionRef', region_counter.region_id(order_of_texts[idx_textregion] + 1)) region_counter.inc('region') for id_marginal in id_of_marginalia: name = ET.SubElement(region_order_sub, 'RegionRefIndexed') diff --git a/qurator/eynollah/writer.py b/qurator/eynollah/writer.py index 3bd68f2..d643941 100644 --- a/qurator/eynollah/writer.py +++ b/qurator/eynollah/writer.py @@ -142,7 +142,7 @@ class EynollahXmlWriter(): id_of_marginalia = [counter_marginals.next_region_id for _ in found_polygons_marginals] if len(found_polygons_text_region) > 0: - xml_reading_order(page, order_of_texts, id_of_texts, id_of_marginalia) + xml_reading_order(page, order_of_texts, id_of_marginalia) for mm in range(len(found_polygons_text_region)): textregion = ET.SubElement(page, 'TextRegion') @@ -188,7 +188,7 @@ class EynollahXmlWriter(): counter_marginals = EynollahIdCounter(region_idx=len(order_of_texts)) id_of_marginalia = [counter_marginals.next_region_id for _ in found_polygons_marginals] - xml_reading_order(page, order_of_texts, id_of_texts, id_of_marginalia) + xml_reading_order(page, order_of_texts, id_of_marginalia) for mm in range(len(found_polygons_text_region)): textregion=ET.SubElement(page, 'TextRegion')