【问题标题】:Is there any lib for python that will get me the synonyms of a word? [closed]是否有任何用于 python 的库可以让我获得一个单词的同义词? [关闭]
【发布时间】:2010-04-15 13:37:44
【问题描述】:

是否有任何用于 python 的 api/lib 可以让我得到一个单词的同义词?

例如,如果我有“房子”这个词,它将返回“建筑、住所、豪宅等......”

【问题讨论】:

标签: python nlp synonym


【解决方案1】:

NLTK 和 Wordnet 可以提供帮助:例如,this article

from nltk.corpus import wordnet

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

打印:

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

【讨论】:

  • 如果是任意词,你不提前知道它的词性怎么办?
【解决方案2】:

更新:正如@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 获取单词并且有点慢。多线程可能有助于加速它。

【讨论】:

  • 和所有的爬虫一样,它们最终都会死掉。自 2022 年 2 月 10 日起,此解决方案不再有效。
猜你喜欢
  • 1970-01-01
  • 2020-09-11
  • 2022-01-05
  • 2012-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 2011-06-29
相关资源
最近更新 更多