SentiStrength软件作为情感分析常用的程序应用能自动情绪分析每秒最多16,000个社交网络文本,英语水平准确度达到最高 - 其他语言可用或轻松添加。这篇文章作为Sentiment使用说明文档入门,方便大家使用。
SentiStrength报告了两种情绪优势:
-1(非负)到-5(非常负)
1(非正)至5(非常积极)
下载
运行测试
C:\Users\user\Desktop> java -jar SentiStrength.jar sentidata ./SentStrength_Data/ text i+like+you.
2 -1
SentiStrenth.jar是SentiStrenth.jar路径地址,./SentStrength_Data/ 是SentStrength_Data文件夹路径,text命令后面可以加需要检测的语句的情感评分。
还可以导入文件检测情感
C:\Users\user\Desktop> java -jar SentiStrength.jar sentidata ./SentStrength_Data/ input myfile.txt
Finished! Results in: myfile1_out.txt
C:\Users\user\Desktop> java -jar SentiStrength.jar sentidata ./SentStrength_Data/ explain text i+like+you.
2 -1 i like[2] you .[sentence: 2,-1] [result: max + and - of any sentence][overall result = 1 as pos>-neg]
python引用 jupyter note操作
#分析每一句评论的情感指数
import subprocess
import shlex
import os
sentiment=[]
sentiString="love this app. great for playing downloading and sharing great quailty music ! "#需要检测的语句
SentiStrengthLocation = "C:/Users/user/Desktop/SentiStrength.jar"#SentiStrength.jar所在的路径
SentiStrengthLanguageFolder = "C:/Users/user/Desktop/SentStrength_Data/"#SentStrength_Data
if not os.path.isfile(SentiStrengthLocation):
print("SentiStrength not found at: ", SentiStrengthLocation)
if not os.path.isdir(SentiStrengthLanguageFolder):
print("SentiStrength data folder not found at: ", SentiStrengthLanguageFolder)
#open a subprocess using shlex to get the command line string into the correct args list format
shlex.split("java -jar '" + SentiStrengthLocation + "' stdin sentidata '" + SentiStrengthLanguageFolder+"'")
p = subprocess.Popen(shlex.split("java -jar '" + SentiStrengthLocation + "' stdin sentidata '" + SentiStrengthLanguageFolder+"' explain'"+"'"),stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
#communicate via stdin the string to be rated. Note that all spaces are replaced with +
b = bytes(sentiString.replace(" ","+"), 'utf-8') #Can't send string in Python 3, must send bytes
stdout_byte, stderr_text = p.communicate(b)
stdout_text = stdout_byte.decode("utf-8") #convert from byte
stdout_text = stdout_text.rstrip().replace("\t"," ")
#remove the tab spacing between the positive and negative ratings. e.g. 1 -5 -> 1 -5
print("{"+stdout_text.replace("+","")+"}")