-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
executable file
·39 lines (33 loc) · 998 Bytes
/
util.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
import os
import sys
def reverse(dict):
rev_dict = {}
for k, v in dict.items():
rev_dict[v] = k
return rev_dict
def to_str(type, idxs, cont, r_vdict, r_adict, r_exp_vdict):
if type == 'a':
return r_adict[idxs]
elif type == 'q':
words = []
for idx in idxs:
words.append(r_vdict[idx])
start = 0
for i, indicator in enumerate(cont):
if indicator == 1:
start = i
break
start = max(0, start - 1)
words = words[start:]
elif type == 'exp':
words = []
for idx in idxs:
if idx == 0:
break
words.append(r_exp_vdict[idx])
return ' '.join(words)
def batch_to_str(type, batch_idx, batch_cont, r_vdict, r_adict, r_exp_vdict):
converted = []
for idxs, cont in zip(batch_idx, batch_cont):
converted.append(to_str(type, idxs, cont, r_vdict, r_adict, r_exp_vdict))
return converted