问题描述
VADER功能
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyser = SentimentIntensityAnalyzer()
def vader(item):
return analyser.polarity_scores(item)['compound']
def sentiment1(attribute):
if attributes[0] in attribute:
idx = attribute.index(attributes[0])
try:
three_before = attribute[idx-3:idx]
except IndexError:
three_before = attribute[:idx]
try:
three_after = attribute[idx:idx+3]
except IndexError:
three_after = attribute[idx:]
three_before.append(attributes[0])
three_before.extend(three_after)
return vader(' '.join(three_before))
def sentiment1(item):
if attributes[0] in item:
att_index = item.index(attributes[0])
lower_bound = max(att_index - 2,0)
upper_bound = min(att_index + 2,len(item))
text = item[lower_bound:upper_bound]
return vader(' '.join(text))
而且,他们都在引用此归因列表。
attributes = ['head','beer','taste']
第二个定义块看似输出正确的值,而第一个定义块在映射到一系列列表时未输出。第二个定义做什么而第一个没有呢?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)