Reputation: 167
I have created polarity and shifters dictionaries (a few words just to test) with columns x and y as requested.
I get the following error:
Error in [.data.frame`(polarity_dt, word_dat[["words"]]) : undefined columns selected
Please could you help me? Thank you in advance.
Best regards
FEEL_polarity <- read.csv2('./FEEL_polarity.csv')
SHIFTERS <- read.csv2('./Shifters.csv')
library("sentimentr")
text_to_analyse <- c("Je ne suis pas heureux. Je suis heureux.")
sentiment(get_sentences(text_to_analyse), polarity_dt = FEEL_polarity,valence_shifters_dt = SHIFTERS)
Upvotes: -1
Views: 1126
Reputation: 23598
As you already mentioned in the comments it is best to use data.table
for the polarity and shifters tables and set the key.
If I run this with your text, I get the result below. -1.3 for sentence 1 and 1.7 for sentence 2. Be aware that negators should be coded as 1L not -1L.
library(sentimentr)
library(data.table)
text_to_analyse <- c("Je ne suis pas heureux. Je suis heureux.")
polarity <- data.table(x = "heureux",
y = 3L,
key = "x")
shifters <- data.table(x = "ne",
y = 1L,
key = "x")
sentiment(get_sentences(text_to_analyse),
polarity_dt = polarity,
valence_shifters_dt = shifters)
element_id sentence_id word_count sentiment
1: 1 1 5 -1.341641
2: 1 2 3 1.732051
Do realize that sentimentr
is developed for the English language.
For French dictionaries you can look at the following websites:
FEEL: a French Expanded Emotion Lexicon. http://advanse.lirmm.fr/feel.php A French lexicon containing more than 14 000 distinct words expressing emotions and sentiments. It follows the Ekman basic two polarities and six emotions (Ekman, 1992). It has been created by automatically translating and expanding the English Emotional Lexicon NRC-Canada (Mohammad & Turney, 2013). The process has been supervised and validated manually by a human professional translator.
This file can be adjusted to get it to work with sentimentr
or maybe with tidytext
. I still have to look into this. And maybe udpipe
might be better for French.
POLTEXT: https://www.poltext.org/en/donnees-et-analyses/lexicoder with a lexicon you can use with quanteda
Upvotes: 0