修改情感包中的极性字

问题描述 投票:1回答:1

是否可以修改sentimentr程序包中的单词?例如,我想将单词“ please”更改为负分数而不是正分数。现在我正在使用该函数:

text$sentiment <- sentiment_by(text$Comment)

用于评估句子情感。

r sentiment-analysis sentimentr
1个回答
0
投票

一个人可以如下修改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)
© www.soinside.com 2019 - 2024. All rights reserved.