├── .gitignore ├── data └── dic_gi.rda ├── R ├── data.R ├── corpus.R ├── preprocessCorpus.R ├── getRelevant.R ├── metaXTS.R ├── OHCLSent.transformations.R ├── chartSentiment.R ├── score.R └── addSentiment.R ├── man ├── negterms_GI.Rd ├── posterms_GI.Rd ├── chartSent.Rd ├── dic_gi.Rd ├── getField.VCorpus.Rd ├── addSentimentVo.Rd ├── addSentiment.Rd ├── setField.VCorpus.Rd ├── neg_refs_per_ref.Rd ├── pos_refs_per_ref.Rd ├── polarity.Rd ├── addSubjectivity.Rd ├── subjectivity.Rd ├── senti_diffs_per_ref.Rd ├── trans.Rd ├── preprocessCorpus.Rd ├── getRelevant.Rd ├── metaXTS.Rd ├── score.Rd └── chartSentiment.Rd ├── inst └── NEWS.Rd ├── work └── paper │ ├── Makefile │ ├── sentiment.Rnw │ └── sentiment.bib ├── DESCRIPTION ├── README.md ├── NAMESPACE └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.tar.gz 3 | Makefile -------------------------------------------------------------------------------- /data/dic_gi.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mannau/tm.plugin.sentiment/HEAD/data/dic_gi.rda -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' This is data to be included in \code{tm.plugin.sentiment} 2 | #' 3 | #' @name dic_gi 4 | #' @docType data 5 | #' @author Mario Annau \email{mario.annau@@gmail.com} 6 | #' @references \url{http://www.wjh.harvard.edu/~inquirer/} 7 | #' @keywords data general inquirer 8 | NULL 9 | -------------------------------------------------------------------------------- /man/negterms_GI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{negterms_GI} 4 | \alias{negterms_GI} 5 | \title{Get Negative Terms from General Inquirer} 6 | \usage{ 7 | negterms_GI() 8 | } 9 | \description{ 10 | Get Negative Terms from General Inquirer 11 | } 12 | \author{ 13 | Mario Annau 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/posterms_GI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{posterms_GI} 4 | \alias{posterms_GI} 5 | \title{Get Positive Terms from General Inquirer} 6 | \usage{ 7 | posterms_GI() 8 | } 9 | \description{ 10 | Get Positive Terms from General Inquirer 11 | } 12 | \author{ 13 | Mario Annau 14 | } 15 | 16 | -------------------------------------------------------------------------------- /inst/NEWS.Rd: -------------------------------------------------------------------------------- 1 | \name{NEWS} 2 | \title{News for Package 'tm.plugin.webmining'} 3 | \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} 4 | 5 | \section{Changes in tm.plugin.sentiment version 0.6.1 (2015-09-06)}{ 6 | \itemize{ 7 | \item Fix Issue #3: Error when no positive/negative words identified (thanks Chetan Mishra for reporting). 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /work/paper/Makefile: -------------------------------------------------------------------------------- 1 | file = sentiment 2 | #submission = "file" 3 | 4 | pdf: latex 5 | 6 | all: Sweave pdf 7 | 8 | latex: ${file}.tex ${file}.bib 9 | texi2dvi -p ${file}.tex 10 | 11 | Sweave: ${file}.Rnw 12 | R CMD Sweave ${file}.Rnw 13 | 14 | clean: 15 | rm -f *~ ${file}.aux ${file}.log ${file}.bbl ${file}.blg ${file}.out ${file}.tpt Rplots.pdf $(file)-* *.Rout *-plot_*.eps *-plot_*.pdf 16 | -------------------------------------------------------------------------------- /man/chartSent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/addSentiment.R 3 | \name{chartSent} 4 | \alias{chartSent} 5 | \title{Chart Sentiment is a Helper function for \code{\link{addSentiment}}} 6 | \usage{ 7 | chartSent(x) 8 | } 9 | \arguments{ 10 | \item{x}{chob} 11 | } 12 | \description{ 13 | Chart Sentiment is a Helper function for \code{\link{addSentiment}} 14 | } 15 | \author{ 16 | Mario Annau 17 | } 18 | \seealso{ 19 | \code{\link{addSentiment}} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/dic_gi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{dic_gi} 5 | \alias{dic_gi} 6 | \title{This is data to be included in \code{tm.plugin.sentiment}} 7 | \description{ 8 | This is data to be included in \code{tm.plugin.sentiment} 9 | } 10 | \author{ 11 | Mario Annau \email{mario.annau@gmail.com} 12 | } 13 | \references{ 14 | \url{http://www.wjh.harvard.edu/~inquirer/} 15 | } 16 | \keyword{data} 17 | \keyword{general} 18 | \keyword{inquirer} 19 | 20 | -------------------------------------------------------------------------------- /man/getField.VCorpus.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/corpus.R 3 | \name{getField.VCorpus} 4 | \alias{getField.VCorpus} 5 | \title{Get Meta Data Field in VCorpus as Vector 6 | Get Meta Data Field in VCorpus as Vector} 7 | \usage{ 8 | \method{getField}{VCorpus}(x, fieldname) 9 | } 10 | \arguments{ 11 | \item{x}{VCorpus object} 12 | 13 | \item{fieldname}{character which specifies meta data field name in corpus} 14 | } 15 | \description{ 16 | Get Meta Data Field in VCorpus as Vector 17 | Get Meta Data Field in VCorpus as Vector 18 | } 19 | \author{ 20 | Mario Annau 21 | } 22 | 23 | -------------------------------------------------------------------------------- /man/addSentimentVo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/addSentiment.R 3 | \name{addSentimentVo} 4 | \alias{addSentimentVo} 5 | \title{Add Sentiment Volume as barchart to current chob} 6 | \usage{ 7 | addSentimentVo(fieldname, color = "blue") 8 | } 9 | \arguments{ 10 | \item{fieldname}{Specifies fieldname in XTS object which contains sentiment volume, default "Volume"} 11 | 12 | \item{color}{Color of barchart, default "blue"} 13 | } 14 | \description{ 15 | Add Sentiment Volume as barchart to current chob 16 | } 17 | \author{ 18 | Mario Annau 19 | } 20 | \seealso{ 21 | \code{\link{addSentimentVo}} \code{\link{chartSentiment}} 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/addSentiment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/addSentiment.R 3 | \name{addSentiment} 4 | \alias{addSentiment} 5 | \title{Add Sentiment Scores as barchart to current chob} 6 | \usage{ 7 | addSentiment(fieldname, on = NA) 8 | } 9 | \arguments{ 10 | \item{fieldname}{Specifies fieldname in XTS object which contains sentiment scores} 11 | 12 | \item{on}{Screen on which to plot} 13 | } 14 | \description{ 15 | Add Sentiment Scores as barchart to current chob 16 | } 17 | \author{ 18 | Mario Annau 19 | } 20 | \references{ 21 | adapted from Jeffrey A. Ryan's \code{\link{quantmod}} package 22 | } 23 | \seealso{ 24 | \code{\link{addSentimentVo}} \code{\link{chartSentiment}} 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/setField.VCorpus.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/corpus.R 3 | \name{setField.VCorpus} 4 | \alias{setField.VCorpus} 5 | \title{Set Meta Data Field in VCorpus from Vector 6 | Set Meta Data Field in VCorpus from Vector} 7 | \usage{ 8 | \method{setField}{VCorpus}(x, fieldname, value) 9 | } 10 | \arguments{ 11 | \item{x}{VCorpus object} 12 | 13 | \item{fieldname}{character which specifies meta data field name in corpus} 14 | 15 | \item{value}{vector which values should be used} 16 | } 17 | \description{ 18 | Set Meta Data Field in VCorpus from Vector 19 | Set Meta Data Field in VCorpus from Vector 20 | } 21 | \note{ 22 | vector must be of same length as Corpus 23 | } 24 | \author{ 25 | Mario Annau 26 | } 27 | 28 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: tm.plugin.sentiment 2 | Imports: 3 | slam 4 | Maintainer: Mario Annau 5 | License: GPL-3 6 | Title: Text corpus sentiment analysis 7 | Author: Mario Annau 8 | Description: tm.plugin.sentiment supports sentiment analysis of text 9 | corpora. Scoring of text documents, build up of sentiment time 10 | series in xts and charting using facilities of quantmod are 11 | supported. 12 | Version: 0.6.1 13 | Date: 2015-09-06 14 | Depends: 15 | tm, 16 | quantmod 17 | Collate: 18 | 'OHCLSent.transformations.R' 19 | 'addSentiment.R' 20 | 'chartSentiment.R' 21 | 'corpus.R' 22 | 'data.R' 23 | 'getRelevant.R' 24 | 'metaXTS.R' 25 | 'preprocessCorpus.R' 26 | 'score.R' 27 | -------------------------------------------------------------------------------- /man/neg_refs_per_ref.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{neg_refs_per_ref} 4 | \alias{neg_refs_per_ref} 5 | \alias{neg_refs_per_ref.DocumentTermMatrix} 6 | \alias{neg_refs_per_ref.TermDocumentMatrix} 7 | \title{Calculate neg_refs_per_ref from Matrix} 8 | \usage{ 9 | neg_refs_per_ref(x, negative) 10 | 11 | \method{neg_refs_per_ref}{TermDocumentMatrix}(x, negative = negterms_GI()) 12 | 13 | \method{neg_refs_per_ref}{DocumentTermMatrix}(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{TermDocumentMatrix} 17 | 18 | \item{negative}{character vector specifying negative terms to be used, defaults to \code{\link{negterms_GI}}} 19 | } 20 | \description{ 21 | Calculate neg_refs_per_ref from Matrix 22 | } 23 | \author{ 24 | Mario Annau 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/pos_refs_per_ref.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{pos_refs_per_ref} 4 | \alias{pos_refs_per_ref} 5 | \alias{pos_refs_per_ref.DocumentTermMatrix} 6 | \alias{pos_refs_per_ref.TermDocumentMatrix} 7 | \title{Calculate pos_refs_per_ref from Matrix} 8 | \usage{ 9 | pos_refs_per_ref(x, positive) 10 | 11 | \method{pos_refs_per_ref}{TermDocumentMatrix}(x, positive = posterms_GI()) 12 | 13 | \method{pos_refs_per_ref}{DocumentTermMatrix}(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{TermDocumentMatrix} 17 | 18 | \item{positive}{character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}}} 19 | } 20 | \description{ 21 | Calculate pos_refs_per_ref from Matrix 22 | } 23 | \author{ 24 | Mario Annau 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/polarity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{polarity} 4 | \alias{polarity} 5 | \alias{polarity.DocumentTermMatrix} 6 | \alias{polarity.TermDocumentMatrix} 7 | \title{Calculate Polarity from Matrix} 8 | \usage{ 9 | polarity(x, positive, negative) 10 | 11 | \method{polarity}{TermDocumentMatrix}(x, positive = posterms_GI(), 12 | negative = negterms_GI()) 13 | 14 | \method{polarity}{DocumentTermMatrix}(x, ...) 15 | } 16 | \arguments{ 17 | \item{x}{TermDocumentMatrix} 18 | 19 | \item{positive}{character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}}} 20 | 21 | \item{negative}{character vector specifying negative terms to be used, defaults to\code{\link{negterms_GI}}} 22 | } 23 | \description{ 24 | Calculate Polarity from Matrix 25 | } 26 | \author{ 27 | Mario Annau 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/addSubjectivity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/addSentiment.R 3 | \name{addSubjectivity} 4 | \alias{addNeg_Refs_Per_Ref} 5 | \alias{addPolarity} 6 | \alias{addPos_Refs_Per_Ref} 7 | \alias{addSentVol} 8 | \alias{addSenti_Diffs_Per_Ref} 9 | \alias{addSubjectivity} 10 | \title{Add Sentiment Field to chobs 11 | Adds one of the following sentiment fields to the current chob: 12 | Subjectivity, Polarity, Pos_Refs_Per_Ref, Pos_Refs_Per_Ref, Neg_Refs_Per_Ref, 13 | Senti_Diffs_Per_Ref, SentVol} 14 | \usage{ 15 | addSubjectivity(..., on = NA, legend = "auto") 16 | } 17 | \description{ 18 | Add Sentiment Field to chobs 19 | Adds one of the following sentiment fields to the current chob: 20 | Subjectivity, Polarity, Pos_Refs_Per_Ref, Pos_Refs_Per_Ref, Neg_Refs_Per_Ref, 21 | Senti_Diffs_Per_Ref, SentVol 22 | } 23 | \author{ 24 | Mario Annau 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/subjectivity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{subjectivity} 4 | \alias{subjectivity} 5 | \alias{subjectivity.DocumentTermMatrix} 6 | \alias{subjectivity.TermDocumentMatrix} 7 | \title{Calculate Polarity from Matrix} 8 | \usage{ 9 | subjectivity(x, positive, negative) 10 | 11 | \method{subjectivity}{TermDocumentMatrix}(x, positive = posterms_GI(), 12 | negative = negterms_GI()) 13 | 14 | \method{subjectivity}{DocumentTermMatrix}(x, ...) 15 | } 16 | \arguments{ 17 | \item{x}{TermDocumentMatrix} 18 | 19 | \item{positive}{character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}}} 20 | 21 | \item{negative}{character vector specifying negative terms to be used, defaults to\code{\link{negterms_GI}}} 22 | } 23 | \description{ 24 | Calculate Polarity from Matrix 25 | } 26 | \author{ 27 | Mario Annau 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/senti_diffs_per_ref.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{senti_diffs_per_ref} 4 | \alias{senti_diffs_per_ref} 5 | \alias{senti_diffs_per_ref.DocumentTermMatrix} 6 | \alias{senti_diffs_per_ref.TermDocumentMatrix} 7 | \title{Calculate senti_diffs_per_ref from Matrix} 8 | \usage{ 9 | senti_diffs_per_ref(x, positive, negative) 10 | 11 | \method{senti_diffs_per_ref}{TermDocumentMatrix}(x, positive = posterms_GI(), 12 | negative = negterms_GI()) 13 | 14 | \method{senti_diffs_per_ref}{DocumentTermMatrix}(x, ...) 15 | } 16 | \arguments{ 17 | \item{x}{TermDocumentMatrix} 18 | 19 | \item{positive}{character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}}} 20 | 21 | \item{negative}{character vector specifying negative terms to be used, defaults to\code{\link{negterms_GI}}} 22 | } 23 | \description{ 24 | Calculate senti_diffs_per_ref from Matrix 25 | } 26 | \author{ 27 | Mario Annau 28 | } 29 | 30 | -------------------------------------------------------------------------------- /R/corpus.R: -------------------------------------------------------------------------------- 1 | #' @noRd 2 | "getField" <- function(x, ...) UseMethod("getField", x) 3 | #' Get Meta Data Field in VCorpus as Vector 4 | #' Get Meta Data Field in VCorpus as Vector 5 | #' @param x VCorpus object 6 | #' @param fieldname character which specifies meta data field name in corpus 7 | #' @author Mario Annau 8 | #' @export getField VCorpus 9 | "getField.VCorpus" <- 10 | function(x, fieldname){ 11 | field <- do.call("c",lapply(x, function(y) meta(y, fieldname))) 12 | names(field) <- NULL 13 | field 14 | } 15 | 16 | #' @noRd 17 | "setField" <- function(x, ...) UseMethod("setField", x) 18 | #' Set Meta Data Field in VCorpus from Vector 19 | #' Set Meta Data Field in VCorpus from Vector 20 | #' @param x VCorpus object 21 | #' @param fieldname character which specifies meta data field name in corpus 22 | #' @param value vector which values should be used 23 | #' @author Mario Annau 24 | #' @note vector must be of same length as Corpus 25 | #' @export setField VCorpus 26 | "setField.VCorpus" <- 27 | function(x, fieldname, value){ 28 | for(i in 1:length(x)){ 29 | meta(x[[i]], fieldname) <- value[i] 30 | } 31 | x 32 | } 33 | -------------------------------------------------------------------------------- /man/trans.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/OHCLSent.transformations.R 3 | \name{Subj} 4 | \alias{Neg_Refs_Per_Ref} 5 | \alias{Polarity} 6 | \alias{Pos_Refs_Per_Ref} 7 | \alias{SentVol} 8 | \alias{Senti_Diffs_Per_Ref} 9 | \alias{Subj} 10 | \alias{has.Neg_Refs_Per_Ref} 11 | \alias{has.Polarity} 12 | \alias{has.Pos_Refs_Per_Ref} 13 | \alias{has.SentVol} 14 | \alias{has.Senti_Diffs_Per_Ref} 15 | \alias{has.Subj} 16 | \title{Simple XTS transformations for (OHLC) Stock Sentiment XTS Objects} 17 | \usage{ 18 | Subj(x) 19 | 20 | has.Subj(x, which = FALSE) 21 | 22 | Polarity(x) 23 | 24 | has.Polarity(x, which = FALSE) 25 | 26 | Pos_Refs_Per_Ref(x) 27 | 28 | has.Pos_Refs_Per_Ref(x, which = FALSE) 29 | 30 | Neg_Refs_Per_Ref(x) 31 | 32 | has.Neg_Refs_Per_Ref(x, which = FALSE) 33 | 34 | Senti_Diffs_Per_Ref(x) 35 | 36 | has.Senti_Diffs_Per_Ref(x, which = FALSE) 37 | 38 | SentVol(x, prefix = "SEMNT") 39 | 40 | has.SentVol(x, which = FALSE, prefix = "SEMNT") 41 | } 42 | \arguments{ 43 | \item{x}{xts object} 44 | } 45 | \description{ 46 | Simple XTS transformations for (OHLC) Stock Sentiment XTS Objects 47 | } 48 | \seealso{ 49 | \code{quantmod} 50 | } 51 | 52 | -------------------------------------------------------------------------------- /man/preprocessCorpus.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/preprocessCorpus.R 3 | \name{preprocessCorpus} 4 | \alias{preprocessCorpus} 5 | \title{Preprocess Corpus with functions specified in control. 6 | Little helper function to have a little more control of the preprocessing step. 7 | Especially the order of the control elements is preserved (as opposed to the 8 | preprocessing done in DocumentTermMatrix or TermDocumentMatrix.} 9 | \usage{ 10 | preprocessCorpus(corpus, control, verbose = FALSE) 11 | } 12 | \arguments{ 13 | \item{corpus}{\code{\link{Corpus}} object which should be processed} 14 | 15 | \item{control}{list of functions to be applied to corpus} 16 | 17 | \item{verbose}{print preprocessing status information} 18 | } 19 | \description{ 20 | Preprocess Corpus with functions specified in control. 21 | Little helper function to have a little more control of the preprocessing step. 22 | Especially the order of the control elements is preserved (as opposed to the 23 | preprocessing done in DocumentTermMatrix or TermDocumentMatrix. 24 | } 25 | \author{ 26 | Mario Annau 27 | } 28 | \seealso{ 29 | \code{\link{DocumentTermMatrix}} \code{\link{TermDocumentMatrix}} 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/getRelevant.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/getRelevant.R 3 | \name{getRelevant} 4 | \alias{getRelevant} 5 | \title{Get Relevant Part from Text Document. 6 | Search for the first and last occurence of items in Text Document, 7 | get sentence boundaries and extract text. 8 | Function can be used in tm_map wrapper} 9 | \usage{ 10 | getRelevant(td, items, boundaries, matches.only = FALSE, 11 | fieldname = "matches") 12 | } 13 | \arguments{ 14 | \item{td}{TextDocument} 15 | 16 | \item{items}{character vector of items to be searched, eg. c("Microsoft", "MSFT")} 17 | 18 | \item{boundaries}{defined sentence boundaries in perl-regex syntax} 19 | 20 | \item{matches.only}{Return number of matches only} 21 | 22 | \item{fieldname}{name which should be used for meta field in Text Document to be annotated} 23 | 24 | \item{matches}{only should only matches be annotated, defaults to FALSE} 25 | } 26 | \description{ 27 | Get Relevant Part from Text Document. 28 | Search for the first and last occurence of items in Text Document, 29 | get sentence boundaries and extract text. 30 | Function can be used in tm_map wrapper 31 | } 32 | \author{ 33 | Mario Annau 34 | } 35 | \seealso{ 36 | \code{\link{tm_map}} 37 | } 38 | 39 | -------------------------------------------------------------------------------- /R/preprocessCorpus.R: -------------------------------------------------------------------------------- 1 | #' Preprocess Corpus with functions specified in control. 2 | #' Little helper function to have a little more control of the preprocessing step. 3 | #' Especially the order of the control elements is preserved (as opposed to the 4 | #' preprocessing done in DocumentTermMatrix or TermDocumentMatrix. 5 | #' @author Mario Annau 6 | #' @param corpus \code{\link{Corpus}} object which should be processed 7 | #' @param control list of functions to be applied to corpus 8 | #' @param verbose print preprocessing status information 9 | #' @seealso \code{\link{DocumentTermMatrix}} \code{\link{TermDocumentMatrix}} 10 | #' @export 11 | preprocessCorpus <- 12 | function(corpus, control, verbose = FALSE){ 13 | 14 | if(missing(control)){ 15 | control = list( removePunctuation = list(), 16 | removeNumbers = list(), 17 | tolower = list(), 18 | removeWords = list(stopwords("english")), 19 | stripWhitespace = list(), 20 | stemDocument = list()) 21 | 22 | } 23 | 24 | if(verbose) 25 | cat("Starting Preprocessing...\n") 26 | 27 | for(n in names(control)){ 28 | if(verbose) 29 | cat(n, " ...") 30 | args <- control[[n]] 31 | if(length(args) == 0){ 32 | corpus <- eval(call("tm_map", corpus, n)) 33 | }else{ 34 | corpus <- eval(call("tm_map", corpus, n, unlist(args))) 35 | } 36 | if(verbose) 37 | cat("Done\n") 38 | } 39 | corpus 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/metaXTS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/metaXTS.R 3 | \name{metaXTS} 4 | \alias{metaXTS} 5 | \title{Calculate xts from scored corpus} 6 | \usage{ 7 | metaXTS(corpus, fieldnames, period = "days", k = 1, aggFUN = mean, symbol, 8 | prefix = "SEMNT", join = "inner", na.omit = TRUE) 9 | } 10 | \arguments{ 11 | \item{corpus}{Scored corpus from which \code{xts} object should be generated, see \code{\link{score}}} 12 | 13 | \item{fieldnames}{Fieldnames to be used from \code{meta(corpus)}, defaults to meta(corpus)} 14 | 15 | \item{period}{Period unit of xts time series object to be returned, defaults to "days", see \code{endpoints}} 16 | 17 | \item{k,}{Period length of xts time series object to be returned, defaults to 1, see \code{endpoints}} 18 | 19 | \item{aggFUN}{Aggregation function to be used for meta fields, defaults to mean} 20 | 21 | \item{symbol}{\code{xts} object to be merged with sentiment time series, preferably \code{OHLC} time series} 22 | 23 | \item{prefix}{Character string specifying prefix of resulting sentiment time series column names} 24 | 25 | \item{join}{Join which should be performed if symbol is specified} 26 | 27 | \item{na.omit}{remove NA's from resulting time series, see \code{\link{na.omit}}} 28 | } 29 | \description{ 30 | Calculate xts from scored corpus 31 | } 32 | \author{ 33 | Mario Annau 34 | } 35 | \seealso{ 36 | \code{\link{score}} \code{endpoints} (in package \code{xts}) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License](http://img.shields.io/badge/license-GPL%20%28%3E=%203%29-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html) 2 | tm.plugin.sentiment 3 | =================== 4 | 5 | **tm.plugin.sentiment** calculates the sentiment from ([tm](http://cran.r-project.org/package=tm) text corpora based on simple word counts. The package already includes a sentiment dictionary from the General Inquirer which can be replaced by custom ones. Build up of sentiment time series in [xts](http://cran.r-project.org/package=xts) and charting using facilities of [quantmod](http://cran.r-project.org/package=quantmod) are also supported. 6 | 7 | ## Install 8 | Using the **devtools** package you can easily install the latest development version of **tm.plugin.sentiment** from github with 9 | 10 | ```python 11 | library(devtools) 12 | install_github("mannau/tm.plugin.sentiment") 13 | ``` 14 | 15 | ## Usage 16 | 17 | The following lines show the basic functionality calculating the sentiment for the Apple (AAPL) stock: 18 | 19 | ```python 20 | library(tm.plugin.sentiment) 21 | 22 | # retrieve corpus 23 | require(tm.plugin.webmining) 24 | corp = WebCorpus(GoogleFinanceSource("AAPL")) 25 | 26 | # score corpus 27 | corp <- score(corp) 28 | sentixts <- metaXTS(corp) 29 | 30 | # chart sentiment scores 31 | chartSentiment(sentixts) 32 | ``` 33 | 34 | ## License 35 | **tm.plugin.sentiment** is released under the [GNU General Public License Version 3](http://www.gnu.org/copyleft/gpl.html) 36 | 37 | 38 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2 (4.1.1): do not edit by hand 2 | 3 | S3method(neg_refs_per_ref,DocumentTermMatrix) 4 | S3method(neg_refs_per_ref,TermDocumentMatrix) 5 | S3method(polarity,DocumentTermMatrix) 6 | S3method(polarity,TermDocumentMatrix) 7 | S3method(pos_refs_per_ref,DocumentTermMatrix) 8 | S3method(pos_refs_per_ref,TermDocumentMatrix) 9 | S3method(senti_diffs_per_ref,DocumentTermMatrix) 10 | S3method(senti_diffs_per_ref,TermDocumentMatrix) 11 | S3method(subjectivity,DocumentTermMatrix) 12 | S3method(subjectivity,TermDocumentMatrix) 13 | export(Neg_Refs_Per_Ref) 14 | export(Polarity) 15 | export(Pos_Refs_Per_Ref) 16 | export(SentVol) 17 | export(Senti_Diffs_Per_Ref) 18 | export(Subj) 19 | export(VCorpus) 20 | export(addNeg_Refs_Per_Ref) 21 | export(addPolarity) 22 | export(addPos_Refs_Per_Ref) 23 | export(addSentVol) 24 | export(addSenti_Diffs_Per_Ref) 25 | export(addSentiment) 26 | export(addSentimentVo) 27 | export(addSubjectivity) 28 | export(chartSent) 29 | export(chartSentiment) 30 | export(getField) 31 | export(getRelevant) 32 | export(has.Neg_Refs_Per_Ref) 33 | export(has.Polarity) 34 | export(has.Pos_Refs_Per_Ref) 35 | export(has.SentVol) 36 | export(has.Senti_Diffs_Per_Ref) 37 | export(has.Subj) 38 | export(metaXTS) 39 | export(neg_refs_per_ref) 40 | export(negterms_GI) 41 | export(polarity) 42 | export(pos_refs_per_ref) 43 | export(posterms_GI) 44 | export(preprocessCorpus) 45 | export(score) 46 | export(senti_diffs_per_ref) 47 | export(setField) 48 | export(subjectivity) 49 | importFrom(slam,col_sums) 50 | -------------------------------------------------------------------------------- /man/score.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/score.R 3 | \name{score} 4 | \alias{score} 5 | \title{Score Corpus 6 | Annotate corpus with scores using various functions 7 | Implementation generates a \code{TermDocumentMatrix} as a first step and applies specified functions to it in order to generate score.} 8 | \usage{ 9 | score(corpus, control, scoreFUNS) 10 | } 11 | \arguments{ 12 | \item{corpus}{Text corpus to be annotated} 13 | 14 | \item{control}{Paramter to control \code{TermDocumentMatrix} generation, if missing default to 15 | \code{control = list( 16 | tolower = TRUE, 17 | removePunctuation = TRUE, 18 | removeNumbers = TRUE, 19 | removeWords = list(stopwords("english")), 20 | stripWhitespace = TRUE, 21 | stemDocument = TRUE, 22 | minWordLength = 3, 23 | weighting = weightTf)}} 24 | 25 | \item{scoreFUNS}{scoring functions to be used on \code{TermDocumentMatrix}, if missing defaults to 26 | \code{scoreFUNS = list( 27 | polarity = list(), 28 | subjectivity = list(), 29 | pos_refs_per_ref = list(), 30 | neg_refs_per_ref = list(), 31 | senti_diffs_per_ref = list() 32 | )}} 33 | 34 | \item{replace}{Specifies if existing corpus meta data.frame should be replaced, defaults to TRUE} 35 | } 36 | \description{ 37 | Score Corpus 38 | Annotate corpus with scores using various functions 39 | Implementation generates a \code{TermDocumentMatrix} as a first step and applies specified functions to it in order to generate score. 40 | } 41 | \author{ 42 | Mario Annau 43 | } 44 | \seealso{ 45 | \code{TermDocumentMatrix} 46 | } 47 | 48 | -------------------------------------------------------------------------------- /R/getRelevant.R: -------------------------------------------------------------------------------- 1 | #' Get Relevant Part from Text Document. 2 | #' Search for the first and last occurence of items in Text Document, 3 | #' get sentence boundaries and extract text. 4 | #' Function can be used in tm_map wrapper 5 | #' @author Mario Annau 6 | #' @param td TextDocument 7 | #' @param items character vector of items to be searched, eg. c("Microsoft", "MSFT") 8 | #' @param boundaries defined sentence boundaries in perl-regex syntax 9 | #' @param matches.only Return number of matches only 10 | #' @param matches only should only matches be annotated, defaults to FALSE 11 | #' @param fieldname name which should be used for meta field in Text Document to be annotated 12 | #' @seealso \code{\link{tm_map}} 13 | #' @export 14 | getRelevant <- 15 | function(td, items, boundaries, matches.only = FALSE, fieldname = "matches"){ 16 | if(missing(boundaries)){ 17 | boundaries = "\\." 18 | } 19 | itempatt <- paste("\\W(",paste("(", items, ")", collapse = "|", sep = ""),")\\W", sep = "") 20 | matches <- gregexpr(itempatt, Content(td), ignore.case = TRUE, perl = TRUE, fixed = FALSE, useBytes = FALSE) 21 | if(!matches.only){ 22 | startend <- range(matches) 23 | delimmatches <- gregexpr(boundaries, Content(td), ignore.case = TRUE, perl = TRUE, fixed = FALSE, useBytes = FALSE) 24 | delimmatches <- as.integer(delimmatches[[1]]) 25 | textlen <- nchar(Content(td)) 26 | sentstart <- max(c(delimmatches[delimmatches < startend[1]], 0)) 27 | sentend <- min(c(delimmatches[delimmatches > startend[2]], textlen)) 28 | subtext <- substr(Content(td), sentstart+1, sentend) 29 | Content(td) <- substr(Content(td), sentstart, sentend) 30 | } 31 | if(any(matches[[1]] == -1)){ 32 | meta(td, fieldname) <- 0 33 | } 34 | else{ 35 | meta(td, fieldname) <- length(matches[[1]]) 36 | } 37 | getRelevant <- td 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/chartSentiment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/chartSentiment.R 3 | \name{chartSentiment} 4 | \alias{chartSentiment} 5 | \title{Chart Sentiment 6 | Chart (stock) sentiment using quantmods plotting capabilities. 7 | Some hopefully useful presets have been made.} 8 | \usage{ 9 | chartSentiment(xts, prefix = "SEMNT", sentname = paste(prefix, "polarity", 10 | sep = "."), volname = paste(prefix, "vol", sep = "."), volcolor = "blue", 11 | na.fill = TRUE, omit.na.leading = TRUE, type = "line", 12 | theme = "white", name, TA = "", postTA = "", ...) 13 | } 14 | \arguments{ 15 | \item{xts}{XTS Object Containing at minimum 'Close' and 'Score' fields} 16 | 17 | \item{prefix}{prefix of sentiment field, defaults to "SEMNT"} 18 | 19 | \item{sentname}{name of sentiment score field, defaults to paste(prefix,"polarity", sep = ".")} 20 | 21 | \item{volname}{name of sentiment volume field, defaults to paste(prefix,"volume", sep = ".")} 22 | 23 | \item{volcolor}{Color of Sentiment Score Volume Bars, defaults to "blue"} 24 | 25 | \item{na.fill}{should parts of timeseries be plotted where \code{sentname} or \code{volname} 26 | in \code{xts} is \code{NA}? Could be useful if Sentiment score/volume have been aggregated or 27 | data is very sparse. Please note that timeseries then becomes compressed, defaults to TRUE} 28 | 29 | \item{omit.na.leading}{Omits leading NA's in timeseries, defaults to TRUE} 30 | 31 | \item{type}{linetype of Stock Chart, defaults to "line",} 32 | 33 | \item{theme}{Chart Theme, defaults to "white"} 34 | 35 | \item{name}{Main Title of Sentiment Chart, default is taken from prefix in time series} 36 | 37 | \item{TA}{add Technical analysis Indicators to chart at the beginning as string, defaults to ""} 38 | 39 | \item{postTA}{add Technical analysis Indicators at the end to the chart, defaults to ""} 40 | 41 | \item{...}{additional parameters to chartSeries function call} 42 | } 43 | \description{ 44 | Chart Sentiment 45 | Chart (stock) sentiment using quantmods plotting capabilities. 46 | Some hopefully useful presets have been made. 47 | } 48 | \author{ 49 | Mario Annau 50 | } 51 | \seealso{ 52 | Most presets and optional arguments refer to quantmods excellent 53 | \code{\link{chartSeries}} function 54 | } 55 | 56 | -------------------------------------------------------------------------------- /R/metaXTS.R: -------------------------------------------------------------------------------- 1 | #' Calculate xts from scored corpus 2 | #' 3 | #' @param corpus Scored corpus from which \code{xts} object should be generated, see \code{\link{score}} 4 | #' @param fieldnames Fieldnames to be used from \code{meta(corpus)}, defaults to meta(corpus) 5 | #' @param period Period unit of xts time series object to be returned, defaults to "days", see \code{endpoints} 6 | #' @param k, Period length of xts time series object to be returned, defaults to 1, see \code{endpoints} 7 | #' @param aggFUN Aggregation function to be used for meta fields, defaults to mean 8 | #' @param symbol \code{xts} object to be merged with sentiment time series, preferably \code{OHLC} time series 9 | #' @param prefix Character string specifying prefix of resulting sentiment time series column names 10 | #' @param join Join which should be performed if symbol is specified 11 | #' @param na.omit remove NA's from resulting time series, see \code{\link{na.omit}} 12 | #' @author Mario Annau 13 | #' @seealso \code{\link{score}} \code{endpoints} (in package \code{xts}) 14 | #' @export 15 | #' @importFrom slam col_sums 16 | metaXTS <- function(corpus, 17 | fieldnames, 18 | period = "days", 19 | k=1, 20 | aggFUN = mean, 21 | symbol, 22 | prefix = "SEMNT", 23 | join = "inner", 24 | na.omit = TRUE){ 25 | 26 | if(missing(fieldnames)){ 27 | fieldnames <- colnames(meta(corpus)) 28 | } 29 | 30 | idx <- do.call(c, lapply(corpus, meta, "datetimestamp")) 31 | df <- data.frame(idx, meta(corpus)[, fieldnames]) 32 | 33 | if(na.omit){ 34 | df <- na.omit(df) 35 | } 36 | 37 | xts <- xts(df[, -1], order.by = df[, 1]) 38 | volxts <- xts(rep(1,NROW(xts)), order.by = index(xts)) 39 | 40 | ep <- endpoints(xts, on = period, k = k) 41 | 42 | xts_agg = NULL 43 | if(length(ep) > 2){ 44 | ldata <- lapply(1:NCOL(xts), function(x) period.apply(xts[,x], ep, aggFUN)) 45 | ldata_all <- do.call("cbind", ldata) 46 | xts_agg <- xts(ldata_all, order.by = index(xts)[ep]) 47 | volxts_agg <- period.apply(volxts, ep, sum) 48 | }else{ 49 | #ep <- ep[ep > 0] 50 | 51 | xts_agg <- xts(t(as.data.frame(apply(xts, 2, aggFUN))), order.by = index(xts)[ep]) 52 | volxts_agg <- xts(sum(volxts), order.by = index(xts)[ep]) 53 | } 54 | 55 | colnames(xts_agg) <- colnames(xts) 56 | colnames(volxts_agg) <- "vol" 57 | 58 | scorevolxts_agg <- cbind(xts_agg, volxts_agg) 59 | colnames(scorevolxts_agg) <- paste(prefix,colnames(scorevolxts_agg), sep=".") 60 | if(period == "days") 61 | index(scorevolxts_agg) <- as.Date(index(scorevolxts_agg)) 62 | 63 | if(!missing(symbol)){ 64 | names <- colnames(symbol) 65 | symbol <- to.period(symbol, period = period, k = k) 66 | colnames(symbol) <- names 67 | scorevolxts_agg <- merge(symbol, scorevolxts_agg, join = join) 68 | } 69 | 70 | return(scorevolxts_agg) 71 | } 72 | 73 | -------------------------------------------------------------------------------- /work/paper/sentiment.Rnw: -------------------------------------------------------------------------------- 1 | \documentclass[article,shortnames]{jss} 2 | 3 | \usepackage[english]{babel} 4 | \usepackage{thumbpdf} 5 | \usepackage{setspace} 6 | \usepackage{amsmath} 7 | \usepackage{amsfonts} 8 | \usepackage{latexsym} 9 | \usepackage{url} 10 | \usepackage{upquote} 11 | 12 | \usepackage{tikz} 13 | \usetikzlibrary{arrows,positioning,fit} 14 | 15 | \newcommand{\acronym}[1]{\textsc{#1}} 16 | \newcommand{\class}[1]{\texttt{\textquotesingle#1\textquotesingle}} 17 | \newcommand{\file}[1]{`\texttt{#1}'} 18 | 19 | \author{Mario Annau\\Raiffeisen Bank International AG \And Kurt 20 | Hornik\\WU Wirtschaftsuniversit\"at\\Wien \And Kristina 21 | Lerman\\University Southern California \And Stefan Theu\ss{}l\\WU 22 | Wirtschaftsuniversit\"at\\Wien \And Robert Zinkov\\University of 23 | Southern California} 24 | 25 | \Plainauthor{Mario Annau, Kurt Hornik, Kristina Lerman, Stefan 26 | Theu\ss{}l, Robert Zinkov} 27 | 28 | \title{Sentiment Analysis Using \proglang{R}} 29 | \Plaintitle{Sentiment Analysis Using R} 30 | \Shorttitle{Sentiment Analysis Using R} 31 | 32 | \Abstract{ 33 | 34 | TODO 35 | } 36 | 37 | \Keywords{sentiment analysis, natural language processing, culturomics} 38 | 39 | %% publication information 40 | %% NOTE: Typically, this can be left commented and will be filled out 41 | %% by the technical editor 42 | %% \Volume{13} 43 | %% \Issue{9} 44 | %% \Month{September} 45 | %% \Year{2004} 46 | %% \Submitdate{2004-09-29} 47 | %% \Acceptdate{2004-09-29} 48 | 49 | \Address{ 50 | Mario Annau\\ 51 | Department of Quant Research\\ 52 | Raiffeisen Bank International AG\\ 53 | Am Stadtpark 9, 54 | A-1030 Wien, Austria\\ 55 | E-mail: \email{mario.annau@gmail.com}\\ 56 | 57 | Kurt Hornik, Stefan Theu\ss{}l\\ 58 | Institute for Statistics and Mathematics\\ 59 | WU Wirtschaftsuniversit\"at Wien\\ 60 | Augasse 2--6\\ 61 | A-1090 Wien, Austria\\ 62 | E-mail: \email{Stefan.Theussl@wu.ac.at}, \email{Kurt.Hornik@R-project.org}\\ 63 | 64 | Kristina Lerman, Robert Zinkov\\ 65 | Information Sciences Institute\\ 66 | University of Southern California\\ 67 | Marina del Rey, CA 90292, U.S.A\\ 68 | E-mail: \email{zinkov@usc.edu} 69 | } 70 | 71 | %% for those who use Sweave please include the following line (with % symbols): 72 | %% need no \usepackage{Sweave.sty} 73 | 74 | \begin{document} 75 | 76 | \section{Introduction} 77 | \label{sec-introduction} 78 | 79 | \section{Background, literature review} 80 | \label{sec-literature} 81 | 82 | 83 | \section{Implementation} 84 | \label{sec-implementation} 85 | 86 | 87 | \section{Applications} 88 | \label{sec-applications} 89 | 90 | \section{Computational details} 91 | \label{sec-computational_details} 92 | 93 | \section{Conclusion and Outlook} 94 | \label{sec-conclusion} 95 | 96 | \bibliography{sentiment} 97 | 98 | 99 | \end{document} 100 | -------------------------------------------------------------------------------- /R/OHCLSent.transformations.R: -------------------------------------------------------------------------------- 1 | #' Simple XTS transformations for (OHLC) Stock Sentiment XTS Objects 2 | #' @aliases 3 | #' Subj has.Subj 4 | #' Polarity has.Polarity 5 | #' Pos_Refs_Per_Ref has.Pos_Refs_Per_Ref 6 | #' Neg_Refs_Per_Ref has.Neg_Refs_Per_Ref 7 | #' Senti_Diffs_Per_Ref has.Senti_Diffs_Per_Ref 8 | #' SentVol has.SentVol 9 | #' @param x xts object 10 | #' @seealso \code{quantmod} 11 | #' @rdname trans 12 | #' @export 13 | `Subj` <- 14 | function(x) 15 | { 16 | if(has.Subj(x)) 17 | return(x[,grep('Subjectivity',colnames(x),ignore.case=TRUE)]) 18 | stop('subscript out of bounds: no column name containing "Score"') 19 | } 20 | 21 | #' @rdname trans 22 | #' @export 23 | `has.Subj` <- 24 | function(x,which=FALSE) 25 | { 26 | loc <- grep('Subjectivity',colnames(x),ignore.case=TRUE) 27 | if(!identical(loc,integer(0))) 28 | return(ifelse(which,loc,TRUE)) 29 | ifelse(which,loc,FALSE) 30 | } 31 | 32 | #' @rdname trans 33 | #' @export 34 | `Polarity` <- 35 | function(x) 36 | { 37 | if(has.Polarity(x)) 38 | return(x[,grep('Polarity',colnames(x),ignore.case=TRUE)]) 39 | stop('subscript out of bounds: no column name containing "Polarity"') 40 | } 41 | 42 | #' @rdname trans 43 | #' @export 44 | `has.Polarity` <- 45 | function(x,which=FALSE) 46 | { 47 | loc <- grep('Polarity',colnames(x),ignore.case=TRUE) 48 | if(!identical(loc,integer(0))) 49 | return(ifelse(which,loc,TRUE)) 50 | ifelse(which,loc,FALSE) 51 | } 52 | 53 | #' @rdname trans 54 | #' @export 55 | `Pos_Refs_Per_Ref` <- 56 | function(x) 57 | { 58 | if(has.Pos_Refs_Per_Ref(x)) 59 | return(x[,grep('Pos_Refs_Per_Ref',colnames(x),ignore.case=TRUE)]) 60 | stop('subscript out of bounds: no column name containing "Pos_Refs_Per_Ref"') 61 | } 62 | 63 | #' @rdname trans 64 | #' @export 65 | `has.Pos_Refs_Per_Ref` <- 66 | function(x,which=FALSE) 67 | { 68 | loc <- grep('Pos_Refs_Per_Ref',colnames(x),ignore.case=TRUE) 69 | if(!identical(loc,integer(0))) 70 | return(ifelse(which,loc,TRUE)) 71 | ifelse(which,loc,FALSE) 72 | } 73 | 74 | #' @rdname trans 75 | #' @export 76 | `Neg_Refs_Per_Ref` <- 77 | function(x) 78 | { 79 | if(has.Neg_Refs_Per_Ref(x)) 80 | return(x[,grep('Neg_Refs_Per_Ref',colnames(x),ignore.case=TRUE)]) 81 | stop('subscript out of bounds: no column name containing "Neg_Refs_Per_Ref"') 82 | } 83 | 84 | #' @rdname trans 85 | #' @export 86 | `has.Neg_Refs_Per_Ref` <- 87 | function(x,which=FALSE) 88 | { 89 | loc <- grep('Neg_Refs_Per_Ref',colnames(x),ignore.case=TRUE) 90 | if(!identical(loc,integer(0))) 91 | return(ifelse(which,loc,TRUE)) 92 | ifelse(which,loc,FALSE) 93 | } 94 | 95 | #' @rdname trans 96 | #' @export 97 | `Senti_Diffs_Per_Ref` <- 98 | function(x) 99 | { 100 | if(has.Senti_Diffs_Per_Ref(x)) 101 | return(x[,grep('Senti_Diffs_Per_Ref',colnames(x),ignore.case=TRUE)]) 102 | stop('subscript out of bounds: no column name containing "Senti_Diffs_Per_Ref"') 103 | } 104 | 105 | #' @rdname trans 106 | #' @export 107 | `has.Senti_Diffs_Per_Ref` <- 108 | function(x,which=FALSE) 109 | { 110 | loc <- grep('Senti_Diffs_Per_Ref',colnames(x),ignore.case=TRUE) 111 | if(!identical(loc,integer(0))) 112 | return(ifelse(which,loc,TRUE)) 113 | ifelse(which,loc,FALSE) 114 | } 115 | 116 | #' @rdname trans 117 | #' @export 118 | `SentVol` <- 119 | function(x, prefix = "SEMNT") 120 | { 121 | name = paste(prefix, "vol", sep=".") 122 | 123 | if(has.SentVol(x, prefix = prefix)) 124 | return(x[,grep(name,colnames(x),ignore.case=TRUE)]) 125 | stop(paste('subscript out of bounds: no column name containing"', name, '"')) 126 | } 127 | 128 | #' @rdname trans 129 | #' @export 130 | `has.SentVol` <- 131 | function(x,which=FALSE, prefix = "SEMNT") 132 | { 133 | name = paste(prefix, "vol", sep=".") 134 | loc <- grep(name,colnames(x),ignore.case=TRUE) 135 | if(!identical(loc,integer(0))) 136 | return(ifelse(which,loc,TRUE)) 137 | ifelse(which,loc,FALSE) 138 | } 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /R/chartSentiment.R: -------------------------------------------------------------------------------- 1 | #' Chart Sentiment 2 | #' Chart (stock) sentiment using quantmods plotting capabilities. 3 | #' Some hopefully useful presets have been made. 4 | #' @author Mario Annau 5 | #' @param xts XTS Object Containing at minimum 'Close' and 'Score' fields 6 | #' @param prefix prefix of sentiment field, defaults to "SEMNT" 7 | #' @param sentname name of sentiment score field, defaults to paste(prefix,"polarity", sep = ".") 8 | #' @param volname name of sentiment volume field, defaults to paste(prefix,"volume", sep = ".") 9 | #' @param volcolor Color of Sentiment Score Volume Bars, defaults to "blue" 10 | #' @param na.fill should parts of timeseries be plotted where \code{sentname} or \code{volname} 11 | #' in \code{xts} is \code{NA}? Could be useful if Sentiment score/volume have been aggregated or 12 | #' data is very sparse. Please note that timeseries then becomes compressed, defaults to TRUE 13 | #' @param omit.na.leading Omits leading NA's in timeseries, defaults to TRUE 14 | #' @param type linetype of Stock Chart, defaults to "line", 15 | #' @param theme Chart Theme, defaults to "white" 16 | #' @param name Main Title of Sentiment Chart, default is taken from prefix in time series 17 | #' @param TA add Technical analysis Indicators to chart at the beginning as string, defaults to "" 18 | #' @param postTA add Technical analysis Indicators at the end to the chart, defaults to "" 19 | #' @param ... additional parameters to chartSeries function call 20 | #' @seealso Most presets and optional arguments refer to quantmods excellent 21 | #' \code{\link{chartSeries}} function 22 | #' @export 23 | chartSentiment <- 24 | function (xts, prefix = "SEMNT", 25 | sentname = paste(prefix,"polarity", sep = "."), 26 | volname = paste(prefix,"vol", sep = "."), 27 | volcolor="blue", 28 | na.fill = TRUE, 29 | omit.na.leading = TRUE, 30 | type = "line", 31 | theme='white', 32 | name, 33 | TA = "", postTA = "", ...) 34 | { 35 | 36 | counter = 1 37 | 38 | if(omit.na.leading){ 39 | firstnona <- min(which(!is.na(xts[,sentname]))) 40 | xts <- xts[firstnona:NROW(xts),] 41 | } 42 | 43 | if(na.fill){ 44 | xts[is.na(xts)] <- 0 45 | } 46 | 47 | if(missing(name)){ 48 | name = "" 49 | if(has.Cl(xts)) 50 | name <- strsplit(colnames(Cl(xts)), "\\.", perl = TRUE)[[1]][1] 51 | else 52 | name <- strsplit(colnames(xts[,1]), "\\.", perl = TRUE)[[1]][1] 53 | 54 | name <- paste("Sentiment", name) 55 | } 56 | 57 | if(sentname != ""){ 58 | TA <- paste(TA, "addSentiment('", sentname, "');", sep = "") 59 | counter = counter + 1 60 | } 61 | 62 | if(has.SentVol(xts)){ 63 | TA <- paste(TA, "addSentimentVo('", volname, "');", sep = "") 64 | counter = counter + 1 65 | } 66 | 67 | if(has.Vo(xts)){ 68 | TA <- paste(TA, "addVo();", sep = "") 69 | counter = counter + 1 70 | } 71 | 72 | if(all(has.Subj(xts), 73 | has.Neg_Refs_Per_Ref(xts), 74 | has.Pos_Refs_Per_Ref(xts), 75 | has.Senti_Diffs_Per_Ref(xts))){ 76 | range <- range(na.omit(rbind(Pos_Refs_Per_Ref(xts), 77 | Neg_Refs_Per_Ref(xts), 78 | Senti_Diffs_Per_Ref(xts), 79 | Subj(xts)))) 80 | 81 | addSubjectivityAll <- newTA(Subj, col=1, yrange = range) 82 | assign("addSubjectivityAll", addSubjectivityAll, envir = .GlobalEnv) 83 | 84 | TA <- paste(TA, "addSubjectivityAll();", sep = "") 85 | counter = counter + 1 86 | 87 | TA <- paste(TA, "addPos_Refs_Per_Ref(on=", counter, ");", sep = "") 88 | TA <- paste(TA, "addNeg_Refs_Per_Ref(on=", counter, ");", sep = "") 89 | TA <- paste(TA, "addSenti_Diffs_Per_Ref(on=", counter, ");", sep = "") 90 | }else{ 91 | if(has.Subj(xts)){ 92 | TA <- paste(TA, "addSubjectivity();", sep = "")# 93 | } 94 | 95 | if(has.Pos_Refs_Per_Ref(xts)){ 96 | TA <- paste(TA, "addPos_Refs_Per_Ref();", sep = "") 97 | } 98 | 99 | if(has.Neg_Refs_Per_Ref(xts)){ 100 | TA <- paste(TA, "addNeg_Refs_Per_Ref();", sep = "") 101 | } 102 | 103 | if(has.Senti_Diffs_Per_Ref(xts)){ 104 | TA <- paste(TA, "addSenti_Diffs_Per_Ref();", sep = "") 105 | } 106 | } 107 | 108 | TA <- paste(TA, postTA, sep = ";") 109 | 110 | 111 | chartSeries(xts, type = "line", theme = "white", 112 | name = name, 113 | TA = TA, ...) 114 | 115 | # plotxts <- xts[,sentname] 116 | # colnames(plotxts) <- paste(prefix, "Close", sep = ".") 117 | # 118 | # chartSeries(xts, type = "line", theme = "white", 119 | # name = name, 120 | # TA = TA) 121 | 122 | } 123 | 124 | -------------------------------------------------------------------------------- /R/score.R: -------------------------------------------------------------------------------- 1 | #' Score Corpus 2 | #' Annotate corpus with scores using various functions 3 | #' Implementation generates a \code{TermDocumentMatrix} as a first step and applies specified functions to it in order to generate score. 4 | #' @param corpus Text corpus to be annotated 5 | #' @param control Paramter to control \code{TermDocumentMatrix} generation, if missing default to 6 | #' \code{control = list( 7 | #' tolower = TRUE, 8 | #' removePunctuation = TRUE, 9 | #' removeNumbers = TRUE, 10 | #' removeWords = list(stopwords("english")), 11 | #' stripWhitespace = TRUE, 12 | #' stemDocument = TRUE, 13 | #' minWordLength = 3, 14 | #' weighting = weightTf)} 15 | #' @param scoreFUNS scoring functions to be used on \code{TermDocumentMatrix}, if missing defaults to 16 | #' \code{scoreFUNS = list( 17 | #' polarity = list(), 18 | #' subjectivity = list(), 19 | #' pos_refs_per_ref = list(), 20 | #' neg_refs_per_ref = list(), 21 | #' senti_diffs_per_ref = list() 22 | #' )} 23 | #' @param replace Specifies if existing corpus meta data.frame should be replaced, defaults to TRUE 24 | #' @author Mario Annau 25 | #' @seealso \code{TermDocumentMatrix} 26 | #' @export 27 | `score` <- function(corpus, 28 | control, 29 | scoreFUNS){ 30 | 31 | if(missing(control)){ 32 | control = list( 33 | tolower = TRUE, 34 | removePunctuation = TRUE, 35 | removeNumbers = TRUE, 36 | removeWords = list(stopwords("english")), 37 | stripWhitespace = TRUE, 38 | stemDocument = TRUE, 39 | minWordLength = 3, 40 | weighting = weightTf) 41 | } 42 | if(missing(scoreFUNS)){ 43 | scoreFUNS = list( 44 | polarity = list(), 45 | subjectivity = list(), 46 | pos_refs_per_ref = list(), 47 | neg_refs_per_ref = list(), 48 | senti_diffs_per_ref = list() 49 | ) 50 | } 51 | 52 | tdm <- TermDocumentMatrix(corpus, control = control) 53 | 54 | 55 | res <- list() 56 | for(n in names(scoreFUNS)){ 57 | args <- unlist(scoreFUNS[[n]]) 58 | if(is.null(args)){ 59 | res[[n]] <- eval(call(n, tdm)) 60 | }else{ 61 | res[[n]] <- eval(call(n, tdm, args)) 62 | } 63 | } 64 | 65 | dfres <- as.data.frame(res) 66 | meta <- meta(corpus) 67 | 68 | for(n in colnames(dfres)) { 69 | meta(corpus, n) <- dfres[, n] 70 | } 71 | corpus 72 | } 73 | 74 | #' Calculate Polarity from Matrix 75 | #' @author Mario Annau 76 | #' @param x TermDocumentMatrix 77 | #' @param positive character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}} 78 | #' @param negative character vector specifying negative terms to be used, defaults to\code{\link{negterms_GI}} 79 | #' @rdname polarity 80 | #' @export 81 | polarity <- function(x, positive, negative) UseMethod("polarity", x) 82 | 83 | #' @rdname polarity 84 | #' @export 85 | polarity.TermDocumentMatrix <- function(x, positive = posterms_GI(), negative = negterms_GI() ){ 86 | pos <- tm_term_score(x, positive) 87 | neg <- tm_term_score(x, negative) 88 | all <- (pos+neg) 89 | ifelse(all != 0, (pos-neg)/all, 0) 90 | } 91 | 92 | #' @rdname polarity 93 | #' @export 94 | polarity.DocumentTermMatrix <- function(x, ...) polarity(t(x), ...) 95 | 96 | #' Calculate Polarity from Matrix 97 | #' @author Mario Annau 98 | #' @param x TermDocumentMatrix 99 | #' @param positive character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}} 100 | #' @param negative character vector specifying negative terms to be used, defaults to\code{\link{negterms_GI}} 101 | #' @rdname subjectivity 102 | #' @export 103 | subjectivity <- function(x, positive, negative) UseMethod("subjectivity", x) 104 | 105 | #' @rdname subjectivity 106 | #' @export 107 | subjectivity.TermDocumentMatrix <- function(x, positive = posterms_GI(), negative = negterms_GI() ){ 108 | pos <- tm_term_score(x, positive) 109 | neg <- tm_term_score(x, negative) 110 | all <- col_sums(x) 111 | ifelse(all != 0, (pos+neg)/all, 0) 112 | } 113 | 114 | #' @rdname subjectivity 115 | #' @export 116 | subjectivity.DocumentTermMatrix <- function(x, ...) subjectivity(t(x), ...) 117 | 118 | #' Calculate pos_refs_per_ref from Matrix 119 | #' @author Mario Annau 120 | #' @param x TermDocumentMatrix 121 | #' @param positive character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}} 122 | #' @rdname pos_refs_per_ref 123 | #' @export 124 | pos_refs_per_ref <- function(x, positive) UseMethod("pos_refs_per_ref", x) 125 | 126 | #' @rdname pos_refs_per_ref 127 | #' @export 128 | pos_refs_per_ref.TermDocumentMatrix <- function(x, positive = posterms_GI()){ 129 | pos <- tm_term_score(x, positive) 130 | all <- col_sums(x) 131 | ifelse(all != 0, (pos)/(all), 0) 132 | } 133 | 134 | #' @rdname pos_refs_per_ref 135 | #' @export 136 | pos_refs_per_ref.DocumentTermMatrix <- function(x, ...) pos_refs_per_ref(t(x), ...) 137 | 138 | #' Calculate neg_refs_per_ref from Matrix 139 | #' @author Mario Annau 140 | #' @param x TermDocumentMatrix 141 | #' @param negative character vector specifying negative terms to be used, defaults to \code{\link{negterms_GI}} 142 | #' @rdname neg_refs_per_ref 143 | #' @export 144 | neg_refs_per_ref <- function(x, negative) UseMethod("neg_refs_per_ref", x) 145 | 146 | #' @rdname neg_refs_per_ref 147 | #' @export 148 | neg_refs_per_ref.TermDocumentMatrix <- function(x, negative = negterms_GI()){ 149 | neg <- tm_term_score(x, negative) 150 | all <- col_sums(x) 151 | ifelse(all != 0, (neg)/(all), 0) 152 | } 153 | 154 | #' @rdname neg_refs_per_ref 155 | #' @export 156 | neg_refs_per_ref.DocumentTermMatrix <- function(x, ...) neg_refs_per_ref(t(x), ...) 157 | 158 | #' Calculate senti_diffs_per_ref from Matrix 159 | #' @author Mario Annau 160 | #' @param x TermDocumentMatrix 161 | #' @param positive character vector specifying positive terms to be used, defaults to \code{\link{posterms_GI}} 162 | #' @param negative character vector specifying negative terms to be used, defaults to\code{\link{negterms_GI}} 163 | #' @rdname senti_diffs_per_ref 164 | #' @export 165 | senti_diffs_per_ref <- function(x, positive, negative) UseMethod("senti_diffs_per_ref", x) 166 | 167 | #' @rdname senti_diffs_per_ref 168 | #' @export 169 | senti_diffs_per_ref.TermDocumentMatrix <- function(x, positive = posterms_GI(), negative = negterms_GI()){ 170 | pos <- tm_term_score(x, positive) 171 | neg <- tm_term_score(x, negative) 172 | all <- col_sums(x) 173 | ifelse(all != 0, (pos-neg)/all, 0) 174 | } 175 | 176 | #' @rdname senti_diffs_per_ref 177 | #' @export 178 | senti_diffs_per_ref.DocumentTermMatrix <- function(x, ...) senti_diffs_per_ref(t(x), ...) 179 | 180 | #' Get Positive Terms from General Inquirer 181 | #' @author Mario Annau 182 | #' @export 183 | posterms_GI <- function(){ 184 | data("dic_gi") 185 | data <- get("dic_gi", pos=globalenv()) 186 | data[["positive"]] 187 | } 188 | 189 | #' Get Negative Terms from General Inquirer 190 | #' @author Mario Annau 191 | #' @export 192 | negterms_GI <- function(){ 193 | data("dic_gi") 194 | data <- get("dic_gi", pos=globalenv()) 195 | data[["negative"]] 196 | } -------------------------------------------------------------------------------- /R/addSentiment.R: -------------------------------------------------------------------------------- 1 | #' Add Sentiment Field to chobs 2 | #' Adds one of the following sentiment fields to the current chob: 3 | #' Subjectivity, Polarity, Pos_Refs_Per_Ref, Pos_Refs_Per_Ref, Neg_Refs_Per_Ref, 4 | #' Senti_Diffs_Per_Ref, SentVol 5 | #' @aliases addSubjectivity addPolarity addPos_Refs_Per_Ref addNeg_Refs_Per_Ref 6 | #' addSenti_Diffs_Per_Ref addSentVol 7 | #' @author Mario Annau 8 | #' @include OHCLSent.transformations.R 9 | #' @export addSubjectivity addPolarity addPos_Refs_Per_Ref addNeg_Refs_Per_Ref addSenti_Diffs_Per_Ref addSentVol 10 | addSubjectivity <- newTA(Subj, col=1) 11 | addPolarity <- newTA(Polarity, col=4) 12 | addPos_Refs_Per_Ref <- newTA(Pos_Refs_Per_Ref, col=3) 13 | addNeg_Refs_Per_Ref <- newTA(Neg_Refs_Per_Ref, col=2) 14 | addSenti_Diffs_Per_Ref <- newTA(Senti_Diffs_Per_Ref, col=5) 15 | addSentVol <- newTA(SentVol, col=6) 16 | 17 | #' Add Sentiment Scores as barchart to current chob 18 | #' @author Mario Annau 19 | #' @param fieldname Specifies fieldname in XTS object which contains sentiment scores 20 | #' @param on Screen on which to plot 21 | #' @seealso \code{\link{addSentimentVo}} \code{\link{chartSentiment}} 22 | #' @references adapted from Jeffrey A. Ryan's \code{\link{quantmod}} package 23 | #' @export 24 | # TODO remove sentimentFUN parameter 25 | `addSentiment` <- 26 | function(fieldname, on = NA){ 27 | lchob <- quantmod:::get.current.chob() 28 | x <- as.matrix(lchob@xdata) 29 | # if (!lchob@show.vol || !has.Vo(x)) 30 | # return(invisible(new("chobTA", new = FALSE, name = "chartNULL", 31 | # call = match.call()))) 32 | Volumes = NULL 33 | if(missing(fieldname)){ 34 | Volumes <- Polarity(x) 35 | fieldname = "Polarity" 36 | }else{ 37 | Volumes <- x[,fieldname] 38 | } 39 | 40 | #Volumes <- x[,fieldname] 41 | max.vol <- max(Volumes, na.rm = TRUE) 42 | 43 | bar.col <- ifelse(Volumes > 0, lchob@colors$up.col, lchob@colors$dn.col) 44 | 45 | border.col <- ifelse(is.null(lchob@colors$border), bar.col, 46 | lchob@colors$border) 47 | bar.col <- bar.col[lchob@xsubset] 48 | chobTA <- new("chobTA") 49 | 50 | if (any(is.na(on))) { 51 | chobTA@new <- TRUE 52 | } 53 | else { 54 | chobTA@new <- FALSE 55 | chobTA@on <- on 56 | } 57 | 58 | chobTA@TA.values <- (Volumes)[lchob@xsubset] 59 | chobTA@name <- "chartSent" 60 | chobTA@call <- match.call() 61 | chobTA@params <- list(xrange = lchob@xrange, colors = lchob@colors, 62 | color.vol = lchob@color.vol, multi.col = lchob@multi.col, 63 | spacing = lchob@spacing, width = lchob@width, bp = lchob@bp, 64 | x.labels = lchob@x.labels, log.scale = FALSE, 65 | bar.col = bar.col, border.col = border.col, time.scale = lchob@time.scale, vol.scale=list(1, fieldname)) 66 | chobTA@params$thin <- ifelse(lchob@type %in% c("bars", "matchsticks"), 67 | TRUE, FALSE) 68 | if (is.null(sys.call(-1))) { 69 | TA <- lchob@passed.args$TA 70 | lchob@passed.args$TA <- c(TA, chobTA) 71 | lchob@windows <- lchob@windows + ifelse(chobTA@new, 1, 72 | 0) 73 | FUN <- quantmod:::chartSeries.chob 74 | do.call("FUN", list(lchob)) 75 | invisible(chobTA) 76 | } 77 | else { 78 | return(chobTA) 79 | } 80 | 81 | } 82 | 83 | #' Add Sentiment Volume as barchart to current chob 84 | #' @author Mario Annau 85 | #' @param fieldname Specifies fieldname in XTS object which contains sentiment volume, default "Volume" 86 | #' @param color Color of barchart, default "blue" 87 | #' @seealso \code{\link{addSentimentVo}} \code{\link{chartSentiment}} 88 | #' @export 89 | addSentimentVo <- function(fieldname, color = "blue"){ 90 | lchob <- quantmod:::get.current.chob() 91 | x <- as.matrix(lchob@xdata) 92 | # if (!lchob@show.vol || !has.Vo(x)) 93 | # return(invisible(new("chobTA", new = FALSE, name = "chartNULL", call = match.call()))) 94 | # 95 | #vol.scale <- x@params$vol.scale 96 | 97 | Volumes = NULL 98 | if(missing(fieldname)){ 99 | Volumes <- SentVol(x) 100 | }else{ 101 | Volumes <- x[,fieldname] 102 | } 103 | 104 | max.vol <- max(Volumes, na.rm = TRUE) 105 | 106 | 107 | bar.col <- ifelse(Volumes > 0, color, "red") 108 | 109 | border.col <- ifelse(is.null(lchob@colors$border), bar.col, 110 | lchob@colors$border) 111 | #bar.col <- bar.col[lchob@xsubset] 112 | bar.col <- color 113 | 114 | chobTA <- new("chobTA") 115 | chobTA@new <- TRUE 116 | chobTA@TA.values <- (Volumes)[lchob@xsubset] 117 | chobTA@name <- "chartVo" 118 | chobTA@call <- match.call() 119 | chobTA@params <- list(xrange = lchob@xrange, colors = lchob@colors, 120 | color.vol = TRUE, multi.col = lchob@multi.col, 121 | spacing = lchob@spacing, width = lchob@width, bp = lchob@bp, 122 | x.labels = lchob@x.labels, log.scale = FALSE, 123 | bar.col = bar.col, border.col = border.col, time.scale = lchob@time.scale, vol.scale=list(1, "Text Documents")) 124 | chobTA@params$thin <- ifelse(lchob@type %in% c("bars", "matchsticks"), 125 | TRUE, FALSE) 126 | if (is.null(sys.call(-1))) { 127 | TA <- lchob@passed.args$TA 128 | lchob@passed.args$TA <- c(TA, chobTA) 129 | lchob@windows <- lchob@windows + ifelse(chobTA@new, 1, 130 | 0) 131 | FUN <- quantmod:::chartSeries.chob 132 | do.call("FUN", list(lchob)) 133 | # legend("topleft", 134 | # legend=c(paste("Test (",vol.scale[[2]],"):",sep=''),format(last(Volumes)*vol.scale[[1]],big.mark=',')), 135 | # text.col=c(x@params$colors$fg.col, last(bar.col)), bty="n", y.inter=0.95) 136 | 137 | invisible(chobTA) 138 | } 139 | else { 140 | return(chobTA) 141 | } 142 | 143 | } 144 | 145 | #' Chart Sentiment is a Helper function for \code{\link{addSentiment}} 146 | #' @author Mario Annau 147 | #' @param x chob 148 | #' @seealso \code{\link{addSentiment}} 149 | #' @export 150 | `chartSent` <- 151 | function(x) { 152 | # if volume is to be plotted, do so here 153 | # scale volume - vol.divisor 154 | if(class(x) != "chobTA") stop("chartSentiment requires a suitable chobTA object") 155 | Volumes <- x@TA.values 156 | 157 | spacing <- x@params$spacing 158 | width <- x@params$width 159 | 160 | x.range <- x@params$xrange 161 | x.range <- seq(x.range[1],x.range[2]*spacing) 162 | 163 | # multi.col <- x@params$multi.col 164 | color.vol <- x@params$color.vol 165 | log.scale <- ifelse(x@params$log.scale,"y","") 166 | 167 | vol.scale <- x@params$vol.scale 168 | 169 | if(x@new) { 170 | plot.new() 171 | plot.window(xlim=c(1, x@params$xrange[2] * spacing), 172 | ylim=c(min(Volumes,na.rm=TRUE),max(Volumes,na.rm=TRUE)), 173 | log=log.scale) 174 | coords <- par('usr') 175 | rect(coords[1],coords[3],coords[2],coords[4],col=x@params$colors$area) 176 | abline(h=axTicks(2), col=x@params$colors$grid.col, lty='dotted') 177 | } 178 | 179 | x.pos <- 1 + spacing * (1:length(Volumes) - 1) 180 | 181 | # bar.col <- if(x@params$color.vol) { 182 | # x@params$bar.col 183 | # } else x@params$border.col 184 | 185 | bar.col <- x@params$bar.col 186 | border.col <- x@params$border.col 187 | 188 | if(x@params$thin) { 189 | # plot thin volume bars if appropriate 190 | segments(x.pos,0,x.pos,Volumes,col=bar.col) 191 | } else { 192 | rect(x.pos-spacing/3,0,x.pos+spacing/3,Volumes, 193 | col=bar.col,border=border.col) 194 | } 195 | legend.text <- list(list( 196 | legend=c(paste("Sentiment Score(",vol.scale[[2]],"):",sep=''),format(last(Volumes)*vol.scale[[1]],big.mark=',')), 197 | text.col=c(x@params$colors$fg.col, last(bar.col)) 198 | )) 199 | legend("topleft", 200 | legend=c(paste("Sentiment Score(",vol.scale[[2]],"):",sep=''),format(last(Volumes)*vol.scale[[1]],big.mark=',')), 201 | text.col=c(x@params$colors$fg.col, last(bar.col)), bty="n", y.inter=0.95) 202 | 203 | 204 | # text(0, max(Volumes,na.rm=TRUE) * .9, "Volume:",pos=4) 205 | 206 | # text(0, max(Volumes,na.rm=TRUE) * .9, 207 | # paste("\n\n\n",format(last(Volumes)*vol.scale[[1]],big.mark=','), sep = ""), 208 | # pos = 4,col=last(bar.col)) 209 | 210 | axis(2) 211 | box(col=x@params$colors$fg.col) 212 | invisible(vector('list',2)) 213 | } # }}} 214 | 215 | 216 | -------------------------------------------------------------------------------- /work/paper/sentiment.bib: -------------------------------------------------------------------------------- 1 | @Article{737-Barroso_et_al-2003, 2 | title = {Web Search for a Planet: The {Google} Cluster 3 | Architecture}, 4 | author = {Luiz Andr\'{e} Barroso and Jeffrey Dean and Urs 5 | H\"olzle}, 6 | journal = {{IEEE} micro}, 7 | volume = {23}, 8 | number = {2}, 9 | pages = {22--28}, 10 | year = {2003} 11 | } 12 | 13 | @Article{737-Blei+Lafferty-2007, 14 | author = {David M. Blei and John D. Lafferty}, 15 | title = {A Correlated Topic Model of Science}, 16 | journal = {The Annals of Applied Statistics}, 17 | year = 2007, 18 | volume = 1, 19 | number = 1, 20 | pages = {17--35}, 21 | } 22 | 23 | @Article{737-Borthakur-2010, 24 | title = {{HDFS} Architecture}, 25 | author = {Dhruba Borthakur}, 26 | journal = {Document on {H}adoop Wiki}, 27 | year = {2010}, 28 | url = 29 | {http://hadoop.apache.org/common/docs/r0.20.2/hdfs_design.html} 30 | } 31 | 32 | @InProceedings{737-Dean+Ghemawat-2004, 33 | title = {{MapReduce}: Simplified Data Processing on Large 34 | Clusters}, 35 | author = {Jeffrey Dean and Sanjay Ghemawat}, 36 | booktitle = {Proceedings of the Sixth Symposium on Operating 37 | System Design and Implementation}, 38 | pages = {137--150}, 39 | year = {2004}, 40 | url = {http://labs.google.com/papers/mapreduce.html} 41 | } 42 | 43 | @Manual{737-Feinerer-2011, 44 | title = {\pkg{tm}: Text Mining Package}, 45 | author = {Ingo Feinerer}, 46 | year = 2011, 47 | note = {\proglang{R} package version 0.5-6}, 48 | url = {http://tm.R-Forge.R-project.org/} 49 | } 50 | 51 | @Article{737-Feinerer_etal-2008, 52 | author = {Ingo Feinerer and Kurt Hornik and David Meyer}, 53 | title = {Text Mining Infrastructure in {\proglang{R}}}, 54 | journal = {Journal of Statistical Software}, 55 | volume = 25, 56 | number = 5, 57 | pages = {1--54}, 58 | month = {March}, 59 | year = 2008, 60 | issn = {1548-7660}, 61 | url = {http://www.jstatsoft.org/v25/i05} 62 | } 63 | 64 | @book{737-Francis+Kucera-1982, 65 | title = {Frequency Analysis of English Usage: Lexicon and 66 | Grammar}, 67 | author = {W. Nelson Francis and Henry Ku\v{c}era}, 68 | year = {1982}, 69 | publisher = {Houghton Mifflin} 70 | } 71 | 72 | @article{737-Gantz-2008, 73 | title = {The Diverse and Exploding Digital Universe: An 74 | Updated Forecast of Worldwide Information Growth 75 | Through 2011}, 76 | author = {John F. Gantz and Christopher Chute and Alex 77 | Manfrediz and Stephen Minton and David Reinsel and 78 | Wolfgang Schlichting and Anna Toncheva}, 79 | journal = {IDC White Paper}, 80 | year = {2008}, 81 | url = 82 | {http://www.emc.com/collateral/analyst-reports/diverse-exploding-digital-universe.pdf} 83 | } 84 | 85 | @InProceedings{737-Ghemawat_etal-2003, 86 | author = {Sanjay Ghemawat and Howard Gobioff and {Shun-Tak} 87 | Leung}, 88 | title = {The {G}oogle File System}, 89 | pages = {29--43}, 90 | year = 2003, 91 | booktitle = {Proceedings of the 19th {ACM} Symposium on Operating 92 | Systems Principles}, 93 | month = {October}, 94 | publisher = {ACM Press}, 95 | address = {New York, NY, USA}, 96 | doi = {http://doi.acm.org/10.1145/1165389.945450} 97 | } 98 | 99 | @Article{737-Griffiths+Steyvers-2004, 100 | author = {Thomas L. Griffiths and Mark Steyvers}, 101 | title = {Finding Scientific Topics}, 102 | journal = {Proceedings of the National Academy of Sciences of 103 | the United States of America}, 104 | volume = 101, 105 | year = 2004, 106 | issue = {Suppl. 1}, 107 | pages = {5228--5235}, 108 | doi = {10.1073/pnas.0307752101} 109 | } 110 | 111 | @book{737-Hogg+Denison-2008, 112 | title = {A History of the English Language}, 113 | editor = {Richard Hogg and David Denison}, 114 | year = 2008, 115 | publisher = {Cambridge University Press} 116 | } 117 | 118 | @Manual{737-Hornik+Meyer+Buchta-2011, 119 | title = {\pkg{slam}: Sparse Lightweight Arrays and Matrices}, 120 | author = {Kurt Hornik and David Meyer and Christian Buchta}, 121 | year = {2011}, 122 | note = {\proglang{R} package version 0.1-22}, 123 | url = {http://CRAN.R-project.org/package=slam}, 124 | } 125 | 126 | @Article{737-Laemmel-2007, 127 | title = {Google's {MapReduce} Programming Model---Revisited}, 128 | author = {Ralf L{\"a}mmel}, 129 | journal = {Science of Computer Programming}, 130 | volume = {68}, 131 | number = {3}, 132 | pages = {208--237}, 133 | year = {2007}, 134 | publisher = {Elsevier} 135 | } 136 | 137 | @Misc{737-Lewis-1997, 138 | author = {David Lewis}, 139 | title = {Reuters-21578 Text Categorization Test Collection}, 140 | year = 1997, 141 | url = 142 | {http://www.daviddlewis.com/resources/testcollections/reuters21578/} 143 | } 144 | 145 | @article{737-Lewis_et_al-2004, 146 | title = {{RCV1}: A New Benchmark Collection for Text 147 | Categorization Research}, 148 | author = {David D. Lewis and Yiming Yang and Tony G. Rose and 149 | Fan Li}, 150 | journal = {The Journal of Machine Learning Research}, 151 | volume = {5}, 152 | pages = {361--397}, 153 | year = {2004} 154 | } 155 | 156 | @Manual{737-MPIForum-1994, 157 | title = {{MPI}: A Message-Passing Interface Standard}, 158 | author = {{Message Passing Interface Forum}}, 159 | year = 1994 160 | } 161 | 162 | @Manual{737-MPIForum-2003, 163 | title = {{MPI}-2: Extensions to the Message-Passing Interface}, 164 | author = {{Message Passing Interface Forum}}, 165 | year = 2003 166 | } 167 | 168 | @article{737-Michel_et_al-2011, 169 | title = {Quantitative Analysis of Culture Using Millions of 170 | Digitized Books}, 171 | author = {Jean-Baptiste Michel and Yuan Kui Shen and Aviva 172 | Presser Aiden and Adrian Veres and Matthew K. Gray 173 | and {The Google Books Team} and Joseph P. Pickett 174 | and Dale Hoiberg and Dan Clancy and Peter Norvig and 175 | Jon Orwant and Steven Pinker and Martin A. Nowak and 176 | Erez Lieberman Aiden}, 177 | journal = {Science}, 178 | volume = 331, 179 | pages = {176--182}, 180 | year = 2011, 181 | doi = {10.1126/science.1199644} 182 | } 183 | 184 | @Article{737-Porter-1980, 185 | author = {Martin Porter}, 186 | title = {An Algorithm for Suffix Stripping}, 187 | journal = {Program}, 188 | year = 1980, 189 | volume = 3, 190 | pages = {130--137} 191 | } 192 | 193 | @Manual{737-R-2011, 194 | title = {\proglang{R}: A Language and Environment for 195 | Statistical Computing}, 196 | author = {{\proglang{R} Development Core Team}}, 197 | organization = {\proglang{R} Foundation for Statistical Computing}, 198 | address = {Vienna, Austria}, 199 | year = 2011, 200 | note = {{ISBN} 3-900051-07-0}, 201 | url = {http://www.R-project.org}, 202 | } 203 | 204 | @Article{737-Rossini_etal-2003, 205 | author = {Anthony Rossini and Luke Tierney and Na Li}, 206 | title = {Simple Parallel Statistical Computing in 207 | \proglang{R}}, 208 | journal = {{UW} Biostatistics Working Paper Series}, 209 | year = 2003, 210 | number = {Working Paper 193}, 211 | URL = {http://www.bepress.com/uwbiostat/paper193} 212 | } 213 | 214 | @Misc{737-Sandhaus-2008, 215 | author = {Evan Sandhaus}, 216 | title = {The {New York Times} Annotated Corpus}, 217 | year = 2008, 218 | publisher = {Linguistic Data Consortium}, 219 | address = {Philadelphia, USA}, 220 | url = 221 | {http://www.ldc.upenn.edu/Catalog/CatalogEntry.jsp?catalogId=LDC2008T19} 222 | } 223 | 224 | @article{737-Schmidberger_etal-2009, 225 | author = {Markus Schmidberger and Martin Morgan and Dirk 226 | Eddelbuettel and Hao Yu and Luke Tierney and Ulrich 227 | Mansmann}, 228 | title = {State of the Art in Parallel Computing with \proglang{R}}, 229 | journal = {Journal of Statistical Software}, 230 | volume = {31}, 231 | number = {1}, 232 | pages = {1--27}, 233 | day = {4}, 234 | month = {8}, 235 | year = {2009}, 236 | CODEN = {JSSOBK}, 237 | ISSN = {1548-7660}, 238 | bibdate = {2009-06-02}, 239 | URL = {http://www.jstatsoft.org/v31/i01}, 240 | accepted = {2009-06-02}, 241 | submitted = {2008-12-29} 242 | } 243 | 244 | @article{737-Tetlock-2007, 245 | title = {Giving Content to Investor Sentiment: The Role of 246 | Media in the Stock Market}, 247 | volume = {62}, 248 | number = {3}, 249 | journal = {The Journal of Finance}, 250 | author = {Paul Tetlock}, 251 | year = {2007}, 252 | pages = {1139--1168} 253 | } 254 | 255 | @Misc{737-hadoop-2010, 256 | author = {{The Apache Software Foundation}}, 257 | title = {{H}adoop}, 258 | year = {2010}, 259 | note = {Release 0.20.2}, 260 | url = {http://hadoop.apache.org/core/} 261 | } 262 | 263 | @Manual{737-Theussl+Feinerer-2011a, 264 | title = {\pkg{hive}: {H}adoop {I}nteracti{VE}}, 265 | author = {Stefan Theu\ss{}l and Ingo Feinerer}, 266 | year = {2011}, 267 | note = {\proglang{R} package version 0.1-10}, 268 | url = {http://CRAN.R-project.org/package=hive} 269 | } 270 | 271 | @Manual{737-Theussl+Feinerer-2011b, 272 | title = {Text Mining Distributed Corpus Plug-In}, 273 | author = {Stefan Theu\ss{}l and Ingo Feinerer}, 274 | year = {2011}, 275 | note = {\proglang{R} package version 0.1-6}, 276 | url = {http://CRAN.R-project.org/package=tm.plugin.dc} 277 | } 278 | 279 | @Manual{737-Tierney_etal-2011, 280 | title = {\pkg{snow}: Simple Network of Workstations}, 281 | author = {Luke Tierney and Anthony Rossini and Na Li and Hana 282 | Sevcikova}, 283 | year = 2011, 284 | note = {\proglang{R} package version 0.3-5}, 285 | } 286 | 287 | @Manual{737-Urbanek-2011, 288 | title = {\pkg{multicore}: Parallel Processing of \proglang{R} 289 | Code on Machines With Multiple Cores or CPUs}, 290 | author = {Simon Urbanek}, 291 | year = {2011}, 292 | note = {\proglang{R} package version 0.1-5}, 293 | url = {http://www.rforge.net/multicore/}, 294 | } 295 | 296 | @Article{737-Yu-2002, 297 | author = {Hao Yu}, 298 | title = {{\pkg{Rmpi}}: Parallel Statistical Computing in \proglang{R}}, 299 | journal = {\proglang{R} News}, 300 | year = 2002, 301 | volume = 2, 302 | number = 2, 303 | pages = {10--14} 304 | } 305 | 306 | @Manual{737-Yu-2010, 307 | title = {\pkg{Rmpi}: Interface (Wrapper) to {MPI} 308 | (Message-Passing Interface)}, 309 | author = {Hao Yu}, 310 | year = 2010, 311 | note = {R package version 0.5-9}, 312 | url = {http://www.stats.uwo.ca/faculty/yu/Rmpi}, 313 | } 314 | 315 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------