Wordnet 的属性错误:属性错误:模块 'nltk_data.corpora.wordnet' 没有属性 'synset'



'看看能否打印引理dog的所有同义词集定义'

因此,对于这个练习,我被告知运行代码并下载nltk,然后查找引理'dog '的所有语法集定义。

下载运行,并显示'true ',因此,nltk已下载。

然而,当我想从nltk_data. net导入wordnet时。语料库(nltk文件夹语料库),我可以导入它,但属性'synset'从wordnet字典输出:AttributeError。

我怎样才能得到引理'dog'的同义词集的输出?

## help found on https://www.nltk.org/howto/wordnet.html
import nltk_data
from nltk_data.corpora import wordnet as wn
dog = wn.synset('dog.n.01')

代码错误图片,查看完整练习说明

  1. 如果您想要所有单词"dog"的语法集,请使用wn.synsets([word])代替wn。同义词集(wn名称)。
  2. 与其将输出赋值给一个变量,不如直接让输出到stdout。这样你可以看到你所拥有的。如果您想要一些有趣的展开,可以使用define ()"功能是可爱的。(我喜欢#0是狗,#1是女人,#2是男人。:))

wn.synsets(狗)

[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]

[syn.definition() for syn in wn.synsets('dog')]

['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', 'a dull unattractive unpleasant girl or woman', 'informal term for a man', 'someone who is morally reprehensible', 'a smooth-textured sausage of minced beef or pork usually smoked; often served on a bread roll', 'a hinged catch that fits into a notch of a ratchet to move a wheel forward or prevent it from moving backward', 'metal supports for logs in a fireplace', 'go after with the intent to catch']

最新更新