输入一个名词以获得另一个具有类似含义的名词。python,nltk

输入一个名词以获得另一个具有类似含义的名词。python,nltk,python,nltk,wordnet,Python,Nltk,Wordnet,输入:名词 输出:名词 例如: 输入:狗,我想得到猫,狼,老虎的输出 或 输入:电脑,我想得到笔记本电脑、平板电脑、手机等的输出 任何人都可以编写一个python代码来实现这一点吗?更喜欢使用NLTK 示例代码: text = nltk.Text(word.lower() for word in nltk.corpus.treebank.words()) y= text.similar('dog') print (y) 更新:找到这个,它工作得更好 from py_thesaurus impo

输入:名词

输出:名词

例如:

输入:狗,我想得到猫,狼,老虎的输出

输入:电脑,我想得到笔记本电脑、平板电脑、手机等的输出

任何人都可以编写一个python代码来实现这一点吗?更喜欢使用NLTK

示例代码:

text = nltk.Text(word.lower() for word in nltk.corpus.treebank.words())
y= text.similar('dog')
print (y)
更新:找到这个,它工作得更好

from py_thesaurus import Thesaurus
thesaurus = Thesaurus('dog')
print(thesaurus.get_synonym())

对于狗,即使我也没有火柴

类似的单词取决于您使用的语料库。现在我使用的语料库和你使用的一样

代码:

输出:


您能发布一段您尝试过的代码吗?您最好编辑您的问题并添加代码there@lee:您在上述代码中面临什么问题?你能说清楚一点吗?我没有火柴或者没有。。只是想知道有没有更好的方法来做这件事?谢谢你的回复。欢迎。你可以照这个做
import nltk

text = nltk.Text(word.lower() for word in nltk.corpus.treebank.words())
text.similar('computer')

similar_words = text._word_context_index.similar_words('computer')
print(similar_words)
industrial insurance research manufacturing market car farm trading
presence stored
['manufacturing', 'industrial', 'insurance', 'research', 'market', 'presence', 'farm', 'trading', 'stored', 'car']