Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all the hyponyms of a word/synset in python nltk and wordnet?

I have a list of all the nouns in wordnet now i want to leave only words which are vehicles and remove the rest. How do i do it? Below is the pseudo-code i want to make but i do not know how to make it work

for word in wordlist:
  if not "vehicle" in wn.synsets(word):
    wordlist.remove(word)
like image 286
watisit Avatar asked Mar 11 '13 03:03

watisit


People also ask

What is Synset in WordNet?

Synset is a special kind of a simple interface that is present in NLTK to look up words in WordNet. Synset instances are the groupings of synonymous words that express the same concept. Some of the words have only one Synset and some have several.

What does NLTK WordNet do?

WordNet is a lexical database of English. Using synsets, helps find conceptual relationships between words such as hypernyms, hyponyms, synonyms, antonyms etc. An exception class for wordnet-related errors. The lexical entry for a single morphological form of a sense-disambiguated word.

What is WordNet used for?

WordNet is a lexical database of semantic relations between words in more than 200 languages. WordNet links words into semantic relations including synonyms, hyponyms, and meronyms. The synonyms are grouped into synsets with short definitions and usage examples.


1 Answers

from nltk.corpus import wordnet as wn
vehicle = wn.synset('vehicle.n.01')
typesOfVehicles = list(set([w for s in vehicle.closure(lambda s:s.hyponyms()) for w in s.lemma_names()]))

This will give you all the unique words from every synset that is a hyponym of the noun "vehicle" (1st sense).

like image 82
Jared Avatar answered Nov 15 '22 15:11

Jared