13

Is there any api/lib for python that will get me the synonyms of a word?

For example if i have the word "house" it will return "building, domicile, mansion, etc..."

SilentGhost
  • 287,765
  • 61
  • 300
  • 288
daniels
  • 17,788
  • 30
  • 99
  • 168
  • 1
    Related: https://stackoverflow.com/questions/19258652/how-to-get-synonyms-from-nltk-wordnet-python/67401089#67401089 – Pikamander2 May 05 '21 at 12:21

2 Answers2

18

NLTK and Wordnet can help: e.g., per this article,

from nltk.corpus import wordnet

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

prints:

['dog', 'domestic_dog', 'Canis_familiaris']
user
  • 5,119
  • 7
  • 45
  • 62
Alex Martelli
  • 811,175
  • 162
  • 1,198
  • 1,373
4

Update: as @deweydb has pointed out, as of Feb 10th 2022, this solution no longer works.

You can also use PyDictionary

For example,

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

The output is

[u'great', u'satisfying', u'exceptional', u'positive', u'acceptable']

This is actually fetching words from www.thesaurus.com and is a little slow. Multi-threading may help accelerate it.

Zhu Li
  • 505
  • 5
  • 15
  • 1
    As with all scrapers, eventually they die. As of Feb 10th 2022, this solution no longer works. – deweydb Feb 10 '22 at 19:09