AttributeError: 'tuple' object has no attribute 'lower' sentiword
AttributeError: 'tuple' object has no attribute 'lower' sentiword
我尝试使用此代码使用 sentiword 计算情绪,我尝试了标记化和 pos 标记,但当我尝试此操作时,我收到错误消息
print("Array..............\n\n")
tagged=np.array(df['tagged_texts'])
print(tagged)
pos=neg=obj=count=0
for word, tag in tagged:
ss_set = None
if 'NN' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
elif 'VB' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
elif 'JJ' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
elif 'RB' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
if ss_set:
pos=pos+synset.pos_score()
neg=neg+synset.neg_score()
obj=obj+synset.obj_score()
count+=1
我收到错误
Array..............
[list([('no', 'DT'), ('coment', 'NN')])
list([('fast', 'RB'), ('respon', 'NN')]) list([('giood', 'NN')]) ...
list([('excelent', 'NN')]) list([('givemore', 'NN'), ('promo', 'NN')])
list([('thankss', 'NN'), ('gojekkk', 'NN')])]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-45-bb3df6752c85> in <module>
5 for word, tag in tagged:
6 ss_set = None
----> 7 if 'NN' in tag and swn.senti_synsets(word):
8 ss_set = list(swn.senti_synsets(word))[0]
9 elif 'VB' in tag and swn.senti_synsets(word):
~\Anaconda3\lib\site-packages\nltk\corpus\reader\sentiwordnet.py in senti_synsets(self, string, pos)
94
95 sentis = []
---> 96 synset_list = wn.synsets(string, pos)
97 for synset in synset_list:
98 sentis.append(self.senti_synset(synset.name()))
~\Anaconda3\lib\site-packages\nltk\corpus\reader\wordnet.py in synsets(self, lemma, pos, lang, check_exceptions)
1573 of that language will be returned.
1574 """
-> 1575 lemma = lemma.lower()
1576
1577 if lang == 'eng':
AttributeError: 'tuple' 对象没有属性 'lower'
任何人都可以帮助我了解这段代码哪里出错了吗?谢谢
tagged 以元组对列表的形式开始。所以,word 和 tag 都是元组。例如word 和 tag 的第一个值将是
word : ('no', 'DT')
tag : ('coment', 'NN')
也许,试试:
temp = []
for x in tagged:
for y in x:
temp.append(y)
tagged = temp
在 运行 循环之前 - 假设您想在主循环中迭代元组。
我尝试使用此代码使用 sentiword 计算情绪,我尝试了标记化和 pos 标记,但当我尝试此操作时,我收到错误消息
print("Array..............\n\n")
tagged=np.array(df['tagged_texts'])
print(tagged)
pos=neg=obj=count=0
for word, tag in tagged:
ss_set = None
if 'NN' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
elif 'VB' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
elif 'JJ' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
elif 'RB' in tag and swn.senti_synsets(word):
ss_set = list(swn.senti_synsets(word))[0]
if ss_set:
pos=pos+synset.pos_score()
neg=neg+synset.neg_score()
obj=obj+synset.obj_score()
count+=1
我收到错误
Array..............
[list([('no', 'DT'), ('coment', 'NN')])
list([('fast', 'RB'), ('respon', 'NN')]) list([('giood', 'NN')]) ...
list([('excelent', 'NN')]) list([('givemore', 'NN'), ('promo', 'NN')])
list([('thankss', 'NN'), ('gojekkk', 'NN')])]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-45-bb3df6752c85> in <module>
5 for word, tag in tagged:
6 ss_set = None
----> 7 if 'NN' in tag and swn.senti_synsets(word):
8 ss_set = list(swn.senti_synsets(word))[0]
9 elif 'VB' in tag and swn.senti_synsets(word):
~\Anaconda3\lib\site-packages\nltk\corpus\reader\sentiwordnet.py in senti_synsets(self, string, pos)
94
95 sentis = []
---> 96 synset_list = wn.synsets(string, pos)
97 for synset in synset_list:
98 sentis.append(self.senti_synset(synset.name()))
~\Anaconda3\lib\site-packages\nltk\corpus\reader\wordnet.py in synsets(self, lemma, pos, lang, check_exceptions)
1573 of that language will be returned.
1574 """
-> 1575 lemma = lemma.lower()
1576
1577 if lang == 'eng':
AttributeError: 'tuple' 对象没有属性 'lower'
任何人都可以帮助我了解这段代码哪里出错了吗?谢谢
tagged 以元组对列表的形式开始。所以,word 和 tag 都是元组。例如word 和 tag 的第一个值将是
word : ('no', 'DT')
tag : ('coment', 'NN')
也许,试试:
temp = []
for x in tagged:
for y in x:
temp.append(y)
tagged = temp
在 运行 循环之前 - 假设您想在主循环中迭代元组。