-1

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)
Narendra
  • 1,511
  • 1
  • 10
  • 20
hganger
  • 147
  • 2
  • 12
  • What is the structure of your polarity and shifter data.frames? – phiver Apr 28 '18 at 08:56
  • Hi phiver, polarity is: column x: "heureux" column y: +3. shifters is : column x: "ne" column y: 1. I solved the point using as_key function. – hganger May 03 '18 at 15:49
  • So the point is closed. However the results are not really OK. As I should get a negative value for the first sentence (in english I am not happy) and I got 1.3! – hganger May 03 '18 at 15:56

1 Answers1

0

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

phiver
  • 23,048
  • 14
  • 44
  • 56
  • Hi phiver. Thank you for the time you spent to answer. I will have a look to the links you provided. – hganger May 05 '18 at 17:28
  • Hi phiver. In fact, I got a positive value for the first sentence because of the double negation ("ne" and "pas"). SO I kept only "pas" and I got the right result ! – hganger May 06 '18 at 16:04
  • Good to hear. "Pas" is a bit easier to find as it will not transform into n' as in "n'ai pas". I assume you are taking care of jamais, rien, ni, etc. – phiver May 06 '18 at 16:13