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)
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)
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)
def test_calculate_log_probabilities_empty(self): ngram = NGramTrie(2) ngram.gram_frequencies = {} ngram.calculate_log_probabilities() self.assertEqual(ngram.gram_log_probabilities, {})
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)