error in r code sentiment analysis

柔情痞子 提交于 2019-12-12 01:43:34

问题


I am trying to write a code in r to do sentiment analysis by exporting and analyzing tweets,the following code is supposed to clean the tweet call up the sentiment package do the scoring and return back the result , this code has been cited in many tech blogs the code is as follows :

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)
}  

However i keep on getting the following error:

Error in score.sentiment(Datasetgaza$text, pos.words, neg.words, .progress = "text") : unused argument (.progress = "text")

The argument passed was: gaza.scores=score.sentiment(Datasetgaza$text,pos.words,neg.words,.progress='text')

any help with the code would be very appreciated


回答1:


You missed a '.' in front of progress. sure this will help.

    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)
}  


来源:https://stackoverflow.com/questions/24903030/error-in-r-code-sentiment-analysis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!