我是ML爱好者。最近我开始使用R及其软件包。但是我无法为R 3.2.0安装情绪包。我已经用Google搜索了这个问题。它说R 3.2.0不再提供情绪包了。但是我在许多github存储库中看到过没有使用情绪包但仍在使用它的文件。我的主要问题是如何使用R 3.2的情绪包0.0
答案 0 :(得分:4)
这是一个起点。首先是安装情绪插件的一些代码(谢谢你,Dason,有用的评论)。
接下来,使用之前SO帖子中的一些文字来展示您可能会做什么,您可以创建一个数据框。
安装包以进行情绪分析:
# install.packages("tm.lexicon.GeneralInquirer", repos="http://datacube.wu.ac.at", type="source")
library(tm.lexicon.GeneralInquirer)
# install.packages("tm.plugin.sentiment", repos="http://R-Forge.R-project.org")
library(tm.plugin.sentiment) # posted comments on SO about this not working
library(tm)
使用已安装的功能:
some_txt<- c("I am very happy at stack overflow , excited, and optimistic.",
"I am very scared from OP question, annoyed, and irritated.", "I am completely neutral about blandness.")
corpus <- Corpus(VectorSource(some_txt))
pos <- sum(sapply(corpus, tm_term_score, terms_in_General_Inquirer_categories("Positiv")))
neg <- sum(sapply(corpus, tm_term_score, terms_in_General_Inquirer_categories("Negativ")))
pos.score <- tm_term_score(TermDocumentMatrix(corpus, control = list(removePunctuation = TRUE)),
terms_in_General_Inquirer_categories("Positiv")) # this lists each document with number below
neg.score <- tm_term_score(TermDocumentMatrix(corpus, control = list(removePunctuation = TRUE)),
terms_in_General_Inquirer_categories("Negativ"))
total.df <- data.frame(positive = pos.score, negative = neg.score)
total.df <- transform(total.df, net = positive - negative)
positive negative net
1 3 1 2
2 0 1 -1
3 0 0 0