Пример #1
0
def test_frequency():
    '''Test the frequency method'''
    ngram_freq = NgramFrequencies(1, '')
    ngram_freq.dic_ngram["a"] = 3
    ngram_freq.dic_ngram["c"] = 2
    ngram_freq.dic_ngram["e"] = 6
    ngram_freq.total_count = 11
    new_dic = ngram_freq.frequency()
    assert new_dic["a"] == round(3 / 11, 3)
Пример #2
0
def test_top_n_freqs():
    '''Test the top n reqs method'''
    ngram_freq = NgramFrequencies(1, '')
    ngram_freq.dic_ngram["ab"] = 1
    ngram_freq.dic_ngram["cd"] = 7
    ngram_freq.dic_ngram["ef"] = 12
    ngram_freq.total_count = 20
    list_top_freq = ngram_freq.top_n_freqs(3)
    assert list_top_freq[0][0] == "ef"
    assert list_top_freq[1][0] == "cd"
    assert list_top_freq[2][0] == "ab"