Object "inc" with NLTK for py 2.7

I just downloaded nltk this morning and already faced the problem of repeating 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 just changed it to

fd[word] += 1

      

However, where can I go when I come across the code below?

for word in gutenberg.words(u'austen-persuasion.txt'):
    cfd[prev_word].inc(word)
    prev_word = word

      

+3


source to share


1 answer


This is a nested FreqDist. Try to change

    cfd[prev_word].inc(word)

      



to

    cfd[prev_word][word] += 1

      

+2


source







All Articles