Skip to content

Commit

Permalink
revert d96b532 until OCR-D/spec#121 is unresolved
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Jun 8, 2020
1 parent 1411cf1 commit b5aaa3d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Changed:
output file group is targeted but for pages that aren't in that group, #471
* `ocrd_cli_wrap_processor`: Take `page_id` into account when doing `WorkspaceValidator.check_file_grp`
* `run_cli` accepts an `overwrite` parameter to pass on to processor calls, #471
* `Task.validate`: set implicit input/output groups from ocrd-tool.json, #471
* <del>`Task.validate`: set implicit input/output groups from ocrd-tool.json, #471</del> blocked by OCR-D/spec#121
* `ocrd process`: support --overwrite and pass on to processor calls, #471

Added:
Expand Down
25 changes: 14 additions & 11 deletions ocrd/ocrd/task_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,24 @@ def validate(self):
parameters = {}
if self.parameter_path:
parameters = parse_json_string_or_file(self.parameter_path)
# make implicit input/output groups explicit by defaulting to what is
# provided in ocrd-tool.json
# TODO adapt once OCR-D/spec#121 lands
actual_output_grps = [*self.ocrd_tool_json['output_file_grp']]
for i, grp in enumerate(self.output_file_grps):
actual_output_grps[i] = grp
self.output_file_grps = actual_output_grps
actual_input_grps = [*self.ocrd_tool_json['input_file_grp']]
for i, grp in enumerate(self.input_file_grps):
actual_input_grps[i] = grp
self.input_file_grps = actual_input_grps
# TODO uncomment and adapt once OCR-D/spec#121 lands
# # make implicit input/output groups explicit by defaulting to what is
# # provided in ocrd-tool.json
# actual_output_grps = [*self.ocrd_tool_json['output_file_grp']]
# for i, grp in enumerate(self.output_file_grps):
# actual_output_grps[i] = grp
# self.output_file_grps = actual_output_grps
# actual_input_grps = [*self.ocrd_tool_json['input_file_grp']]
# for i, grp in enumerate(self.input_file_grps):
# actual_input_grps[i] = grp
# self.input_file_grps = actual_input_grps
param_validator = ParameterValidator(self.ocrd_tool_json)
report = param_validator.validate(parameters)
if not report.is_valid:
raise Exception(report.errors)
# TODO remove once OCR-D/spec#121 lands
if 'output_file_grp' in self.ocrd_tool_json and not self.output_file_grps:
raise Exception("Processor requires output_file_grp but none was provided.")
return report

def __str__(self):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_task_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ def test_parse_no_in(self):
def test_parse_implicit_after_validate(self):
task = ProcessorTask.parse('%s -I IN -O OUT -p \'{"param1": true}\'' % SAMPLE_NAME_REQUIRED_PARAM)
task.validate()
self.assertEqual(task.input_file_grps, ['IN', 'SECOND_IN'])
self.assertEqual(task.output_file_grps, ['OUT', 'SECOND_OUT'])
# TODO uncomment and adapt once OCR-D/spec#121 lands
# self.assertEqual(task.input_file_grps, ['IN', 'SECOND_IN'])
# self.assertEqual(task.output_file_grps, ['OUT', 'SECOND_OUT'])
self.assertEqual(task.input_file_grps, ['IN'])
self.assertEqual(task.output_file_grps, ['OUT'])

def test_parse_unknown(self):
with self.assertRaisesRegex(Exception, 'Failed parsing task description'):
Expand Down

0 comments on commit b5aaa3d

Please sign in to comment.