R/Lemmatize.R

Defines functions Lemmatize

Documented in Lemmatize

#' @title Lemmatizer
#'
#' @description This function allows you lemmatize words using the treetag lemmatizer
#' @param word word to lemmatize, if multiple use loop/apply/dplyr
#' @param print Whether to print word being lemmatized. Useful for long lists of words. Defaults to TRUE
#' @return lemmatized words
#' @export Lemmatize


Lemmatize = function(word, print =T, debug = F){
  if (print == T){
    print(word)}
  if(!is.na(word)){
    if(word == ""){
      return("")}}
    lemmax = koRpus::treetag(as.character(word), treetagger="manual", format="obj", debug = debug, TT.tknz=T, lang="en", TT.options=list(path="C:\\treetagger", preset="en"))
  if(lemmax@TT.res[["lemma"]] == "<unknown>"){
    if (print == T){
    print(lemmax@TT.res[["token"]])}
    return (lemmax@TT.res[["token"]])}
  else{
    if (print == T){
    print(lemmax@TT.res[["lemma"]])}
    return(lemmax@TT.res[["lemma"]])
}}
gandalfnicolas/ADCAT documentation built on April 15, 2020, 8:26 p.m.