示例#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_frequencies(self):
        ngram = NGramTrie(2)
        ngram.n_gram_frequencies = {}

        actual = ngram.calculate_log_probabilities()
        self.assertEqual(ngram.n_gram_log_probabilities, {})
        self.assertEqual(1, actual)
示例#3
0
    def test_calculate_log_probabilities_one_bi_gram(self):
        ngram = NGramTrie(2)
        ngram.n_gram_frequencies = {(1, 2): 10}

        actual = ngram.calculate_log_probabilities()
        self.assertEqual(ngram.n_gram_log_probabilities[(1, 2)], 0.0)
        self.assertEqual(0, actual)
示例#4
0
 def test_calculate_log_probabilities_empty(self):
     ngram = NGramTrie(2)
     ngram.gram_frequencies = {}
     ngram.calculate_log_probabilities()
     self.assertEqual(ngram.gram_log_probabilities, {})
示例#5
0
 def test_three_gram_calculate_log_probabilities_one_three_gram(self):
     ngram = NGramTrie(3)
     ngram.gram_frequencies = {(1, 2, 3): 10}
     ngram.calculate_log_probabilities()
     self.assertEqual(ngram.gram_log_probabilities[(1, 2, 3)], 0.0)