Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'inc' object with NLTK for py 2.7

I have only just downloaded nltk this morning and have already run into a reoccurring problem with my code.

I get,

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

I had the same error with this code,

for word in gutenberg.words(’austen-persuasion.txt’):
    fd.inc(word)

but simply changed it to

fd[word] += 1

However, where do I go when faced with the below code?

for word in gutenberg.words(u'austen-persuasion.txt'):
    cfd[prev_word].inc(word)
    prev_word = word
like image 771
grove park Avatar asked Dec 14 '25 18:12

grove park


1 Answers

It's a nested FreqDist. Try changing

    cfd[prev_word].inc(word)

to

    cfd[prev_word][word] += 1
like image 84
lenz Avatar answered Dec 16 '25 23:12

lenz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!