Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 294
joydip134 Avatar asked Sep 13 '14 19:09

joydip134


1 Answers

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

like image 82
Rainy Avatar answered Oct 26 '22 21:10

Rainy