2015-01-06 36 views
4
from nltk.corpus import wordnet 
syn=wordnet.synsets('cookbook')[0] 
print syn.definition 

預期輸出:沒有得到使用WORDNET同義詞集的定義方法所需的輸出

'a book of recipes and cooking directions' 

實際輸出:

bound method Synset.definition of Synset('cookbook.n.01') 

我無法找出我的代碼,這是造成的錯誤實際產出與預期產出之間的差異。

回答

5
>>> from nltk.corpus import wordnet as wn 
>>> wn.synsets('dog')[0] 
Synset('dog.n.01') 
>>> wn.synsets('dog')[0].definition 
<bound method Synset.definition of Synset('dog.n.01')> 
>>> wn.synsets('dog')[0].definition() 
u'a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds' 

這是因爲Synset對象屬性已更改爲Synset功能,請參閱https://github.com/nltk/nltk/commit/ba8ab7e23ea2b8d61029484098fd62d5986acd9c

+1

謝謝:)。我瘋狂地瀏覽解決方案。 – APD

相關問題