-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharmonic_initalizer_numpy.py
38 lines (34 loc) · 1.54 KB
/
harmonic_initalizer_numpy.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
from dep_initializer_numpy import DepCreator
from stop_cont_initializer_numpy import ContStopCreator
import numpy as np
from pickle_handler import PickleHandler
class HarmonicInitializer:
def __init__(self,harmonic_file_name, root_val_file_name):
self.harmonic_file_name = harmonic_file_name
self.root_val_file_name = root_val_file_name
self.dep_creator = DepCreator()
self.stop_cont_creator = ContStopCreator()
np.seterr(divide='ignore', invalid='ignore')
def sentences(self):
sentences = []
with open(self.harmonic_file_name,"r") as fp:
sentences += fp.readlines()
with open(self.root_val_file_name,"r") as fp:
sentences += fp.readlines()
return sentences
def initialize_harmonic_values(self):
sentences = self.sentences()
for sent in sentences:
if "attach" in sent:
self.dep_creator.add_entry(sent)
if "continue" in sent:
self.stop_cont_creator.add_entry(sent)
if "stop" in sent:
self.stop_cont_creator.add_entry(sent)
if "root" in sent:
self.dep_creator.add_entry(sent)
if __name__ == "__main__":
initializer = HarmonicInitializer("data/harmonic", "data/root_val_file.txt")
initializer.initialize_harmonic_values()
pickle_handler = PickleHandler("data/harmonic_values_numpy")
pickle_handler.write_to_pickle(initializer.dep_creator.prob_attach, initializer.stop_cont_creator.prob_cont, "data/harmonic_values_numpy")