calc_net_sentiment_nrc.Rd
For a given text, translate all words into NRC sentiments and count sentiment occurrences.
calc_net_sentiment_nrc( x, target_col_name = NULL, text_col_name, filter_class = NULL )
x | A data frame with two columns: the column with the classes; and the column with the text. Any other columns will be ignored. |
---|---|
target_col_name | A string with the column name of the target variable.
Defaults to |
text_col_name | A string with the column name of the text variable. |
filter_class | A string or vector of strings with the name(s) of the
class(es) for which bigrams are to be created and counted. Defaults to
|
A data frame with 12 or 13 columns: the text column; the line number; the 10 NRC sentiments (anger, anticipation disgust, fear, joy, negative, positive, sadness, surprise, trust- see Mohammad & Turney, 2013); and the column with the classes (if any).
Mohammad S.M. & Turney P.D. (2013). Crowdsourcing a Word–Emotion Association Lexicon. Computational Intelligence, 29(3):436-465.
library(experienceAnalysis) books <- janeaustenr::austen_books() # Jane Austen books emma <- paste(books[books$book == "Emma", ], collapse = " ") # String with whole book pp <- paste(books[books$book == "Pride & Prejudice", ], collapse = " ") # String with whole book # Make data frame with books Emma and Pride & Prejudice x <- data.frame( text = c(emma, pp), book = c("Emma", "Pride & Prejudice") ) # Net sentiment in each book calc_net_sentiment_nrc(x, target_col_name = "book", text_col_name = "text", filter_class = NULL)#> # A tibble: 2 x 13 #> text linenumber anger anticipation disgust fear joy negative positive #> <chr> <int> <int> <int> <int> <int> <int> <int> <int> #> 1 "c(\"EMMA~ 1 1548 4821 1323 2343 4432 4473 9471 #> 2 "c(\"PRID~ 2 1295 3596 973 1767 3336 3641 7443 #> # ... with 4 more variables: sadness <int>, surprise <int>, trust <int>, #> # book <chr>