2011-07-12 50 views
4

我想導入wordnet字典,但是當我輸入字典形式wordnet我看到這個錯誤:導入共發現在NLTK

for l in open(WNSEARCHDIR+'/lexnames').readlines(): 
IOError: [Errno 2] No such file or directory: 'C:\\Program Files\\WordNet\\2.0\\dict/lexnames' 

我安裝wordnet2.1此目錄中,但我不能導入 請幫我解決這個問題

import nltk 
from nltk import * 
from nltk.corpus import wordnet 
from wordnet import Dictionary 

print '-----------------------------------------' 
print Dictionary.length 

回答

15

對我來說,以下工作:

>>> nltk.download() 
# Download window opens, fetch wordnet 
>>> from nltk.corpus import wordnet as wn 

現在我有一個WordNetCorpusReaderwn。我不知道你爲什麼要找Dictionary班,因爲docs沒有列出這樣的班級。 NLTK書籍section 2.5解釋了你可以用nltk.corpus.wordnet模塊做什麼。

+0

感謝您的回答 –

+5

nltk.download('wordnet')'也可以工作=) – alvas

+0

@alvas的版本爲我使用Jupyter notebook,python 3.5工作。 'ntlk.download()'本身無法從筆記本內部打開GUI。如果此命令的幫助在列出用於所有選項的正確字符串方面做得更好,那肯定會很好。 – szeitlin