|
3 | 3 | import os.path
|
4 | 4 | import numpy as np
|
5 | 5 |
|
6 |
| -from ocrd_utils import getLogger, concat_padded |
| 6 | +from ocrd_utils import ( |
| 7 | + getLogger, |
| 8 | + make_file_id, |
| 9 | + assert_file_grp_cardinality, |
| 10 | +) |
7 | 11 | from ocrd_modelfactory import page_from_file
|
8 | 12 | from ocrd_models.ocrd_page import (
|
9 | 13 | MetadataItemType,
|
@@ -96,15 +100,12 @@ def process(self):
|
96 | 100 |
|
97 | 101 | Produce a new output file by serialising the resulting hierarchy.
|
98 | 102 | """
|
99 |
| - assert len(self.output_file_grp.split(',')) == 1, \ |
100 |
| - "Expected exactly one output file group, but '%s' has %d" % ( |
101 |
| - self.output_file_grp, len(self.output_file_grp.split(','))) |
| 103 | + assert_file_grp_cardinality(self.input_file_grp, 1) |
| 104 | + assert_file_grp_cardinality(self.output_file_grp, 1) |
102 | 105 |
|
103 | 106 | for (n, input_file) in enumerate(self.input_files):
|
104 | 107 | LOG.info("INPUT FILE %i / %s", n, input_file.pageId or input_file.ID)
|
105 |
| - file_id = input_file.ID.replace(self.input_file_grp, self.output_file_grp) |
106 |
| - if file_id == input_file.ID: |
107 |
| - file_id = concat_padded(self.output_file_grp, n) |
| 108 | + file_id = make_file_id(input_file, self.output_file_grp) |
108 | 109 |
|
109 | 110 | pcgts = page_from_file(self.workspace.download_file(input_file))
|
110 | 111 | page_id = pcgts.pcGtsId or input_file.pageId or input_file.ID # (PageType has no id)
|
@@ -178,9 +179,6 @@ def process(self):
|
178 | 179 | comments=line_xywh['features'] + ',dewarped'))
|
179 | 180 |
|
180 | 181 | # update METS (add the PAGE file):
|
181 |
| - file_id = input_file.ID.replace(self.input_file_grp, self.output_file_grp) |
182 |
| - if file_id == input_file.ID: |
183 |
| - file_id = concat_padded(self.output_file_grp, n) |
184 | 182 | file_path = os.path.join(self.output_file_grp, file_id + '.xml')
|
185 | 183 | out = self.workspace.add_file(
|
186 | 184 | ID=file_id,
|
|
0 commit comments