简体   繁体   English

将字符串列表转换为同义词集列表

[英]Convert list of string to list of synsets

Convert List of String to List of objects of type synset. 将字符串列表转换为类型为synset的对象列表。

I have tried to split and add but was not able to type cast it to sysnet type. 我试图拆分和添加,但是无法将其类型转换为sysnet类型。

    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() 您可以使用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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