本文介紹了AttributeError:“FreqDist"對象沒有屬性“inc"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我是 Python 和 NLTK 的初學者.我正在嘗試從教程中運行以下代碼:
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'
知道我做錯了什么嗎?
推薦答案
你應該這樣做:
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"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!