from nltk.corpus import wordnet
syn=wordnet.synsets('cookbook')[0]
print syn.definition
预期产出:
'a book of recipes and cooking directions'
实际输出:
bound method Synset.definition of Synset('cookbook.n.01')
我无法查明代码中导致实际输出与预期输出之间差异的错误。
答案 0 :(得分:7)
>>> 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 :(得分:0)
您在()
兄弟之后忘记了.definition
。
尝试下面的这一行,它将起作用。
print(wn.synsets('dog')[0].definition())