Correct order for output files.

This commit is contained in:
Patrick Jentsch
2019-05-13 15:03:43 +02:00
parent 937abb8c8d
commit 843151e547
3 changed files with 174 additions and 80 deletions

View File

@ -7,22 +7,31 @@ import os
import re
import sys
input_files = filter(lambda x: x.endswith(".hocr"), sorted(os.listdir(sys.argv[1])))
input_files = sorted(
filter(
lambda x: x.endswith(".hocr"),
os.listdir(sys.argv[1])
),
key=lambda x: int(re.search(r'\d+', x).group(0))
)
# "page-1.hocr" -> "1"
output_file = open(sys.argv[2], "w")
output_file.write('<?xml version="1.0" encoding="UTF-8"?>\n' +
'<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="dtabf">\n' +
' <teiHeader>\n' +
' <fileDesc>\n' +
' <titleStmt/>\n' +
' <publicationStmt/>\n' +
' <sourceDesc/>\n' +
' </fileDesc>\n' +
' <encodingDesc/>\n' +
' <profileDesc/>\n' +
' </teiHeader>\n' +
' <text>\n' +
' <body>\n')
output_file.write(
'<?xml version="1.0" encoding="UTF-8"?>\n'
+ '<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="dtabf">\n'
+ ' <teiHeader>\n'
+ ' <fileDesc>\n'
+ ' <titleStmt/>\n'
+ ' <publicationStmt/>\n'
+ ' <sourceDesc/>\n'
+ ' </fileDesc>\n'
+ ' <encodingDesc/>\n'
+ ' <profileDesc/>\n'
+ ' </teiHeader>\n'
+ ' <text>\n'
+ ' <body>\n'
)
for input_file in input_files:
tree = ET.parse(os.path.join(sys.argv[1], input_file))
@ -40,7 +49,9 @@ for input_file in input_files:
output_file.write('<lb/>\n')
output_file.write(' </p>\n')
output_file.write(' </body>\n' +
' </text>\n' +
'</TEI>')
output_file.write(
' </body>\n'
+ ' </text>\n'
+ '</TEI>')
output_file.close()