Skip to content
Snippets Groups Projects
Commit aa7eb15b authored by Alexander Hartelt's avatar Alexander Hartelt
Browse files

removed image extension form xml filename and changed id generation for xml tags

parent 4019e618
Branches
No related tags found
No related merge requests found
import itertools
import os
from typing import Tuple, List
import math
......@@ -67,6 +68,9 @@ class XMLGenerator:
creates the xml to the given baselines
:return: xml-string of baselines
"""
def make_id_gen(identifier):
return map(lambda x: f"{identifier}{x}", itertools.count(start=1))
textline_id_gen = make_id_gen("TextLine")
xmlns_uris = {'pc': 'http://schema.primaresearch.org/PAGE/gts/pagecontent/2017-07-15'}
attr_qname = ET.QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation")
root_node = ET.Element("PcGts", {
......@@ -84,11 +88,9 @@ class XMLGenerator:
ET.SubElement(tr_node, "Coords", points=coords_to_string(t.coords))
for i_ind, i in enumerate(t.textLines):
# ET.SubElement(tr_node, "Coords", points=self.coords_to_string(region.coords))
tl_node = ET.SubElement(tr_node, "TextLine", id="TextLine")
tl_node = ET.SubElement(tr_node, "TextLine", id=next(textline_id_gen))
ET.SubElement(tl_node, "Coords", points=coords_to_string(i.coords))
ET.SubElement(tl_node, "Baseline", points=coords_to_string(i.baseline.coords))
# annotate_with_XMLNS_prefixes(root_node, "pc", False)
return minidom.parseString(ET.tostring(root_node)).toprettyxml(indent=' ')
def save_textregions_as_xml(self, output_path: str):
......@@ -96,7 +98,7 @@ class XMLGenerator:
Transform textregions to xml and save it to output_path
:param output_path:
"""
complete_name = os.path.join(output_path, self.imageFilename + ".xml")
complete_name = os.path.join(output_path, self.imageFilename.split(".")[0] + ".xml") # remove .image extensions from filename
output_string = self.baselines_to_xml_string()
file = open(complete_name, "w")
file.write(output_string)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment