R:情感分析包

时间:2020-07-06 18:19:52

标签: r grouping sentiment-analysis

有人知道为什么R中SentimentAnalysis包中的函数aggregate中的analyzeSentiment自变量没有对情感分数进行分组吗?这是一个简单的可复制示例:

> library(SentimentAnalysis)
> documents <- c("Wow, I really like the new light sabers!",
+                "That book was excellent.",
+                "R is a fantastic language.",
+                "The service in this restaurant was miserable.",
+                "This is neither positive or negative.",
+                "The waiter forget about my dessert -- what poor service!")
> Group=factor(c(1,1,2,2,3,3))
> Test_data=data.frame(documents=documents,Group=Group,stringsAsFactors = F)
> sentiment <- analyzeSentiment(x=Test_data$documents,aggregate=Test_data$Group)
> Test_data$SentimentQDAP=sentiment$SentimentQDAP
> Test_data
                                                 documents Group SentimentQDAP
1                 Wow, I really like the new light sabers!     1     0.3333333
2                                 That book was excellent.     1     0.5000000
3                               R is a fantastic language.     2     0.5000000
4            The service in this restaurant was miserable.     2    -0.3333333
5                    This is neither positive or negative.     3     0.0000000
6 The waiter forget about my dessert -- what poor service!     3    -0.4000000

哪些给了我以下内容:

enter image description here

函数analysisSentiment上的帮助说:“ 汇总:一个可以对文档进行分组的因子变量。当加入例如同一天的新闻或移动同一作者的评论时,这很有用。” < / p>

我的问题是,为什么每个小组的分数都不一样?

1 个答案:

答案 0 :(得分:1)

我检查了analyzeSentiment函数的source code,以查看该aggregate自变量会发生什么情况。

有趣的是,它在您的代码中没有执行任何操作的原因是因为该参数本质上是多余的-它从未使用过!如果您从最初的analyzeSentiment函数开始遵循调用堆栈,则aggregate参数会被传递,直到到达情感计算的主要中心analyzeSentiment.DocumentTermMatrix。这是计算结果数据帧然后返回的地方,传递给aggregate的值似乎在代码中的任何地方都没有出现。它已传入并且从未使用过。

必须是它们从未添加到软件包中的功能,或者是为了向后兼容而保留在先前版本中的构件。