Differnt Nltk, wordnet hypernym output needed

646 Views Asked by At

When I try to print the hypernym, I just want the word rather the all the information about the word.

pp = wn.synset('grow.v.01')
pp1= pp.hypernyms()
print pp1

My output is [Synset('change.v.02')]. I just want "change". What change do i need to do? Sorry I am new to wordnet.

1

There are 1 best solutions below

2
On

You can use the lemma_names function of the Synset object. Bear in mind it returns list of names, you can pick the one you are happy with (in this case its only 1 result 'change').

>> print(pp1[0].lemma_names())
['change']

Also calling hypernyms() also returns you a list, thus I used pp1[0]. For example querying for 'dog' returns [dog, frump, cad...] etc.. If you want to get all lemma_names for all hypernyms, you can use a list comprehension.

>> [s.lemma_names() for s in wn.synsets('dog')]
[['dog', 'domestic_dog', 'Canis_familiaris'],
 ['frump', 'dog'],
 ['dog'],
 ...
 ['chase', 'chase_after', 'trail', 'tail', 'tag', 'give_chase', 'dog', 'go_after',  'track']]