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
  • 307,395
  • 66
  • 306
  • 293
daniels
  • 18,416
  • 31
  • 103
  • 173
  • 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

19

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,335
  • 7
  • 47
  • 63
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
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
  • 585
  • 6
  • 18
  • 3
    As with all scrapers, eventually they die. As of Feb 10th 2022, this solution no longer works. – deweydb Feb 10 '22 at 19:09