获取错误Python对象模块合成器不起作用



这是我的代码:

from nltk import wordnet 
synonyms=wordnet.synsets("dog")

它返回以下错误消息:

AttributeError: 'module' object has no attribute 'synset'

这是正确的导入语句:

from nltk.corpus import wordnet

您可能还需要在Python提示中运行以下内容:

import nltk

nltk.download()

from nltk.corpus import wordnet as wn
wn.synset('motorcycle.n.01').definition()
Out[120]: 'a motor vehicle with two wheels and a strong frame'
wn.synset('motorcycle.n.01').lemma_names()
Out[121]: ['motorcycle', 'bike']
wn.synsets('bike')
Out[122]: [Synset('motorcycle.n.01'), Synset('bicycle.n.01'), Synset('bicycle.v.01')]
wn.synsets('motorcar')
Out[123]: [Synset('car.n.01')]

最新更新