Skip to content
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3c9216d
Update DESCRIPTION
Shantanu1497 Dec 5, 2018
62ad324
Added comma removal before valence shifters
Shantanu1497 Dec 5, 2018
1cbabe1
Update sentiment.R
Shantanu1497 Dec 5, 2018
54a51cb
Update sentiment.Rd
Shantanu1497 Dec 5, 2018
331c577
Update sentiment.R
Shantanu1497 Dec 5, 2018
d84c5df
Update sentiment.R
Shantanu1497 Dec 5, 2018
cb49912
Update NAMESPACE
Shantanu1497 Dec 11, 2018
95f540c
Update sentiment.R
Shantanu1497 Dec 11, 2018
8a2f7c9
Update sentiment_by.R
Shantanu1497 Dec 11, 2018
53065fe
Update sentiment_by.R
Shantanu1497 Dec 11, 2018
36fc4c6
Update sentiment.R
Shantanu1497 Dec 11, 2018
3a807ac
Update sentiment.R
Shantanu1497 Dec 11, 2018
a7e75ba
Update sentiment.R
Shantanu1497 Dec 11, 2018
a192b24
Update NAMESPACE
Shantanu1497 Dec 11, 2018
d56f5c8
Update NAMESPACE
Shantanu1497 Dec 11, 2018
6136892
Update sentiment.R
Shantanu1497 Dec 11, 2018
261cf0d
Update sentiment.R
Shantanu1497 Dec 11, 2018
1623621
Update sentiment.R
Dec 12, 2018
0873e8f
Update sentiment.Rd
Dec 12, 2018
6541279
Update sentiment.R
Dec 12, 2018
8c30b40
Update sentiment.R
Dec 12, 2018
51afb4c
Merge pull request #1 from aainasingh/master
Shantanu1497 Dec 12, 2018
5995a98
Update sentiment.Rd
Shantanu1497 Dec 12, 2018
ed83ba3
Global - valence_shifters_dt
Shantanu1497 Dec 12, 2018
38cc674
Updated Conditions to Preprocess
Shantanu1497 Jan 12, 2019
29acb76
Referenced globally - stringr::str_split
Shantanu1497 Jan 12, 2019
c632a47
Update NAMESPACE
Shantanu1497 Jan 12, 2019
70347da
Update DESCRIPTION
Shantanu1497 Jan 12, 2019
2720148
Updating variable names for readability
Shantanu1497 Jan 12, 2019
e50b0d1
Updated condition for length=0
Shantanu1497 Jan 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update sentiment.R
  • Loading branch information
Shantanu1497 authored Dec 11, 2018
commit 95f540c203552e5c76b4da8bea50b58be65766bc
13 changes: 7 additions & 6 deletions R/sentiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' a raw character vector though \code{get_sentences} is preferred as it avoids
#' the repeated cost of doing sentence boundary disambiguation every time
#' \code{sentiment} is run.
#' @param comma
#' @param polarity_dt A \pkg{data.table} of positive/negative words and
#' weights with x and y as column names. The \pkg{lexicon} package has several
#' dictionaries that can be used, including:
Expand Down Expand Up @@ -307,7 +308,7 @@
#' sentiment(Tweet, polarity_dt = combined_emoji)
#'
#' }
sentiment <- function(text.var, polarity_dt = lexicon::hash_sentiment_jockers_rinker,
sentiment <- function(text.var, comma = TRUE, polarity_dt = lexicon::hash_sentiment_jockers_rinker,
valence_shifters_dt = lexicon::hash_valence_shifters, hyphen = "",
amplifier.weight = .8, n.before = 5, n.after = 2, question.weight = 1,
adversative.weight = .25, neutral.nonverb.like = FALSE, missing_value = 0, ...){
Expand Down Expand Up @@ -349,7 +350,7 @@ return(u)

#' @export
#' @method sentiment get_sentences_character
sentiment.get_sentences_character <- function(text.var, polarity_dt = lexicon::hash_sentiment_jockers_rinker,
sentiment.get_sentences_character <- function(text.var, comma = FALSE ,polarity_dt = lexicon::hash_sentiment_jockers_rinker,
valence_shifters_dt = lexicon::hash_valence_shifters, hyphen = "",
amplifier.weight = .8, n.before = 5, n.after = 2, question.weight = 1,
adversative.weight = .25, neutral.nonverb.like = FALSE, missing_value = 0, ...){
Expand All @@ -358,7 +359,7 @@ sentiment.get_sentences_character <- function(text.var, polarity_dt = lexicon::h
cluster_tag <- w_neg <- neg <- A <- a <- D <- d <- wc <- id <-
T_sum <- N <- . <- b <- before <- NULL

## check to ake sure valence_shifters_dt polarity_dt are mutually exclusive
## check to make sure valence_shifters_dt polarity_dt are mutually exclusive
if(any(valence_shifters_dt[[1]] %in% polarity_dt[[1]])) {
stop('`polarity_dt` & `valence_shifters_dt` not mutually exclusive')
}
Expand All @@ -374,7 +375,7 @@ sentiment.get_sentences_character <- function(text.var, polarity_dt = lexicon::h
# break rows into count words
sent_dat <- make_sentence_df2(sents)

if(neutral.nonverb.like) sent_dat$sentences <- unlist(lapply(sent_dat$sentences, run_preprocess))
if(comma) sent_dat$sentences <- unlist(lapply(sent_dat$sentences, run_preprocess))

# buts <- valence_shifters_dt[valence_shifters_dt[[2]] == 4,][['x']]
#
Expand Down Expand Up @@ -544,7 +545,7 @@ like_preverbs_regex <- paste0('\\b(', paste(like_preverbs, collapse = '|'), ')(\

#' @export
#' @method sentiment character
sentiment.character <- function(text.var, polarity_dt = lexicon::hash_sentiment_jockers_rinker,
sentiment.character <- function(text.var, comma = FALSE, polarity_dt = lexicon::hash_sentiment_jockers_rinker,
valence_shifters_dt = lexicon::hash_valence_shifters, hyphen = "",
amplifier.weight = .8, n.before = 5, n.after = 2, question.weight = 1,
adversative.weight = .25, neutral.nonverb.like = FALSE, missing_value = 0, ...){
Expand All @@ -563,7 +564,7 @@ sentiment.character <- function(text.var, polarity_dt = lexicon::hash_sentiment_

#' @export
#' @method sentiment get_sentences_data_frame
sentiment.get_sentences_data_frame <- function(text.var, polarity_dt = lexicon::hash_sentiment_jockers_rinker,
sentiment.get_sentences_data_frame <- function(text.var, comma = FALSE, polarity_dt = lexicon::hash_sentiment_jockers_rinker,
valence_shifters_dt = lexicon::hash_valence_shifters, hyphen = "",
amplifier.weight = .8, n.before = 5, n.after = 2, question.weight = 1,
adversative.weight = .25, neutral.nonverb.like = FALSE, missing_value = 0, ...){
Expand Down