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

发布于 2021-01-29 16:14:56

 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
被浏览
47
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。
    >>> 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



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看