View source: R/textstat_valence.R
textstat_valence | R Documentation |
Compute sentiment scores from tokens or document-feature matrices, based on the valences of dictionary keys and values.
textstat_valence(
x,
dictionary,
normalization = c("dictionary", "all", "none"),
...
)
x |
a character, corpus, tokens, or dfm object containing text, tokens, or features whose sentiment will be scored. |
dictionary |
a quanteda dictionary that has valence set, in the form of numerical valences associated with sentiment |
normalization |
the baseline for normalizing the sentiment counts after
scoring. Sentiment scores within keys are weighted means of the tokens
matched to dictionary values, weighted by their valences. The default
|
... |
not used here |
a data.frame of sentiment scores
If the input item is a dfm, then multi-word values will not be matched unless the features of the dfm have been compounded previously. The input objects should not have had dictionaries applied previously.
For a discussion of how to aggregate sentiment scores to the document level, see:
Lowe, W., Benoit, K. R., Mikhaylov, S., & Laver, M. (2011). Scaling Policy Preferences from Coded Political Texts. Legislative Studies Quarterly, 36(1), 123–155. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/j.1939-9162.2010.00006.x")}
valence()
library("quanteda")
## Not run:
# AFINN
afinn <- read.delim(system.file("extdata/afinn/AFINN-111.txt",
package = "quanteda.sentiment"),
header = FALSE, col.names = c("word", "valence"))
data_dictionary_afinn <- dictionary(list(afinn = afinn$word))
valence(data_dictionary_afinn) <- list(afinn = afinn$valence)
textstat_valence(toks, dictionary = data_dictionary_afinn)
# ANEW
anew <- read.delim(url("https://bit.ly/2zZ44w0"))
anew <- anew[!duplicated(anew$Word), ] # because some words repeat
data_dictionary_anew <- dictionary(list(pleasure = anew$Word,
arousal = anew$Word,
dominance = anew$Word))
valence(data_dictionary_anew) <- list(pleasure = anew$ValMn,
arousal = anew$AroMn,
dominance = anew$DomMn)
textstat_valence(toks, data_dictionary_anew["pleasure"])
textstat_valence(toks, data_dictionary_anew["arousal"])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.