From b77ca5914f114978921ce22fd65a1c8a560f04d8 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Wed, 10 Jun 2020 11:48:58 +0200 Subject: [PATCH] Set relative file paths in hocr --- ocr | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ocr b/ocr index 73b24eb..b261a96 100755 --- a/ocr +++ b/ocr @@ -256,6 +256,19 @@ class OCRPipeline(WorkflowRunner): os.listdir(input_dir)) files.sort(key=lambda x: int(re.search(r'\d+', x).group(0))) files = map(lambda x: os.path.join(input_dir, x), files) + # set relative file paths into hocr + relative_files = map(lambda x: os.path.join('..', + 'tiff', + os.path.basename(x).replace('.hocr', '.tif')), # noqa + files) + for file, relative_file in zip(files, relative_files): + with open(file, 'r+') as f: + html = f.read() + html = html.replace(file.replace('.hocr', '.tif'), + relative_file) + f.seek(0) + f.truncate(0) # deletes content of file to write new html + f.write(html) output_path_base = os.path.join(job.output_dir, 'PoCo') output_path = os.path.join(output_path_base, 'hocr') cmd = 'cp "{}" "{}"'.format('" "'.join(files), output_path) @@ -398,7 +411,6 @@ class OCRPipeline(WorkflowRunner): zip_jobs.append(self.addTask(command=cmd, dependencies=deps, label=lbl)) # zip PoCo files - # TODO: Fix relative paths before? poco_paths = [] poco_names = [] for i, job in enumerate(self.jobs):