Learn R Programming

quanteda (version 0.9.9-50)

dictionary: create a dictionary

Description

Create a quanteda dictionary class object, either from a list or by importing from a foreign format. Currently supported input file formats are the Wordstat, LIWC, Lexicoder v2 and v3, and Yoshikoder formats. The import using the LIWC format works with all currently available dictionary files supplied as part of the LIWC 2001, 2007, and 2015 software (see References).

Usage

dictionary(..., file = NULL, format = NULL, concatenator = " ",
  tolower = TRUE, encoding = "auto")

Arguments

...
a named list of character vector dictionary entries, including valuetype pattern matches, and including multi-word expressions separated by concatenator. The argument may be an explicit list or named set of elements that can be turned into a list. See examples. This argument may be omitted if the dictionary is read from file.
file
file identifier for a foreign dictionary
format
character identifier for the format of the foreign dictionary. If not supplied, the format is guessed from the dictionary file's extension. Available options are:
"wordstat"
format used by Provalis Research's Wordstat software
"LIWC"
format used by the Linguistic Inquiry and Word Count software
"yoshikoder"
format used by Yoshikoder software
"lexicoder"
format used by Lexicoder
"YAML"
the standard YAML format
concatenator
the character in between multi-word dictionary values. This defaults to "_" except LIWC-formatted files, which defaults to a single space " ".
tolower
if TRUE, convert all dictionary values to lowercase
encoding
additional optional encoding value for reading in imported dictionaries. This uses the iconv labels for encoding. See the "Encoding" section of the help for file.

Value

A dictionary class object, essentially a specially classed named list of characters.

References

Wordstat dictionaries page, from Provalis Research http://provalisresearch.com/products/content-analysis-software/wordstat-dictionary/.

Pennebaker, J.W., Chung, C.K., Ireland, M., Gonzales, A., & Booth, R.J. (2007). The development and psychometric properties of LIWC2007. [Software manual]. Austin, TX (www.liwc.net).

Yoshikoder page, from Will Lowe http://conjugateprior.org/software/yoshikoder/.

Lexicoder format, http://www.lexicoder.com

See Also

dfm

Examples

Run this code
mycorpus <- corpus_subset(data_corpus_inaugural, Year>1900)
mydict <- dictionary(list(christmas = c("Christmas", "Santa", "holiday"),
                          opposition = c("Opposition", "reject", "notincorpus"),
                          taxing = "taxing",
                          taxation = "taxation",
                          taxregex = "tax*",
                          country = "america"))
head(dfm(mycorpus, dictionary = mydict))

# also works
mydict2 <- dictionary(christmas = c("Christmas", "Santa", "holiday"),
                      opposition = c("Opposition", "reject", "notincorpus"))
dfm(mycorpus, dictionary = mydict2)

## Not run: ------------------------------------
# # import the Laver-Garry dictionary from http://bit.ly/1FH2nvf
# lgdict <- dictionary(file = "http://www.kenbenoit.net/courses/essex2014qta/LaverGarry.cat",
#                      format = "wordstat")
# head(dfm(data_corpus_inaugural, dictionary = lgdict))
# 
# # import a LIWC formatted dictionary from http://www.moralfoundations.org
# mfdict <- dictionary(file = "http://ow.ly/VMRkL", format = "LIWC")
# head(dfm(data_corpus_inaugural, dictionary = mfdict))
## ---------------------------------------------

Run the code above in your browser using DataLab