这是我的代码:
from nltk import wordnet
synonyms=wordnet.synsets("dog")
它返回以下错误消息:
AttributeError: 'module' object has no attribute 'synset'
答案 0 :(得分:3)
这是正确的import语句:
from nltk.corpus import wordnet
您还可能需要在Python提示符中运行以下命令:
import nltk
nltk.download()
答案 1 :(得分:0)
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')]