2

Can you recommend a good Python library to get thesaurus and taxonomy of a given word?

Synonym:

>>> print get_synonym('image')
['picture', 'photo']

Taxonomy:

>>> print get_taxonomy('baseball')
['sports']
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
jack
  • 17,261
  • 37
  • 100
  • 125

2 Answers2

5

pywordnet, now part of NLTK

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

NLTK

Installation

You might need superuser rights for that:

$ pip install nltk

Usage

>>> import nltk
>>> from nltk.corpus import wordnet as wn

>>> wn.synsets('dog')
[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]

>>> wn.synset('dog.n.01').definition()
u'a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds'

>>> wn.synset('dog.n.03').definition()
u'informal term for a man'

>>> baseball = wn.synset('baseball.n.01')
>>> sport = wn.synset('sport.n.01')
>>> picture = wn.synset('picture.n.01')

>>> sport.path_similarity(baseball)
0.16666666666666666

>>> sport.path_similarity(picture)
0.06666666666666667
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958