Skip to content

Commit

Permalink
added sentiment_frame and depricated polarity_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
trinker committed Apr 23, 2014
1 parent 114e7c1 commit f58fca3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ IMPROVEMENTS

CHANGES

* `polarity_frame` is deprecated and will be removed in a subsequent release.
Please use `sentiment_frame` instead.


CHANGES IN qdap VERSION 1.3.5
----------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ IMPROVEMENTS

**CHANGES**

* `polarity_frame` is deprecated and will be removed in a subsequent release.
Please use `sentiment_frame` instead.


**CHANGES** IN <a href="https://github.com/trinker/qdap" target="_blank">qdap</a> VERSION 1.3.5
----------------------------------------------------------------
Expand Down
14 changes: 10 additions & 4 deletions R/polarity.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@
#' plot(poldat3, nrow=4)
#' qheat(scores(poldat3)[, -7], high="red", order.b="ave.polarity")
#'
#' ## Create researcher defined polarity.frame
#' POLENV <- polarity_frame(positive.words, negative.words)
#' ## Create researcher defined sentiment.frame
#' POLENV <- sentiment_frame(positive.words, negative.words)
#' POLENV
#' ls(POLENV)[1:20]
#'
#' c("abrasive", "abrupt", "happy") %ha% POLENV
#'
#' ## ANIMATION
#' #===========
#' (deb2 <- with(subset(pres_debates2012, time=="time 2"),
Expand Down Expand Up @@ -353,7 +354,7 @@ polarity <- function (text.var, grouping.var = NULL,
if (!is.environment(polarity.frame)) {
if (!is.data.frame(polarity.frame)) {
stop(paste("Please supply a dataframe or environment",
"(see `polarity_frame`) to polarity.frame"))
"(see `sentiment_frame`) to polarity.frame"))
}
polarity.frame <- hash(polarity.frame)
}
Expand Down Expand Up @@ -597,6 +598,11 @@ print.polarity_count <-
#' @rdname polarity
polarity_frame <- function(positives, negatives, pos.weights = 1,
neg.weights = -1, envir = TRUE) {

.Deprecated(msg = paste("polarity_frame is deprecated. Please use the",
"sentiment_frame function instead."),
old = as.character(sys.call(sys.parent()))[1L])

plen <- length(positives)
nlen <- length(negatives)
if (!length(plen) %in% c(length(positives), 1)) {
Expand Down
42 changes: 42 additions & 0 deletions R/power.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' Power Score (Sentiment Analysis)
#'
#' \code{sentiment_frame} - Generate a sentiment lookup environment or data.frame
#' for use with the \code{xxx.frame} argument of various sentiment functions
#' function.
#'
#' @param positives A character vector of positive words.
#' @param negatives A character vector of negative words.
#' @param pos.weights A vector of weights to weight each positive word by.
#' Length must be equal to length of \code{postives} or length 1 (if 1 weight
#' will be recycled).
#' @param neg.weights A vector of weights to weight each negative word by.
#' Length must be equal to length of \code{negatives} or length 1 (if 1 weight
#' will be recycled).
#' @param envir logical. If \code{TRUE} a lookup table (a dataframe within
#' an environment) is produced rather than a data.frame.
#' @export
#' @rdname power
sentiment_frame <- function(positives, negatives, pos.weights = 1,
neg.weights = -1, envir = TRUE) {
plen <- length(positives)
nlen <- length(negatives)
if (!length(plen) %in% c(length(positives), 1)) {
stop("The length of positives and pos.weights must be equal")
}
if (!length(nlen) %in% c(length(negatives), 1)) {
stop("The length of negatives and negative weights must be equal")
}
if (length(pos.weights) == 1) {
pos.weights <- rep(pos.weights, plen)
}
if (length(neg.weights) == 1) {
neg.weights <- rep(neg.weights, nlen)
}
dat <- data.frame(words = c(positives, negatives), polarity = c(pos.weights,
neg.weights))
if (envir) {
hash(dat)
} else {
dat
}
}
2 changes: 1 addition & 1 deletion inst/maintenance.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ library(highlight); library(qdap); library(staticdocs); library(acc.roxygen2)
#STEP 1: create static doc
#right now examples are FALSE in the future this will be true
#in the future qdap2 will be the go to source
build_site(pkg="C:/Users/trinker/GitHub/qdap")
build_site(pkg="C:/Users/trinker/GitHub/qdap",launch = FALSE)

#STEP 2: reshape index
path <- "inst/web"
Expand Down

0 comments on commit f58fca3

Please sign in to comment.