2014-09-13 35 views
10

मैं पायथन और एनएलटीके में एक नौसिखिया हूं।विशेषता त्रुटि: 'FreqDist' ऑब्जेक्ट में कोई विशेषता नहीं है 'inc'

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

किसी भी विचार मैं गलत क्या कर रहा हूँ: अगर मैं इस मैं निम्नलिखित त्रुटि मिलती है चलाने

from nltk.corpus import gutenberg 
from nltk import FreqDist 

fd = FreqDist() 

for word in gutenberg.words('austen-sense.txt'): 
    fd.inc(word) 

: मैं एक ट्यूटोरियल से निम्नलिखित कोड को चलाने के लिए कोशिश कर रहा हूँ?

उत्तर

15

तुम इतनी है कि यह करना चाहिए:

fd[word] += 1 

लेकिन आमतौर पर FreqDist इस तरह प्रयोग किया जाता है:

fd = FreqDist(my_text) 

भी उदाहरण यहाँ देखें:

http://www.nltk.org/book/ch01.html

+0

धन्यवाद .... यह काम किया। – user2763487

+0

एक विकी पेज है, https://github.com/nltk/nltk/wiki/Porting-your-code-to-NLTK-3.0, इंटरफ़ेस परिवर्तनों को सूचीबद्ध करना – user799188

3

कुछ सुविधाओं को हटा दिया गया है।

प्रश्न में कोड संस्करण nltk पर काम 2.0.4

https://pypi.python.org/pypi/nltk/2.0.4

संस्करण को स्थापित करने 2.0.4 का पालन करता है:

wget https://pypi.python.org/packages/source/n/nltk/nltk-2.0.4.zip#md5=cbd04d8635f1358a69a38c4774be029c

7z x nltk-2.0.4.zip

cd nltk-2.0.4/

python setup.py install

कौन सा संस्करण रन निम्नलिखित स्थापित किया गया है देखने के लिए:

pip search nltk

enter image description here

0

nltk का नवीनतम संस्करण inc नहीं है। इसके बजाय मैंने अद्यतन का उपयोग किया।

from nltk.corpus import gutenberg 
from nltk import FreqDist 

fd = FreqDist() 

for word in gutenberg.words('austen-sense.txt'): 
    fd.update([word]) 

अद्यतन पुन: प्रयोज्य आइटम लेता है। तो सुनिश्चित करें कि आप अपडेट फ़ंक्शन में पुन: प्रयोज्य आइटम पास कर रहे हैं।

1

कैसे NLTK 3.0 पुस्तक उदाहरण बदलने के लिए तलाश कर रहे लोगों के लिए:

import nltk 
from nltk.corpus import brown 

suffix_fdist = nltk.FreqDist() 
for word in brown.words(): 
    word = word.lower() 
    suffix_fdist[word[-1:]] +=1 
    suffix_fdist[word[-2:]] +=1 
    suffix_fdist[word[-3:]] +=1 
common_suffixes = [] 
for suffix in suffix_fdist.most_common(100): 
    common_suffixes.append(str(suffix.__getitem__(0))) 
print common_suffixes 
संबंधित मुद्दे

 संबंधित मुद्दे