Learn R Programming

textstem (version 0.1.4)

lemmatize_strings: Lemmatize a Vector of Strings

Description

Lemmatize a vector of strings.

Usage

lemmatize_strings(x, dictionary = lexicon::hash_lemmas, ...)

Arguments

x

A vector of strings.

dictionary

A dictionary of base terms and lemmas to use for replacement. The first column should be the full word form in lower case while the second column is the corresponding replacement lemma. The default makes the dictionary from the text using make_lemma_dictionary. For larger texts a dictionary may take some time to compute. It may be more useful to generate the dictionary prior to running the function and explicitly pass the dictionary in.

Other arguments passed to split_token.

Value

Returns a vector of lemmatized strings.

See Also

lemmatize_words

Examples

Run this code
# NOT RUN {
x <- c(
    'the dirtier dog has eaten the pies',
    'that shameful pooch is tricky and sneaky',
    "He opened and then reopened the food bag",
    'There are skies of blue and red roses too!',
    NA,
    "The doggies, well they aren't joyfully running.",
    "The daddies are coming over...",
    "This is 34.546 above"
)

## Default lexicon::hash_lemmas dictionary
lemmatize_strings(x)

## Hunspell dictionary
lemma_dictionary <- make_lemma_dictionary(x, engine = 'hunspell')
lemmatize_strings(x, dictionary = lemma_dictionary)

## Bigger data set
library(dplyr)
presidential_debates_2012$dialogue %>%
    lemmatize_strings() %>%
    head()

# }
# NOT RUN {
## Treetagger dictionary
lemma_dictionary2 <- make_lemma_dictionary(x, engine = 'treetagger')
lemmatize_strings(x, lemma_dictionary2)

lemma_dictionary3 <- presidential_debates_2012$dialogue %>%
    make_lemma_dictionary(engine = 'treetagger')

presidential_debates_2012$dialogue %>%
     lemmatize_strings(lemma_dictionary3) %>%
     head()
# }

Run the code above in your browser using DataLab