【问题标题】:error in r code sentiment analysisr代码情感分析中的错误
【发布时间】:2014-07-23 06:07:16
【问题描述】:

我正在尝试在 r 中编写代码通过导出和分析推文来进行情感分析,以下代码应该清理推文调用情感包进行评分并返回结果,此代码已被引用在许多技术博客中,代码如下:

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('[[:punct:]]','',sentence)
     sentence =gsub('[[:cntrl]]','',sentence)
     sentence =gsub('\\d+','',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)
     score=sum(pos.matches)-sum(neg.matches)
     return(score)
 },pos.words,neg.words,.progress=.progress)
 scores.df=data.frame(scores=scores,text=sentences)
 return(scores.df)
}  

但是我不断收到以下错误:

score.sentiment(Datasetgaza$text, pos.words, neg.words, .progress = "text") 中的错误: 未使用的参数(.progress = "text")

传递的参数是: gaza.scores=score.sentiment(Datasetgaza$text,pos.words,neg.words,.progress='text')

对代码的任何帮助将不胜感激

【问题讨论】:

  • 函数的选项是progress,但在代码中是.progress。我想前者是一个错字。尝试将progress 替换为.progress
  • 给我们一个指向这些“许多技术博客”之一的链接,因为它们一定使用了与您粘贴相同的错误代码。
  • 根据this page,上面转载的代码有错别字。

标签: r sentiment-analysis


【解决方案1】:

你错过了一个“。”在进步面前。 相信这会有所帮助。

    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('[[:punct:]]','',sentence)
     sentence =gsub('[[:cntrl]]','',sentence)
     sentence =gsub('\\d+','',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)
     score=sum(pos.matches)-sum(neg.matches)
     return(score)
 },pos.words,neg.words,.progress=.progress)
 scores.df=data.frame(scores=scores,text=sentences)
 return(scores.df)
}  

【讨论】:

  • 此答案不会向已发布的 cmets 和答案添加任何新内容。
猜你喜欢
  • 2022-01-11
  • 2013-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-09
  • 2018-09-07
  • 1970-01-01
相关资源
最近更新 更多