# via vector of strings
corpus <- c("Positive text", "Neutral but uncertain text", "Negative text")
sentiment <- analyzeSentiment(corpus)
compareToResponse(sentiment, c(+1, 0, -2))
# via Corpus from tm package
library(tm)
reut21578 <- system.file("texts", "crude", package="tm")
reuters <- Corpus(DirSource(reut21578),
readerControl=list(reader=readReut21578XML))
# via DocumentTermMatrix (with stemmed entries)
dtm <- DocumentTermMatrix(Corpus(VectorSource(c("posit posit", "negat neutral"))))
sentiment <- analyzeSentiment(dtm)
compareToResponse(sentiment, convertToBinaryResponse(c(+1, -1)))
# By adapting the parameter rules, one can incorporate customized dictionaries
# e.g. in order to adapt to arbitrary languages
dictionaryAmplifiers <- SentimentDictionary(c("more", "much"))
sentiment <- analyzeSentiment(corpus,
rules=list("Amplifiers"=list(ruleRatio,
dictionaryAmplifiers)))
# On can also restrict the number of computed methods to the ones of interest
# in order to achieve performance optimizations
sentiment <- analyzeSentiment(corpus,
rules=list("SentimentLM"=list(ruleSentiment,
loadDictionaryLM())))
sentiment
Run the code above in your browser using DataLab