pythonnltkwordnetsynset

Convert list of string to list of synsets


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


Solution

  • 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)