Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polarity_dt requires words with spaces to work #117

Closed
mrwunderbar666 opened this issue May 4, 2020 · 1 comment
Closed

polarity_dt requires words with spaces to work #117

mrwunderbar666 opened this issue May 4, 2020 · 1 comment

Comments

@mrwunderbar666
Copy link

While I was testing some custom dictionaries, I noticed an unexpected behaviour in sentiment and sentiment_by:

If the polarity_dt provided does not contain a word with spaces and a custom valence_shifters_dt is used, then the function is broken.

I traced the bug to this section of the code:

sent_dat[, 'words' := list(make_words(space_fill_senti(sentences, space_words), hyphen = hyphen))]

You can replicate it running this short script:

library(sentimentr)

mytext <- c(
  'do you like it?  But I hate really bad dogs',
  'I am the best friend.',
  'Do you really like it?  I\'m not a fan',
  'I am good',
  'I am not good',
  'You are bad',
  'You are not bad'
)

neg_words <- c("bad", "hate")
neg_words <- data.frame(x=neg_words, y=-1, stringsAsFactors = FALSE)
pos_words <- c("good", "like", "friend", "fan")
pos_words <- data.frame(x=pos_words, y=1, stringsAsFactors = FALSE)
my_dict <- rbind(pos_words, neg_words) 

# custom valence shifter
negs_words <- c('not')
negators <- data.frame(x=negs_words, y="1", stringsAsFactors = FALSE)
amplifier_words <- c('really')
amps <- data.frame(x=amplifier_words, y="2", stringsAsFactors = FALSE)

my_valenceshifters <- rbind(negators, amps)
my_valenceshifters <- as_key(my_valenceshifters, sentiment = FALSE, comparison = NULL)

my_sentiment <- as_key(my_dict, comparison = NULL)
is_key(my_sentiment)
mytext <- get_sentences(mytext)

# result will be 0 for all
sentiment_by(mytext, polarity_dt = my_sentiment, valence_shifters_dt = my_valenceshifters)

dummy_spaced <- data.frame(x = c('space word'), y = 0, stringsAsFactors = FALSE)
my_sentiment <- update_key(my_sentiment, x = dummy_spaced)

# results are as expected
sentiment_by(mytext, polarity_dt = my_sentiment, valence_shifters_dt = my_valenceshifters)
@trinker
Copy link
Owner

trinker commented May 4, 2020

Thanks for the issue! We're looking into this behavior.

@trinker trinker closed this as completed in 69a51a7 Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants