trinker / sentimentr

Dictionary based sentiment analysis that considers valence shifters
Other
427 stars 84 forks source link

Using custom polarity_dt dictionaries #109

Closed sherwinhlee closed 3 years ago

sherwinhlee commented 5 years ago

If I customize my own dictionary with polarity_dt / valence_shifters_dt in dataframe and specify that as arguments to sentiment() or sentiment_by(), does that replace the default dictionary? If so and I want to add to the existing lexicons, how do I go about doing that?

MsPhotonUIUC commented 5 years ago

Can I second this question?

I've been following the "as_key" code example* but to no avail. Have been trying to add a few words that the dictionary doesn't give a value to "learns", "learned", but don't know how to apply changes. If you've figured it out, I'd love some help.

*https://rdrr.io/cran/sentimentr/man/as_key.html

sherwinhlee commented 5 years ago

Figured it out. If you want to add onto the dictionary, you have to use update_key() with the default lexicon as your first parameter and set the x parameter to your new additions. Store that as a new object and that will be passed into the polarity_dt argument.

GabriellaS-K commented 4 years ago

@sherwinhlee how did you look at what the default lexicon was? I'd like to see it before i make amendments! Thanks

trinker commented 3 years ago

@GabriellaS-K If you look at the source code by typing sentiment you're see the arguments for the dictionaries or type ?sentiment. That leads you to lexicon::hash_sentiment_jockers_rinker.

@sherwinhlee & @MsPhotonUIUC You can definitiely make your own and update existing _dt tables but this can be tricky business with out the helper functions as you run into problems if you have duplicated words or words in polarity that are also in valence_shifters. The update_key helps with this process. Glad you figured it out.