eliminate id_of_texts from xml_reading_order, fix plus one error

pull/28/head
Konstantin Baierer 4 years ago
parent 6c60d9e90a
commit a3465ca1a0

@ -20,14 +20,14 @@ class EynollahIdCounter():
self._counter[name] = val self._counter[name] = val
def region_id(self, region_idx=None): def region_id(self, region_idx=None):
if not region_idx: if region_idx is None:
region_idx = self._counter['region'] region_idx = self._counter['region']
return REGION_ID_TEMPLATE % region_idx return REGION_ID_TEMPLATE % region_idx
def line_id(self, region_idx=None, line_idx=None): def line_id(self, region_idx=None, line_idx=None):
if not region_idx: if region_idx is None:
region_idx = self._counter['region'] region_idx = self._counter['region']
if not line_idx: if line_idx is None:
line_idx = self._counter['line'] line_idx = self._counter['line']
return LINE_ID_TEMPLATE % (region_idx, line_idx) return LINE_ID_TEMPLATE % (region_idx, line_idx)

@ -41,7 +41,7 @@ def add_textequiv(parent, text=''):
unireg = ET.SubElement(textequiv, 'Unicode') unireg = ET.SubElement(textequiv, 'Unicode')
unireg.text = text 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 = ET.SubElement(page, 'ReadingOrder')
region_order_sub = ET.SubElement(region_order, 'OrderedGroup') region_order_sub = ET.SubElement(region_order, 'OrderedGroup')
region_order_sub.set('id', "ro357564684568544579089") 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): for idx_textregion, _ in enumerate(order_of_texts):
name = ET.SubElement(region_order_sub, 'RegionRefIndexed') name = ET.SubElement(region_order_sub, 'RegionRefIndexed')
name.set('index', str(region_counter.get('region'))) 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') region_counter.inc('region')
for id_marginal in id_of_marginalia: for id_marginal in id_of_marginalia:
name = ET.SubElement(region_order_sub, 'RegionRefIndexed') name = ET.SubElement(region_order_sub, 'RegionRefIndexed')

@ -142,7 +142,7 @@ class EynollahXmlWriter():
id_of_marginalia = [counter_marginals.next_region_id for _ in found_polygons_marginals] id_of_marginalia = [counter_marginals.next_region_id for _ in found_polygons_marginals]
if len(found_polygons_text_region) > 0: 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)): for mm in range(len(found_polygons_text_region)):
textregion = ET.SubElement(page, 'TextRegion') textregion = ET.SubElement(page, 'TextRegion')
@ -188,7 +188,7 @@ class EynollahXmlWriter():
counter_marginals = EynollahIdCounter(region_idx=len(order_of_texts)) counter_marginals = EynollahIdCounter(region_idx=len(order_of_texts))
id_of_marginalia = [counter_marginals.next_region_id for _ in found_polygons_marginals] 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)): for mm in range(len(found_polygons_text_region)):
textregion=ET.SubElement(page, 'TextRegion') textregion=ET.SubElement(page, 'TextRegion')

Loading…
Cancel
Save