-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_fixtures.py
executable file
·61 lines (46 loc) · 1.66 KB
/
create_fixtures.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
''' This script reads the data collected by us and organized by Coleen at SRI and generates a Django fixture for the annotation app '''
import json
import os.path as pt
import codecs
#from annotations.models import ARAnnotation, ENAnnotation
en_path = '/home/enoriega/UnivAriz-2/P3Testing_UnivAriz-2.en.hyps'
ar_path = '/home/enoriega/UnivAriz-2/P3Testing_UnivAriz-2.ia.hyps'
ar_fixture = 'ia_fixture.json'
en_fixture = 'en_fixture.json'
def parse_hyps(path, lang, model, pk = 1):
elements = []
with codecs.open(path, 'r', encoding='utf_8') as f:
for line in f:
tokens = line.split(' ', 1) # Split only two tokens
id = tokens[0]
hyp = tokens[1][:-1]
item = {
'pk': pk,
'model':'transcriptions.annotation',
"fields":{
'audio': pt.join(lang, id+'.wav'),
'sentence_id':id,
'hyp': hyp,
'trans':hyp,
'annotated':False,
'skipped':False,
}
}
elements.append(item)
item = {
'pk': pk,
'model':model,
"fields":{
}
}
elements.append(item)
pk += 1
return elements, pk
# First deal with english
en, pk = parse_hyps(en_path, 'en', 'transcriptions.enannotation')
# Now with arabic
ar, pk = parse_hyps(ar_path, 'ia', 'transcriptions.arannotation', pk=pk)
with codecs.open(ar_fixture, 'w', encoding='utf_8') as f:
json.dump(ar, f)
with codecs.open(en_fixture, 'w', encoding='utf_8') as f:
json.dump(en, f)