【问题标题】:Error in Sentiment Analysis using R Package "Sentiment"使用 R 包“情绪”进行情绪分析时出错
【发布时间】: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。我对您的服务感到满意

  1. 问题未得到解决

使用的功能:

分析 = score.sentiment(sample, pos_words, neg_words)

当我运行上述函数时,我收到以下警告,输出分数为 0,0,这是错误的:

警告信息: 在 data.frame(score = scores, text = sentence) : 行名是从一个短变量中找到的,已被丢弃

输出:

分数文本

  1. 0 我对您的服务感到满意

  2. 0 问题未得到解决

当我只使用一行作为输入时,我得到了正确的分数。

有人可以帮我解决这个问题吗?

谢谢,

桑迪普

【问题讨论】:

    标签: r sentiment-analysis


    【解决方案1】:

    你能检查一下你要执行senti分析的文本列是否是一个向量。 示例:如果数据集有 2 列:数字和文本。您想对文本执行情感分析。所以在运行代码之前,让它像句子=dataset$text 这样的向量。现在使用代码中的句子。

    【讨论】:

      猜你喜欢
      • 2012-05-01
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      相关资源
      最近更新 更多