R/clema.R

Defines functions clema

Documented in clema

#' Lemmatize words using a chilean spanish dictionary
#'
#' @param words A word or a vector of words to lemmatize
#' @param replace If true the function will replace the NA values with originals
#'
#' @return A lemmatized vector of words
#' @export
#'
#' @examples clema("carabinera")
clema <- function(words, replace=TRUE) {

  stopifnot(!is.na(words))

  value <- spacy_lemma_dictionary_es_cl[match(words, spacy_lemma_dictionary_es_cl$ind), ]$values

  if(replace==TRUE) {
    value <- replace(value, is.na(value), words[is.na(value)])
  }

  return(value)

}
robsalasco/clema documentation built on Nov. 5, 2019, 3:14 a.m.