-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdep_creator.py
29 lines (25 loc) · 1.06 KB
/
dep_creator.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
from math import exp
from collections import defaultdict
from mult_holder import MultinomialHolder
class DepCreator:
def __init__(self):
self.mult_holder = MultinomialHolder()
def add_entry(self, sentence):
if len(sentence.split()) == 4:
self.add_root_entry(sentence)
else:
self.add_dep_entry(sentence)
def add_dep_entry(self, sentence):
dep_type, tag1, symbol, tag2, colon, value = sentence.split()
if "left" in dep_type:
self.mult_holder.inc_counts(tag1, (tag2, "left"),
exp(float(value)))
if "right" in dep_type:
self.mult_holder.inc_counts(tag2, (tag1, "right"),
exp(float(value)))
def add_root_entry(self, sentence):
root, tag, colon, value = sentence.split()
self.mult_holder.inc_counts(tag, ("*", "left"),
exp(float(value)))
self.mult_holder.inc_counts(tag, ("*", "right"),
exp(float(value)))