其他分享
首页 > 其他分享> > 使用Wordnet Synset的定义方法无法获得所需的输出

使用Wordnet Synset的定义方法无法获得所需的输出

作者:互联网

 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')

我无法查明代码中的错误,这会导致实际输出和预期输出之间的差异.

解决方法:

>>> 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

标签:python,nltk,output,owl,wordnet
来源: https://codeday.me/bug/20190612/1223723.html