我是一个ML enthusiast.Recently,我已经开始使用R和它的packages.But了,我无法为R3.2.0安装情感包。我在谷歌上搜索过这个问题。它说情感包不再适用于R3.0。但是我在很多github存储库中看到过,其中不使用情感包,但它的文件仍然是used.My,主要问题是如何使用R3.2.0的情感包?
发布于 2015-04-28 12:59:26
这是一个起点。首先是一些安装感情插件的代码(谢谢您,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 0https://stackoverflow.com/questions/29918017
复制相似问题