AttributeError的:“FreqDist'对象有没有属性”INC“ [英] AttributeError: 'FreqDist' object has no attribute 'inc'
本文介绍了AttributeError的:“FreqDist'对象有没有属性”INC“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Python和NLTK初学者。我试图运行教程以下code:
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?
推荐答案
您应该这样做像这样:
fd[word] += 1
但通常FreqDist使用这样的:
But usually FreqDist is used like this:
fd = FreqDist(my_text)
也期待在这里的例子:
Also look at the examples here:
http://www.nltk.org/book/ch01.html
这篇关于AttributeError的:“FreqDist'对象有没有属性”INC“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文