2014-08-29 51 views
2

所以我相對較新,我想要一些幫助。NLTK Wordnet,錯誤排序(wn.langs())

所以我試圖讓nltk中的Wordnet使用Open Multi WordNet。這是頁我來已經展示瞭如何做到這一點http://www.nltk.org/howto/wordnet.html

問題是,當我嘗試sorted(wn.langs())我得到這個錯誤

Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
AttributeError: 'WordNetCorpusReader' object has no attribute 'langs' 

由於我使用python 2.7,我知道它會爲sorted(wn.langs)而不是sorted(wn.langs()),但無論哪種方式都會出現此錯誤。

任何人都可以幫助我嗎?

回答

2

我追查到這一點,我認爲這是一個NLTK版本問題。你有什麼NLTK版本?

如果你開始你的解釋,然後運行

from nltk.corpus import wordnet as wn 
sorted(wn.langs()) 

當我nltk==2.0.4(也使用Python 2.7)下運行這段代碼,我看到了同樣的錯誤,你。所以我檢查了源代碼和langs(self)方法不存在。但是,看最新的stable version on GitHub,你可以看到它在那裏。

假設你正在使用PIP(如果你不是,如果你使用的是Windows go here,並按照「其他說明」),做

pip install --upgrade nltk 

,並應安裝nltk==3.0.0

再次運行該代碼,您應該看到

>>> sorted(wn.langs()) 
[u'als', u'arb', u'cat', u'cmn', u'dan', u'eng', u'eus', u'fas', u'fin', u'fra', u'fre', u'glg', u'heb', u'ind', u'ita', u'jpn', u'nno', u'nob', u'pol', u'por', u'spa', u'tha', u'zsm'] 
+0

謝謝!有效 :) – Nolohice 2014-09-27 15:09:34