1

Convert List of String to List of objects of type synset.

I have tried to split and add but was not able to type cast it to sysnet type.

    inp="[Synset<'history.n.02'>,Synset<'long.n.02'>]"

I should get output as

    [Synset<'history.n.02'>,Synset<'long.n.02'>]

such that output should be list of synsets. For understanding synsets

2 Answers2

1

You can use wn.synset()

inp="[Synset<'history.n.02'>,Synset<'long.n.02'>]"
inp=inp[1:-1]
for i in inp.split(','):
    val= i[8:-2]
    print wn.synset(val)
0

How about

from nltk.corpus import wordnet as wn

words = ['dog','cat']
wn_words = [wn.synsets(word) for word in words]
balderman
  • 22,927
  • 7
  • 34
  • 52