getting the word from Lemmas

20 views
Skip to first unread message

Ambarish Jash

unread,
Nov 7, 2012, 9:44:31 PM11/7/12
to nltk-...@googlegroups.com
I am trying to find antonyms. I have been mostly successful at it except that at the last stage I am getting the following output

[Lemma('ahistorical.a.01.ahistorical')]

[Lemma('synchronic.a.02.synchronic')]


ahistorical ans synchronic are the correct antonyms. How do I get them out from such a data structure?


--
Ambarish Jash

Steve Vogel

unread,
Nov 8, 2012, 7:14:43 PM11/8/12
to nltk-...@googlegroups.com
Ambarish,

Try using the "name" attribute for the Lemma.  As in your_lemma.name

For example:

#######

from nltk.corpus import wordnet as wn

my_synset_list = wn.synsets('historical')
first_synset = my_synset_list[0]
my_lemma_list = first_synset.lemmas
first_lemma = my_lemma_list[0]
my_antonym_list = first_lemma.antonyms()
first_antonym = my_antonym_list[0]
antonym_name = first_antonym.name

print "my_synset_list = ", my_synset_list
print "first_synset = ", first_synset
print "my_lemma_list = ", my_lemma_list
print "first_lemma = ", first_lemma
print "my_antonym_list = ", my_antonym_list
print "first_antonym = ", first_antonym
print "antonym_name = ", antonym_name

#######

which yields:

my_synset_list =  [Synset('historical.a.01'), Synset('historical.s.02'), Synset('historic.s.01'), Synset('diachronic.a.01')]
first_synset =  Synset('historical.a.01')
my_lemma_list =  [Lemma('historical.a.01.historical')]
first_lemma =  Lemma('historical.a.01.historical')
my_antonym_list =  [Lemma('ahistorical.a.01.ahistorical')]
first_antonym =  Lemma('ahistorical.a.01.ahistorical')
antonym_name =  ahistorical

Reply all
Reply to author
Forward
0 new messages