mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr.git
synced 2025-07-01 19:00:34 +00:00
Correct order for output files.
This commit is contained in:
45
hocrtotei
45
hocrtotei
@ -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()
|
||||
|
Reference in New Issue
Block a user