[go: nahoru, domu]

Skip to content

Commit

Permalink
Separate out smoothing and plotting functions
Browse files Browse the repository at this point in the history
- Create the function adjust_and_smooth() and call that within plot_sentiments() instead of having everything be within the plot function
- Fix up both those functions: clean up the legend positioning and labels, fix the adjusted mean calculation, and clarify comments
- Stop using the ALL_MODELS_LIST global variable and instead just write out the full list every time to make it clear in the doc strings which SentimentR model names are expected in each function
- Change jockersrinker to jockers_rinker for readability and plot legends
  • Loading branch information
afelleson committed Mar 19, 2024
1 parent 8bb1a35 commit 9681399
Show file tree
Hide file tree
Showing 2 changed files with 348 additions and 118 deletions.
22 changes: 11 additions & 11 deletions src/imppkg/run_sentimentr.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ get_sentimentr_values <- function(sentences_vector) {

get_sentences_obj <- get_sentences(sentences_vector)

jockersrinker <- sentiment(get_sentences_obj,
polarity_dt=lexicon::hash_sentiment_jockers_rinker,
hypen="", amplifier.weight=0.8, n.before=5, n.after=2,
adversative.weight=0.25, neutral.nonverb.like = FALSE,
missing_value = NULL)
jockers_rinker <- sentiment(get_sentences_obj,
polarity_dt=lexicon::hash_sentiment_jockers_rinker,
hypen="", amplifier.weight=0.8, n.before=5, n.after=2,
adversative.weight=0.25, neutral.nonverb.like = FALSE,
missing_value = NULL)

jockers <- sentiment(get_sentences_obj,
polarity_dt=lexicon::hash_sentiment_jockers,
Expand Down Expand Up @@ -72,10 +72,10 @@ get_sentimentr_values <- function(sentences_vector) {

# loughran_mcdonald is for financial texts
loughran_mcdonald <- sentiment(get_sentences_obj,
polarity_dt=lexicon::hash_sentiment_loughran_mcdonald,
hypen="", amplifier.weight=0.8, n.before=5, n.after=2,
adversative.weight=0.25, neutral.nonverb.like = FALSE,
missing_value = 0)
polarity_dt=lexicon::hash_sentiment_loughran_mcdonald,
hypen="", amplifier.weight=0.8, n.before=5, n.after=2,
adversative.weight=0.25, neutral.nonverb.like = FALSE,
missing_value = 0)

socal_google <- sentiment(get_sentences_obj,
polarity_dt=lexicon::hash_sentiment_socal_google,
Expand All @@ -84,8 +84,8 @@ get_sentimentr_values <- function(sentences_vector) {
missing_value = NULL)

sentimentr_df <- data.frame('text_clean' = sentences_vector,
'was_averaged' = restoreOldSentences(jockersrinker)$flag,
'sentimentr_jockersrinker' = restoreOldSentences(jockersrinker)$sentiment_avg,
'was_averaged' = restoreOldSentences(jockers_rinker)$flag,
'sentimentr_jockers_rinker' = restoreOldSentences(jockers_rinker)$sentiment_avg,
'sentimentr_jockers' = restoreOldSentences(jockers)$sentiment_avg,
'sentimentr_huliu' = restoreOldSentences(huliu)$sentiment_avg,
'sentimentr_nrc' = restoreOldSentences(nrc)$sentiment_avg,
Expand Down
Loading

0 comments on commit 9681399

Please sign in to comment.