-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
36 lines (29 loc) · 902 Bytes
/
utils.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
import pickle
def read_glossary(glossary_file):
glossary = {}
with open(glossary_file, 'r') as glossary_file:
lines = glossary_file.read().split('\n')
lines.remove('')
for line in lines:
f, w = line.strip().split(' ')
glossary[w] = int(f)
return glossary
def read_eval_file(eval_file):
eval_data = {}
with open(eval_file, 'r') as eval_file:
lines = eval_file.read().split('\n')
lines.remove('')
for line in lines:
w, p = line.split('\t')
if w in eval_data:
eval_data[w].append(p)
else:
eval_data[w] = [p]
return eval_data
def save_obj(file, obj):
with open(file, 'wb') as obj_file:
pickle.dump(obj, obj_file)
def load_obj(file):
with open(file, 'rb') as obj_file:
obj = pickle.load(obj_file)
return obj