classify_emotion: classifies the emotion (e.g. anger, disgust, fear, joy,...

View source: R/classify_emotion.R

classify_emotionR Documentation

classifies the emotion (e.g. anger, disgust, fear, joy, sadness, surprise) of a set of texts.

Description

classify_emotion Classifies the emotion (e.g. anger, disgust, fear, joy, sadness, surprise) of a set of texts using a naive Bayes classifier trained on Carlo Strapparava and Alessandro Valitutti's emotions lexicon.

Usage

classify_emotion(
  textColumns,
  algorithm = "bayes",
  prior = 1,
  verbose = FALSE,
  lang = "en",
  ...
)

Arguments

textColumns

A data.frame of text documents listed one per row.

algorithm

A string indicating whether to use the naive bayes algorithm or a simple voter algorithm.

prior

A numeric specifying the prior probability to use for the naive Bayes classifier.

verbose

A logical specifying whether to print detailed output regarding the classification process.

lang

Language, "en" for English and "pt" for Brazilian Portuguese.

...

Additional parameters to be passed into the create_matrix function.

Value

Returns an object of class data.frame with seven columns and one row for each document.

anger

The absolute log likelihood of the document expressing an angry sentiment.

disgust

The absolute log likelihood of the document expressing a disgusted sentiment.

fear

The absolute log likelihood of the document expressing a fearful sentiment.

joy

The absolute log likelihood of the document expressing a joyous sentiment.

sadness

The absolute log likelihood of the document expressing a sad sentiment.

surprise

The absolute log likelihood of the document expressing a surprised sentiment.

trust

The absolute log likelihood of the document expressing a trust sentiment.

negative

The absolute log likelihood of the document expressing a negative sentiment.

positive

The absolute log likelihood of the document expressing a positive sentiment.

anticipation

The absolute log likelihood of the document expressing a anticipation sentiment.

best_fit

The most likely sentiment category (e.g. anger, disgust, fear, joy, sadness, surprise) for the given text.

Author(s)

Timothy P. Jurka <tpjurka@ucdavis.edu> and Jodavid Ferreira <jdaf1@de.ufpe.br>

Examples

# DEFINE DOCUMENTS
documents <- c("I am very happy, excited, and optimistic.",
               "I am very scared, annoyed, and irritated.")

# CLASSIFY EMOTIONS
classify_emotion(documents,algorithm="bayes",verbose=TRUE, lang = "en")

# pt-BR
documentos <- c("Estou muito feliz, animado e otimista.",
               "Estou muito assustado e irritado.")

# CLASSIFY EMOTIONS
classify_emotion(documentos,algorithm="bayes",verbose=TRUE, lang = "pt")



Jodavid/sentimentBR documentation built on Oct. 9, 2022, 8:37 a.m.