你在句子中遇到的问题是,情感词汇是基于单词的。如果你看看nrc的词典,“愤怒”一词有三个情感价值:愤怒、厌恶和消极。你选择哪一个?或者让句子返回一个词典中的多个单词。试着用文本测试不同的词汇,看看会发生什么,例如
tidytext
。
如果你想要一个能从句子层面分析情感的软件包,你可以
sentimentr
。你不会得到像愤怒这样的情绪值,而是情绪/极性得分。更多关于
多愁善感的人
可以在中找到
package documentation
和上
sentimentr
github页面。
一个小示例代码:
library(sentimentr)
text <- data.frame(id = c("12345","23456","34567"),
sentence = c("I am extremely angry with my service", "I was happy with how everything turned out", "The rep did a great job helping me"),
stringsAsFactors = FALSE)
sentiment(text$sentence)
element_id sentence_id word_count sentiment
1: 1 1 7 -0.5102520
2: 2 1 8 0.2651650
3: 3 1 8 0.3535534
# add sentiment score to data.frame
text$sentiment <- sentiment(text$sentence)$sentiment
text
id sentence sentiment
1 12345 I am extremely angry with my service -0.5102520
2 23456 I was happy with how everything turned out 0.2651650
3 34567 The rep did a great job helping me 0.3535534