polarity: Set or get the sentiment polarity of a dictionary

View source: R/textstat_polarity.R

polarityR Documentation

Set or get the sentiment polarity of a dictionary

Description

Set or retrieve the polarity of a dictionary object for the purposes of sentiment analysis. Polarity consists of a set of dictionary keys that are associated with positive, negative, and (optionally) neutral categories for use in textstat_polarity().

Usage

polarity(x)

polarity(x) <- value

Arguments

x

a dictionary object

value

list consisting of named character vectors pos, neg, and (optionally) neut corresponding to positive, negative, and neutral sentiment categories respectively. Each element may contain multiple key names. The neut category is optional but pos and neg must be supplied.

Details

A dictionary may have only one set of polarities at a time, but may be changed as needed.

Value

polarity() returns the polarity as a list.

⁠polarity<-⁠ sets the dictionary's polarity.

Examples

library("quanteda")
simpledict <- dictionary(list(
    happy = c("happy", "jubilant", "exuberant"),
    sad = c("sad", "morose", "down")
))
polarity(simpledict)
polarity(simpledict) <- list(pos = "happy", neg = "sad")
polarity(simpledict)

# can list multiple keys
polarity(data_dictionary_LSD2015) <- list(
    pos = c("positive", "neg_negative"),
    neg = c("negative", "neg_positive")
)
polarity(data_dictionary_LSD2015)

quanteda/quanteda.sentiment documentation built on Feb. 26, 2024, 12:42 a.m.