有没有适用于Python的库可以获取一个单词的同义词?

13

有没有Python的API或库可以获取单词的同义词?

例如,如果我有单词"house",它将返回"building, domicile, mansion, etc..."。


1
相关链接:https://dev59.com/gmIk5IYBdhLWcg3wdd4l#67401089 - Pikamander2
2个回答

19

NLTK和Wordnet可以帮助:例如,根据这篇文章的描述,

from nltk.corpus import wordnet

dog = wordnet.synset('dog.n.01')
print(dog.lemma_names())

打印:

['dog', 'domestic_dog', 'Canis_familiaris']

2
如果它是任意单词,而且你事先不知道它的词性是什么呢? - Pikamander2

4

更新:如@deweydb指出,截至2022年2月10日,此解决方案已不再有效。

你还可以使用PyDictionary

例如:

from PyDictionary import PyDictionary 
dictionary=PyDictionary() 
print (dictionary.synonym("good"))

输出结果为:
[u'great', u'satisfying', u'exceptional', u'positive', u'acceptable']

这实际上是从www.thesaurus.com获取单词,并且速度较慢。多线程可能有助于加速。


3
像所有网页数据抓取工具一样,它们最终也会失效。截至2022年2月10日,这个解决方案已经无法使用。 - deweydb

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接