标签: sentiment-analysis

如何使用SentiWordNet

我需要对包含推文的一些csv文件进行情绪分析.我正在使用SentiWordNet进行情绪分析.

我得到了他们在他们的网站上提供的以下示例Java代码.我不确定如何使用它.我要分析的csv文件的路径是C:\Users\MyName\Desktop\tweets.csv.路径SentiWordNet_3.0.0.txtC:\Users\MyName\Desktop\SentiWordNet_3.0.0\home\swn\www\admin\dump\SentiWordNet_3.0.0_20130122.txt.我是java的新手,请帮忙,谢谢!以下示例java代码的链接是这样的.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;

public class SWN3 {
    private String pathToSWN = "data"+File.separator+"SentiWordNet_3.0.0.txt";
    private HashMap<String, String> _dict;

    public SWN3(){

        _dict = new HashMap<String, String>();
        HashMap<String, Vector<Double>> _temp = new HashMap<String, Vector<Double>>();
        try{
            BufferedReader csv =  new BufferedReader(new FileReader(pathToSWN));
            String line = "";           
            while((line = csv.readLine()) != null)
            {
                String[] data = line.split("\t");
                Double score = Double.parseDouble(data[2])-Double.parseDouble(data[3]);
                String[] words …
Run Code Online (Sandbox Code Playgroud)

java twitter sentiment-analysis

5
推荐指数
1
解决办法
2万
查看次数

使用 R 的 qdap 包估计文档极性而不使用 sentSplit

我想将qdappolarity函数应用于文档向量,每个文档可以包含多个句子,并为每个文档获取相应的极性。例如:

library(qdap)
polarity(DATA$state)$all$polarity
# Results:
 [1] -0.8165 -0.4082  0.0000 -0.8944  0.0000  0.0000  0.0000 -0.5774  0.0000
[10]  0.4082  0.0000
Warning message:
In polarity(DATA$state) :
  Some rows contain double punctuation.  Suggested use of `sentSplit` function.
Run Code Online (Sandbox Code Playgroud)

这个警告不能忽略,因为它似乎添加了文档中每个句子的极性分数。这可能导致文档级极性分数超出 [-1, 1] 范围。

我知道首先运行sentSplit然后在句子中求平均值的选项,可能按字数加权极性,但这是 (1) 低效的(大约是在带有警告的完整文档上运行的时间的 4 倍),并且( 2)不清楚如何给句子加权。这个选项看起来像这样:

DATA$id <- seq(nrow(DATA)) # For identifying and aggregating documents 
sentences <- sentSplit(DATA, "state")
library(data.table) # For aggregation
pol.dt <- data.table(polarity(sentences$state)$all)
pol.dt[, id := sentences$id]
document.polarity <- pol.dt[, sum(polarity * wc) / …
Run Code Online (Sandbox Code Playgroud)

nlp r sentiment-analysis qdap

5
推荐指数
1
解决办法
3751
查看次数

如何在Java中使用Weka将文本转换为TF-IDF格式?

假设我有以下带有两个属性的示例ARFF文件:

(1)情绪:正面[1]或负面[-1]

(2)推文:文字

@relation sentiment_analysis

@attribute sentiment {1, -1}
@attribute tweet string

@data
-1,'is upset that he can\'t update his Facebook by texting it... and might cry as a result  School today also. Blah!'
-1,'@Kenichan I dived many times for the ball. Managed to save 50\%  The rest go out of bounds'
-1,'my whole body feels itchy and like its on fire '
-1,'@nationwideclass no, it\'s not behaving at all. i\'m mad. why am i here? because I can\'t see …
Run Code Online (Sandbox Code Playgroud)

machine-learning weka arff sentiment-analysis text-classification

5
推荐指数
1
解决办法
2126
查看次数

非英语文本的情感分析

我想分析用德语写的文本的情绪。我找到了很多关于如何用英语做到这一点的教程,但我没有找到关于如何将它应用于不同语言的教程。

我有一个想法是使用TextBlobPython 库先将句子翻译成英文,然后再进行情感分析,但我不确定这是否是解决此任务的最佳方法。

或者还有其他可能的方法来解决这个任务吗?

python nlp machine-learning sentiment-analysis textblob

5
推荐指数
1
解决办法
5511
查看次数

python中非英语推文的情感分析

目标:将每条推文分类为正面或负面,并将其写入输出文件,其中包含用户名、原始推文和推文的情绪。

代码:

import re,math
input_file="raw_data.csv"
fileout=open("Output.txt","w")
wordFile=open("words.txt","w")
expression=r"(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"

fileAFINN = 'AFINN-111.txt'
afinn = dict(map(lambda (w, s): (w, int(s)), [ws.strip().split('\t') for ws in open(fileAFINN)]))

pattern=re.compile(r'\w+')
pattern_split = re.compile(r"\W+")
words = pattern_split.split(input_file.lower())
print "File processing started"
with open(input_file,'r') as myfile:
for line in myfile:
    line = line.lower()

    line=re.sub(expression," ",line)
    words = pattern_split.split(line.lower())
    sentiments = map(lambda word: afinn.get(word, 0), words)
    #print sentiments
    # How should you weight the individual word sentiments?
    # You could do N, sqrt(N) or 1 for example. Here …
Run Code Online (Sandbox Code Playgroud)

python twitter nlp python-2.7 sentiment-analysis

5
推荐指数
1
解决办法
1062
查看次数

"增强"CoreNLP情绪分析结果

我正在尝试使用CoreNLP(Java)对大量产品评论进行情绪分析.总的来说,我发现分析的准确性非常好.从我读到的,我使用的模型最初是使用电影评论创建的(我认为),所以它不是100%适合分析产品评论.我想知道"提高"分析准确性的最佳方法.

我想到的主要是除了产品评论的文本之外,我还有一个用户提供的星级评分.值范围从1-5,1星是最低.我希望有一种方法可以在产生情绪评分时考虑星级评分,因为它更准确地反映了用户对特定产品的感受.有没有一种方法可以最好地将星级评分因子用于CoreNLP中的情绪分析评分?我的分析代码看起来像这样:

List<ProductReview> reviews = this.reviewRepository.findAll();
        for (ProductReview review : reviews) {
            Properties props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref, sentiment");
            props.put("ner.model", "edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz");

            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

            int starRating = review.getStarRating();
            String reviewText = review.getTitle() + " : " + review.getReviewText();
            if (!StringUtils.isEmpty(reviewText)) {
                int longest = 0;
                int mainSentiment = 0;
                Annotation annotation = pipeline.process(reviewText);
                String sentimentStr = null;
                List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
                for (CoreMap sentence : sentences) {
                    Tree sentimentTree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); …
Run Code Online (Sandbox Code Playgroud)

java stanford-nlp sentiment-analysis

5
推荐指数
1
解决办法
641
查看次数

如何将句子拆分为相关词(术语提取)?

是否有任何 NLP python 库可以拆分句子或将单词连接成相关的单词对?例如:

那不是坏例子->“那个”“是”“不错”“例子”

“不错”的意思是一样的好,所以在机器学习中把它当作“不”和“坏”来处理是没有用的。我什至不知道如何称呼这些相关的词对。(术语提取?阶段提取?)或者甚至更好地拆分为带名词的形容词,例如:

与减税有关的不诚实媒体 -> “不诚实媒体”、“相关”、“关于”、“减税”

我找到了 toopia.termextract 但它不适用于 python3。

python nlp text-extraction nltk sentiment-analysis

5
推荐指数
1
解决办法
942
查看次数

在 Python 中根据文本的极性从 Textblob 中获取正负词(情感分析)

我有一个文本 blob,其中如果极性 > 0,我将文本分类为正,如果 = 0,则为中性,如果 < 0,则为负。我如何根据将其分类为正、负或中性来获得单词?

python machine-learning python-3.x sentiment-analysis textblob

5
推荐指数
1
解决办法
4800
查看次数

任何有效的方法来找到周围的ADJ尊重python中的目标短语?

我正在对给定的文件进行情感分析,我的目标是我想在我的句子中找出与目标短语相关的最接近或周围的形容词.我确实知道如何提取与目标短语相关的周围词,但我如何找到与目标短语相对接近或最接近的形容词或NNP/ VBN或其他POS标签.

这是关于如何使周围的单词尊重我的目标短语的草图概念.

sentence_List= {"Obviously one of the most important features of any computer is the human interface.", "Good for everyday computing and web browsing.",
"My problem was with DELL Customer Service", "I play a lot of casual games online[comma] and the touchpad is very responsive"}

target_phraseList={"human interface","everyday computing","DELL Customer Service","touchpad"}
Run Code Online (Sandbox Code Playgroud)

请注意,我的原始数据集是作为数据框给出的,其中给出了句子列表和相应的目标短语.这里我只是模拟数据如下:

import pandas as pd
df=pd.Series(sentence_List, target_phraseList)
df=pd.DataFrame(df)
Run Code Online (Sandbox Code Playgroud)

在这里我将句子标记为如下:

from nltk.tokenize import word_tokenize
tokenized_sents = [word_tokenize(i) for i in sentence_List]
tokenized=[i for i in tokenized_sents]
Run Code Online (Sandbox Code Playgroud)

然后我试着通过 …

python parsing nlp sentiment-analysis

5
推荐指数
1
解决办法
211
查看次数

RetryError: 使用 Gcloud 调用 functools.partial 时超出了 600.0s 的截止日期

我是 python 的初学者,正在尝试应用 Gcloud 情绪分析来分析一些句子。python代码由官方提供:https : //cloud.google.com/natural-language/docs/analyzing-sentiment

错误如下:

RetryError: 调用 functools.partial(.error_remapped_callable at 0x0000020081C0EB70>, document { type: PLAIN_TEXT content: "yes i do!" } , metadata=[('x-goog-api-client', 'gl -python/3.6.5 grpc/1.17.1 gax/1.7.0 gapic/1.1.1')]),最后一个异常:503 通道处于状态 TRANSIENT_FAILURE

我尝试了很多方法(例如禁用防火墙,切换到其他笔记本电脑/wifi)来解决但都失败了。我确定环境变量是使用应用程序默认凭据设置的,并且 API 已通过身份验证。

你有什么想法吗?非常感谢!

编码环境:

蟒蛇 3.6

赢10

来自 CMD pip 列表的 python 包——

gcloud (0.18.3),

谷歌 API 核心(1.7.0),

谷歌云语言 (1.1.1)

from google.cloud import language_v1
from google.cloud.language_v1 import enums
import six


    def sample_analyze_sentiment(content):

    client = language_v1.LanguageServiceClient()

    # content = 'Your text to analyze, e.g. Hello, world!'

    if isinstance(content, …
Run Code Online (Sandbox Code Playgroud)

python python-3.x sentiment-analysis gcloud

5
推荐指数
0
解决办法
743
查看次数