简体   繁体   中英

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

How about

from nltk.corpus import wordnet as wn

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM