首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用R包“情感”分析情感的错误

用R包“情感”分析情感的错误
EN

Stack Overflow用户
提问于 2017-06-05 11:45:43
回答 1查看 467关注 0票数 1

我正在用R包“感情”进行情感分析

neg_words =扫描(“C:/Users/kothasan/Desktop/感情分析/否定.words.txt”,what=‘字符’,注释.what=‘;’)

pos_words =扫描(“C:/Users/kothasan/Desktop/感情分析/pos.words.txt”,什么=‘字符’,注释.what=‘;’)

score.sentiment =函数(句子,pos.words,neg.words,. .progress='none')

{

代码语言:javascript
复制
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“是列名。

代码语言:javascript
复制
                          text
  1. 我对你的服务很满意
  2. 未解决的问题

所使用的功能:

分析=score.sentiment(样本、pos_words、neg_words)

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

警告消息:在data.frame中(得分=分数,文本=句子):行名从一个短变量中找到,并已被丢弃

输出:

得分文本

  1. 我对你的服务很满意
  2. 0未解决的问题

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

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

谢谢,

桑迪普

EN

回答 1

Stack Overflow用户

发布于 2017-10-17 10:02:25

您能否检查要执行senti分析的文本列是否是向量。示例:如果数据集有2列:数字和文本。你想对文本进行情感分析。因此,在运行代码之前,请将代码转到像sentences=dataset$text这样的向量。现在使用代码中的句子。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44368239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档