我试图找到一种方法来实现英语单词的情感规范(荷兰语),以便与全德达进行纵向情感分析。我最终想要的是每年的“平均情绪”,以显示任何纵向趋势。
在数据集中,由64位编码者在4个类别上对所有单词进行7分的Likert评分,这为每个单词提供了一个平均值。我想做的是取其中一个维度,用它来分析情绪随时间的变化。我意识到泉泰有一个实现LIWC-字典的功能,但如果可能的话,我更愿意使用开源的新数据。
本质上,我需要实现方面的帮助,因为我对编码和R很陌生。
新文件看起来如下(在.csv中):
单词/分数:癌症: 1.01,土豆: 3.56,爱情: 6.56
发布于 2017-05-23 18:15:51
还没有直接但是..。它不同于其他字典,因为它不使用键:值对格式,而是为每个术语分配一个数字分数。这意味着您不是根据键来计算匹配的值,而是选择功能,然后使用加权计数对它们进行评分。
在quanteda中可以这样做:
dfm(yourtext, select = ANEWfeatures)创建一个只具有新特性的dfm。rowSums()来获得文档级的价态分数.或者说,
还请注意,tidytext重新使用它的情绪评分,如果您想将您的dfm转换为它们的对象并使用该方法(这基本上是我前面建议的版本)。
更新:
事实证明,我已经在quanteda中构建了您需要的特性,而且根本没有意识到这一点!
这会管用的。首先,在新字典中加载。(你必须自己提供新的文件。)
# read in the ANEW data
df_anew <- read.delim("ANEW2010All.txt", stringsAsFactors = FALSE)
# construct a vector of weights with the term as the name
vector_anew <- df_anew$ValMn
names(vector_anew) <- df_anew$Word既然我们有了一个命名的权向量,我们就可以使用dfm_weight()来应用它了。下面,我首先用相对频率对dfm进行了规范化,这样文档汇总得分就不依赖于标记中的文档长度。如果您不想这样做,只需删除下面所示的行。
library("quanteda")
dfm_anew <- dfm(data_corpus_inaugural, select = df_anew$Word)
# weight by the ANEW weights
dfm_anew_weighted <- dfm_anew %>%
dfm_weight(scheme = "prop") %>% # remove if you don't want normalized scores
dfm_weight(weights = vector_anew)
## Warning message:
## dfm_weight(): ignoring 1,427 unmatched weight features
tail(dfm_anew_weighted)[, c("life", "day", "time")]
## Document-feature matrix of: 6 documents, 3 features (5.56% sparse).
## 6 x 3 sparse Matrix of class "dfm"
## features
## docs life day time
## 1997-Clinton 0.07393220 0.06772881 0.21600000
## 2001-Bush 0.10004587 0.06110092 0.09743119
## 2005-Bush 0.09380645 0.12890323 0.11990323
## 2009-Obama 0.06669725 0.10183486 0.09743119
## 2013-Obama 0.08047970 0 0.19594096
## 2017-Trump 0.06826291 0.12507042 0.04985915
# total scores
tail(rowSums(dfm_anew_weighted))
## 1997-Clinton 2001-Bush 2005-Bush 2009-Obama 2013-Obama 2017-Trump
## 5.942169 6.071918 6.300318 5.827410 6.050216 6.223944 https://stackoverflow.com/questions/44132313
复制相似问题