【发布时间】:2017-11-06 04:27:07
【问题描述】:
我正在使用 R 包“情感”进行情感分析
neg_words = scan("C:/Users/kothasan/Desktop/Sentiment Analysis/neg.words.txt", what='character', comment.char=';')
pos_words = scan("C:/Users/kothasan/Desktop/Sentiment Analysis/pos.words.txt", what='character', comment.char=';')
score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{
require(plyr);
require(stringr);
scores = laply(sentences, function(sentence, pos.words, neg.words) {
sentence = gsub('[^A-z ]','', sentence)
sentence = tolower(sentence);
word.list = str_split(sentence, '\\s+');
words = unlist(word.list);
pos.matches = match(words, pos.words);
neg.matches = match(words, neg.words);
pos.matches = !is.na(pos.matches);
neg.matches = !is.na(neg.matches);
score = sum(pos.matches) - sum(neg.matches);
return(score);
}, pos.words, neg.words, .progress=.progress );
scores.df = data.frame(score=scores, text=sentences);
return(scores.df);
}
样本数据由两行组成:。 "text" 是列名。
text
1。我对您的服务感到满意
- 问题未得到解决
使用的功能:
分析 = score.sentiment(sample, pos_words, neg_words)
当我运行上述函数时,我收到以下警告,输出分数为 0,0,这是错误的:
警告信息: 在 data.frame(score = scores, text = sentence) : 行名是从一个短变量中找到的,已被丢弃
输出:
分数文本
0 我对您的服务感到满意
0 问题未得到解决
当我只使用一行作为输入时,我得到了正确的分数。
有人可以帮我解决这个问题吗?
谢谢,
桑迪普
【问题讨论】:
标签: r sentiment-analysis