我對青澀的分析,使用R包 「情」錯誤情感分析,使用R包 「情」
neg_words =掃描(「C工作。 txt「,what ='character',comment.char =';')
pos_words = scan(」C:/ Users/kothasan/Desktop/Sentiment Analysis/pos.words.txt「,what ='character' ,comment.char = ';')
score.sentiment =函數(句子,pos.words,neg.words,.progress = '無')
{
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
1.我很舒服的服務
- 問題沒有得到解決 使用
0我很舒服你的服務
- 個
0問題沒有得到解決
功能:
分析= score.sentiment (sample,pos_words,neg_words)
當我運行上面的函數時,我得到了下面的警告與輸出得分爲0,0這是錯誤的:
警告消息: 在data.frame(得分=分數,文本=句子):從短變發現 行的名稱和已被丟棄
輸出:
比分文字
我得到正確的分數時,我只用一排作爲輸入。
有人能幫我解決嗎?
感謝,
桑迪普