【发布时间】: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