R/utils.R

Defines functions call_julia .build_type warning_in_place .clean_language

globalVariables(c("."))

call_julia <- function(func, ...) {
  assert_that(has_ta(func))
  julia_call(func, ...)
}

.build_type <- function(x){
  if(x == "ngram_document")
    return("NGramDocument")
  
  x <- strsplit(x, "_")[[1]]
  x <- tools::toTitleCase(x)
  paste0(x, collapse = "")
}

warning_in_place <- function(what){
  cat(
    crayon::yellow(cli::symbol$warning),
    " This function changes `", what, "`",
    crayon::yellow(" in place"), "!\n",
    sep = ""
  )
}

.clean_language <- function(lang){
  lang %>% 
    as.character() %>% 
    gsub("Languages\\.", "", .) %>% 
    gsub("\\(\\)", "", .)
}

.doc_by_type <- function(doc, type){
  if(type == "token")
    token_document(doc)
  else if(type == "ngram")
    ngram_document(doc)
  else
    string_document(doc)
}

.strip <- function(func, document){
  func <- paste0("strip_", func)
  julia_assign("sd", document)
  expr <- paste0("sd, ", func)
  julia_eval(paste0("prepare!(", expr, ")"))
}

.get_backend <- function(){
  getOption("TEXTANALYSIS_BACKEND")
}
news-r/textanalysis documentation built on Nov. 4, 2019, 9:40 p.m.