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

后端 未结 4 1256
鱼传尺愫
鱼传尺愫 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

    Latest version of nltk doesn't have inc. Rather I used update.

    from nltk.corpus import gutenberg
    from nltk import FreqDist
    
    fd = FreqDist()
    
    for word in gutenberg.words('austen-sense.txt'):
        fd.update([word])
    

    The update takes iterable item. So make sure you are passing iterable item in update function.

提交回复
热议问题