Пример #1
0
    def test_get_ngrams_frequencies_from_sentence_none(self):
        ngram = NGramTrie(2)
        sentences = None
        ngram.fill_n_grams(sentences)

        expected = {}
        actual = ngram.calculate_n_grams_frequencies()
        self.assertEqual(expected, ngram.n_gram_frequencies)
        self.assertEqual(1, actual)
Пример #2
0
    def test_calculate_n_grams_frequencies_duplcicates_ideal(self):
        ngram = NGramTrie(2)
        sentences = (((1, 2, 1, 2, 1, 2), (1, 2)), )
        ngram.fill_n_grams(sentences)

        expected = {(1, 2): 4, (2, 1): 2}
        actual = ngram.calculate_n_grams_frequencies()
        self.assertEqual(expected, ngram.n_gram_frequencies)
        self.assertEqual(0, actual)
Пример #3
0
    def test_calculate_n_grams_frequencies_empty(self):
        ngram = NGramTrie(2)
        sentences = ()
        ngram.fill_n_grams(sentences)

        expected = {}
        actual = ngram.calculate_n_grams_frequencies()
        self.assertEqual(expected, ngram.n_gram_frequencies)
        self.assertEqual(1, actual)
Пример #4
0
    def test_calculate_n_grams_frequencies_ideal(self):
        ngram = NGramTrie(2)
        sentences = (((1, 2, 3, 4, 5), ), )
        ngram.fill_n_grams(sentences)

        expected = {(1, 2): 1, (2, 3): 1, (3, 4): 1, (4, 5): 1}
        actual = ngram.calculate_n_grams_frequencies()
        self.assertEqual(expected, ngram.n_gram_frequencies)
        self.assertEqual(0, actual)