我有一个包含不同文本的数组。其中一些有重复的形容词。现在我想从中创建一个数组,它包含真值,1 = 文本包含重复的形容词,0 = 文本不包含重复的形容词。这是我的文本示例:
text = (['When someone who is extremely selfish dramatically
wonders why people are so selfish !', 'I asked God to
protect me from my enemies .. shortly after I started losing friends'])
到目前为止,我尝试使用 wordnet 获取单词的类型
from nltk.corpus import wordnet as wn
my_list = []
for synset in list(wn.all_synsets('a')):
my_list.append(synset)
my_list
truth_values = []
for sentence in text:
for word in sentence:
if word in my_list:
truth_values.append(1)
from nltk.corpus import wordnet as wn
这段代码给了我以下错误:
'str' object has no attribute '_name'
对于重复的条件,我想像这样的计数器
if counter >=1:
truth_value.append(1)
MMTTMM
LEATH
相关分类