Convert list of string to list of synsets

620 Views Asked by At

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

There are 2 best solutions below

0
On BEST ANSWER

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)
6
On

How about

from nltk.corpus import wordnet as wn

words = ['dog','cat']
wn_words = [wn.synsets(word) for word in words]