calc_net_sentiment_nrc: Calculate "net sentiment" in a text

Description Usage Arguments Value References Examples

View source: R/calc_net_sentiment_nrc.R

Description

For a given text, translate all words into NRC sentiments and count sentiment occurrences.

Usage

1
2
3
4
5
6
calc_net_sentiment_nrc(
  x,
  target_col_name = NULL,
  text_col_name,
  filter_class = NULL
)

Arguments

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 NULL.

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 NULL (all rows).

Value

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).

References

Mohammad S.M. & Turney P.D. (2013). Crowdsourcing a Word–Emotion Association Lexicon. Computational Intelligence, 29(3):436-465.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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)

CDU-data-science-team/experienceAnalysis documentation built on Dec. 17, 2021, 12:53 p.m.