我目前正在通过命令result = senti.getSentiment(cs, score='binary')
使用SentiStrength python库进行文本分析。首先,我在Jupyter笔记本中运行它,并且效果很好。它输出2个得分,它们分别是正面和负面情绪得分,例如[(2,-1)]
。但是,当我尝试在anaconda提示符或spyder中运行它时。它仅输出1个值,例如[1]
,我不明白为什么。我猜是因为我在不同的环境上运行它。我想问一下如何在anaconda提示符或其他IDE中运行此命令,以便可以正确输出结果?还是我做错了。
if score == 'scale': # Returns from -1 to 1
senti_score = [sum(senti_score[i:i+2])/4 for i in range(0, len(senti_score), 3)]
elif score == 'binary': # Return 1 if positive and -1 if negative
senti_score = [1 if senti_score[i] >= abs(senti_score[i+1]) else -1 for i in range(0, len(senti_score), 3)]
elif score == 'trinary': # Return Positive and Negative Score and Neutral Score
senti_score = [tuple(senti_score[i:i+3]) for i in range(0, len(senti_score), 3)]
elif score == 'dual': # Return Positive and Negative Score
senti_score = [tuple(senti_score[i:i+2]) for i in range(0, len(senti_score), 3)]
else:
return "Argument 'score' takes in either 'scale' (between -1 to 1) or 'binary' (two scores, positive and negative rating)"
return senti_score
遇到相同的问题,看了看源代码,发现文档错误。您应该对分数类型使用“双”。