示例#1
0
 def test_calculate_log_probabilities_ideal(self):
     ngram = NGramTrie(2)
     ngram.gram_frequencies = {(1, 2): 10, (1, 3): 2, (2, 5): 5}
     first_prob = math.log(10 / 12)
     second_prob = math.log(2 / 12)
     ngram.calculate_log_probabilities()
     self.assertEqual(ngram.gram_log_probabilities[(1, 2)], first_prob)
     self.assertEqual(ngram.gram_log_probabilities[(1, 3)], second_prob)
示例#2
0
 def test_calculate_log_probabilities_empty(self):
     ngram = NGramTrie(2)
     ngram.gram_frequencies = {}
     ngram.calculate_log_probabilities()
     self.assertEqual(ngram.gram_log_probabilities, {})
示例#3
0
 def test_calculate_log_probabilities_one_bi_gram(self):
     ngram = NGramTrie(2)
     ngram.gram_frequencies = {(1, 2): 10}
     ngram.calculate_log_probabilities()
     self.assertEqual(ngram.gram_log_probabilities[(1, 2)], 0.0)