예제 #1
0
 def __init__(self, n, observation_sequence=[], default=0):
     # In addition to the dictionary of n-tuples, cond_prob is a
     # mapping from (w1, ..., wn-1) to P(wn | w1, ... wn-1)
     CountingProbDist.__init__(self, default=default)
     self.n = n
     self.cond_prob = defaultdict()
     self.add_sequence(observation_sequence)
예제 #2
0
 def __init__(self, n, observation_sequence=[]):
     ## In addition to the dictionary of n-tuples, cond_prob is a
     ## mapping from (w1, ..., wn-1) to P(wn | w1, ... wn-1)
     CountingProbDist.__init__(self)
     self.n = n
     self.cond_prob = defaultdict(CountingProbDist())
     self.add_sequence(observation_sequence)
예제 #3
0
 def add(self, ngram):
     """Count 1 for P[(w1, ..., wn)] and for P(wn | (w1, ..., wn-1)"""
     CountingProbDist.add(self, ngram)
     self.cond_prob[ngram[:-1]].add(ngram[-1])
예제 #4
0
 def __init__(self, observation_sequence=[], default=0):
     CountingProbDist.__init__(self, default=default)
     self.n = 1
     self.cond_prob = defaultdict()
     self.add_sequence(observation_sequence)
예제 #5
0
 def add_cond_prob(self, ngram):
     """Builds the conditional probabilities P(wn | (w1, ..., wn-1)"""
     if ngram[:-1] not in self.cond_prob:
         self.cond_prob[ngram[:-1]] = CountingProbDist()
     self.cond_prob[ngram[:-1]].add(ngram[-1])
예제 #6
0
 def __init__(self, training_text):
     training_text = canonicalize(training_text)
     self.P2 = CountingProbDist(bigrams(training_text), default=1)
예제 #7
0
 def __init__(self, observation_sequence=[], default=0):
     CountingProbDist.__init__(self, default=default)
     self.n = 1
     self.cond_prob = defaultdict()
     self.add_sequence(observation_sequence)
예제 #8
0
 def add(self, ngram):
     """Count 1 for P[(w1, ..., wn)] and for P(wn | (w1, ..., wn-1)"""
     CountingProbDist.add(self, ngram)
     if ngram[:-1] not in self.cond_prob:
         self.cond_prob[ngram[:-1]] = CountingProbDist()
     self.cond_prob[ngram[:-1]].add(ngram[-1])