首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在R3.2.0中使用情感包

如何在R3.2.0中使用情感包
EN

Stack Overflow用户
提问于 2015-04-28 11:19:19
回答 1查看 8.5K关注 0票数 0

我是一个ML enthusiast.Recently,我已经开始使用R和它的packages.But了,我无法为R3.2.0安装情感包。我在谷歌上搜索过这个问题。它说情感包不再适用于R3.0。但是我在很多github存储库中看到过,其中不使用情感包,但它的文件仍然是used.My,主要问题是如何使用R3.2.0的情感包?

EN

回答 1

Stack Overflow用户

发布于 2015-04-28 12:59:26

这是一个起点。首先是一些安装感情插件的代码(谢谢您,Dason,给出了有用的评论)。

接下来,使用前一个SO文章中的一些文本来显示您可能做的事情,您可以创建一个数据框架。

安装用于情感分析的软件包:

代码语言:javascript
复制
# 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)

使用已安装函数的

代码语言:javascript
复制
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
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29918017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档