本文介绍了使用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')

我无法在代码中查明导致实际输出与预期输出之间存在差异的错误.

I am unable to pinpoint the error in my code which is causing the difference between the actual output and the expected output.

推荐答案

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

It's because Synset object properties has been changed to Synset functions, see https://github.com/nltk/nltk/commit/ba8ab7e23ea2b8d61029484098fd62d5986acd9c

这篇关于使用Wordnet Synset的定义方法未获得所需的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 05:42