How to programmatically access wordnet hierarchy?

5.2k views Asked by At

Suppose for any word I want to access its IS-A parent value and HAS-A value then is it possible using any api?

3

There are 3 answers

0
Suzana On

You can use the python API of the Natural Language Toolkit. In Wordnet, the IS-A-relation is called hypernym (opposite: hyponym) and the HAS-A relation is called meronym (opposite: holonym).

from nltk.corpus import wordnet
book = wordnet.synsets('book')[0]
book.hypernyms()
>>> [Synset('publication.n.01')]
book.part_meronyms()
>>> [Synset('running_head.n.01'), Synset('signature.n.05')]

I also found the NodeBox Linguistics API easier to use:

import en
en.noun.hypernym('book')
>>> [['publication']]
0
shs On

You can use commandline. The command is "wn book -hypen" to get the hypernyms of the noun book. For meronyms, use the command "wn book -meron". Also the -o option gives the synset offset. Here is the link for further information.

0
Ritwik Bose On

Shameless plug:

I'm writing a Scala library to access WordNet. While not all the similarity measures have been implemented, all the word senses and relations are available. I use it for my research so its in active development.

import com.github.mrmechko.swordnet._

SKey("book",SPos.Noun)
//> List(SKey("publication%1:10:00::"))

SKey("publication%1:10:00::").getRelation(SRelationType.hypernym) //Hypernyms

SKey("publication%1:10:00::").getRelation(SRelationType.hyponym) //Hyponyms etc

SWordNet is available on GitHub and Sonatype