Sentiment分析app评论情感

前言

SentiStrength软件作为情感分析常用的程序应用能自动情绪分析每秒最多16,000个社交网络文本,英语水平准确度达到最高 - 其他语言可用或轻松添加。这篇文章作为Sentiment使用说明文档入门,方便大家使用。
SentiStrength报告了两种情绪优势:

-1(非负)到-5(非常负)

1(非正)至5(非常积极)

实验操作

  • 下载

    • 直接输入邮件下载即可,最后得到Sentiment.jar包、Sentiment_Data(包含程序需要的文本数据)
  • 运行测试

    • 通过命令窗口输入
     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
    

    输出文件 4	-3,结果为(4 -3)

    • 如果还想知道评分中的情感词的情绪分,或者句子的情感分怎么计算出来的加个explain
       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("+","")+"}")

在这里插入图片描述
这里是加了explain之后的结果,去掉只输出情感分。

你可能感兴趣的:(python,nlp)