AttributeError: 'FreqDist' object has no attribute 'inc'

后端 未结 4 1250
鱼传尺愫
鱼传尺愫 2021-01-17 11:19

I am a beginner in Python and NLTK. I am trying to run the following code from a tutorial:

from nltk.corpus import gutenberg
from nltk import FreqDist

fd =          


        
4条回答
  •  伪装坚强ぢ
    2021-01-17 11:52

    For people looking for how to change the book example to NLTK 3.0:

    import nltk
    from nltk.corpus import brown
    
    suffix_fdist = nltk.FreqDist()
    for word in brown.words():
        word = word.lower()
        suffix_fdist[word[-1:]] +=1
        suffix_fdist[word[-2:]] +=1
        suffix_fdist[word[-3:]] +=1
    common_suffixes = []
    for suffix in suffix_fdist.most_common(100):
        common_suffixes.append(str(suffix.__getitem__(0)))
    print common_suffixes
    

提交回复
热议问题