forked from DDMAL/text_alignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
textAlignment.py
63 lines (53 loc) · 1.81 KB
/
textAlignment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from rodan.jobs.base import RodanTask
import gamera.core as gc
import json
import alignToOCR as align
class textAlignment(RodanTask):
name = 'Text Alignment'
author = 'Timothy de Reuse'
description = 'Given a text layer image and plaintext of some text on that page, finds the'
enabled = True
category = 'text'
interactive = False
settings = {
'title': 'Text Alignment Settings',
'type': 'object',
'required': ['MEI Version'],
'properties': {
'MEI Version': {
'enum': ['4.0.0', '3.9.9'],
'type': 'string',
'default': '3.9.9',
'description': 'Specifies the MEI version, 3.9.9 is the old unofficial MEI standard used by Neon',
},
}
}
input_port_types = [{
'name': 'Text Layer',
'resource_types': ['image/rgba+png'],
'minimum': 1,
'maximum': 1,
'is_list': False
}, {
'name': 'Transcript',
'resource_types': ['text/plain'],
'minimum': 1,
'maximum': 1,
'is_list': False
}]
output_port_types = [{
'name': 'JSON',
'resource_types': ['application/JSON'],
'minimum': 1,
'maximum': 1,
'is_list': False
}]
def run_my_task(self, inputs, settings, outputs):
transcript = align.read_file(inputs['Transcript'][0]['resource_path'])
raw_image = gc.load_image(inputs['Text Layer'][0]['resource_path'])
syl_boxes, _, lines_peak_locs = align.process(raw_image, transcript, wkdir_name='test')
# test_string = str(syl_boxes)
outfile_path = outputs['JSON'][0]['resource_path']
with open(outfile_path, 'w') as file:
json.dump(align.to_JSON_dict(syl_boxes, lines_peak_locs), file)
return True