9

The "sentiment" package in R was removed from the Cran repository. What are the other packages which can do Sentiment Analysis?

For example, how I can rewrite this using other packages?

 library(sentiment)
# CLASSIFY EMOTIONS
classify_emotion(some_txt,algorithm="bayes",verbose=TRUE)
# classify polarity
class_pol = classify_polarity(some_txt, algorithm="bayes")

Where documents here is defined as:

# DEFINE text
some_txt<- c("I am very happy at stack overflow , excited, and optimistic.",
                "I am very scared from OP question, annoyed, and irritated.")
Sam
  • 7,252
  • 16
  • 46
  • 65
user1946217
  • 1,733
  • 6
  • 31
  • 40
  • qdap does a polarity thing but it's low level at this point. Essentially it's a dictionary lookup system and may not scale well to large projects. It's intended more for discourse studies. – Tyler Rinker Mar 04 '13 at 04:14
  • Have you looked at the workflows and functions linked to here? http://stackoverflow.com/q/10233087/1036500 Here's a summary of two other methods: https://sites.google.com/site/miningtwitter/questions/sentiment – Ben Mar 04 '13 at 04:37
  • 1
    you can do this , `library(sos) ;findFn('sentiment analysis')`, you have essentially, `qdap` and `textir` but there is also `tm.plugin.sentiment` for time series .. The `sentiment` package is still exist in R-Forge also. – agstudy Mar 04 '13 at 04:38
  • 1
    The `qdap::polarity` function is an implementation based on the first link Ben provides but with a custom algorithm. I'm not happy with it but haven't had time to develop it further yet. – Tyler Rinker Mar 04 '13 at 04:42
  • 1
    @user1946217 I add some concrete example to your question..( I am joking for the text example, feel free to edit it) – agstudy Mar 04 '13 at 05:43
  • @agstudy I do not find the "sentiment" package in R-Forge either. I got the archived version on CRAN. But It isn't loading properly. `> install.packages("C:/Users/Documents/R/win-library/2.15/sentiment.zip", repos=NULL)` `Installing package(s) into ‘C:/Users/Documents/R/win-library/2.15’ (as ‘lib’ is unspecified)` `package ‘sentiment’ successfully unpacked and MD5 sums checked` `> library(sentiment)` `Error in library(sentiment) : ‘sentiment’ is not a valid installed package` Am I missing something – user1946217 Mar 04 '13 at 07:16
  • @TylerRinker Has qdap's polarity abilities improved in the past two years? – Dason Feb 19 '15 at 23:18
  • 2
    @Dason yes I rewrote the algorithm to be more accurate and faster. It also takes into account negators (e.g., "It's not good" is ranked as a negative polarity rather than positive as "not" is accounted for). Other algorithms do not. – Tyler Rinker Feb 19 '15 at 23:37

4 Answers4

12

I can't find sentiment package.This is based on the tm.plugin.sentiment package. You can find it here.

First, I create my Corpus:

some_txt<- c("I am very happy at stack overflow , excited, and optimistic.",
+              "I am very scared from OP question, annoyed, and irritated.")
 text.corpus <- Corpus(VectorSource(some_txt))

Then, I apply score on the corpus

> text.corpus <- score(text.corpus)

The result is stored in the meta :

> meta(text.corpus)
  MetaID polarity subjectivity pos_refs_per_ref neg_refs_per_ref senti_diffs_per_ref
1      0        0    0.2857143        0.1428571        0.1428571           0.0000000
2      0       -1    0.1428571        0.0000000        0.1428571          -0.1428571

behind the code The score function (the default behavior), will pre-procees the corpus using these tm functions:

  • tolower
  • removePunctuation
  • removeNumbers = TRUE,
  • removeWords = list(stopwords("english")),
  • stripWhitespace
  • stemDocument
  • minWordLength = 3,

Then, apply the score functions:

  • polarity
  • subjectivity
  • pos_refs_per_ref
  • neg_refs_per_ref
  • senti_diffs_per_ref
Student
  • 1,197
  • 4
  • 22
  • 39
agstudy
  • 119,832
  • 17
  • 199
  • 261
  • Each time the score() code throws an error: scored <- score(corpus.txt) Error in polarity.TermDocumentMatrix(list(i = c(2L, 6L, 8L, 11L, 12L, : could not find function "tm_tag_score". Others have encountered different errors: http://stackoverflow.com/questions/24612080/tm-plugin-sentiment-issue-error-could-not-find-function-dmetadata. Can you advise or should I post a new question? Thank you. – lawyeR Apr 28 '15 at 12:46
3

There is new R package called sentiment140, required no additional component installation nor language model training.

  • Easy to use
  • work with Twitter Text

Cool stuff !

http://github.com/okugami79/sentiment140

kurrabac
  • 31
  • 1
2

This is what I did to install 'sentiment' 0.2 in R version 3.0.2

I downloaded the 'sentiment_0.2.tar.gz' from the repository http://cran.r-project.org/src/contrib/Archive/sentiment/

Then I've put the 'sentiment_0.2.tar.gz' in the main directory --> C:

Then I used the command to install packages from local zip:

install.packages("C:/sentiment_0.2.tar.gz", repos = NULL, type="source")

This is what I've got:

Warning in install.packages :
  package ‘C:/sentiment_0.2.tar.gz’ is not available (for R version 3.0.2)

Installing package into ‘C:/Users/y65liu/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)

** installing source package 'sentiment' ...

** package 'sentiment' successfully unpacked and MD5 sums checked

** R

** data

** preparing package for lazy loading

** help

** installing help indices

** building package indices

** testing if installed package can be loaded

** DONE (sentiment) ?

When I call the library, the library is regularly loaded with its related packages ('tm', 'Rstem')

You may found documentation on using the sentiment package here:

https://sites.google.com/site/miningtwitter/questions/sentiment/sentiment
desertnaut
  • 57,590
  • 26
  • 140
  • 166
user3875022
  • 116
  • 4
0

To install sentiment analysis package use this http://cran.r-project.org/web/packages/sentiment/index.html since the packages are quite old already and R cran removed them from their site.

the packages that are required before installing are tm , Rstem , twitteR,ggplot2,plyr,RColorBrewer and wordcloud it may provide some errors but I worked for me so far :P

Napmi
  • 521
  • 2
  • 13
  • 32