是否可以修改sentimentr
程序包中的单词?例如,我想将单词“ please”更改为负分数而不是正分数。现在我正在使用该函数:
text$sentiment <- sentiment_by(text$Comment)
用于评估句子情感。
一个人可以如下修改sentiment
程序包的sentimentr
功能使用的极性字典:
library(sentimenr)
library(lexicon)
# sample text
text <- "Please please please, be nice."
# output with default dictionary
sentiment(text, polarity_dt = lexicon::hash_sentiment_jockers_rinker)
# polarity of 'please' in default dictionary
lexicon::hash_sentiment_jockers_rinker$y[lexicon::hash_sentiment_jockers_rinker$x %in% "please"]
# create a modified dictionary
mysentiment <- lexicon::hash_sentiment_jockers_rinker
mysentiment$y[mysentiment$x %in% "please"] <- -1
# modified polarity of 'please'
mysentiment$y[mysentiment$x %in% "please"]
# run sentiment with modified dictionary
sentiment(text, polarity_dt = mysentiment)