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 = FreqDist()
for word in gutenberg.words('austen-sense.txt'):
fd.inc(word)
If I run this I get the following error:
AttributeError: 'FreqDist' object has no attribute 'inc'
Any idea what I am doing wrong?
You should do it like so:
fd[word] += 1
But usually FreqDist is used like this:
fd = FreqDist(my_text)
Also look at the examples here:
http://www.nltk.org/book/ch01.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With