R/NGramLanguageModel.R

Defines functions nglm

Documented in nglm

#' N-gram language model
#'
#' @examples
#' \dontrun{
#' # get working directory
#' # need to pass full path
#' wd <- getwd()
#'
#' # Training to find "WEF"
#' data <- paste("This organisation is called the <START:wef> World Economic Forum <END>",
#'   "It is often referred to as <START:wef> Davos <END> or the <START:wef> WEF <END> .")
#'
#' # train the model
#' model <- tnf_train(model = paste0(wd, "/wef.bin"), lang = "en",
#'   data = data, type = "wef")
#'
#' ngram <- nglm(model)
#' }
#'
#' @keywords internal
nglm <- function(model, output = NULL){

  if(is.null(output))
    output <- tempfile(fileext = ".txt")

  cmd <- paste("NGramLanguageModel", model)

  cat(system2("opennlp", args = cmd, stdout = TRUE), sep = "\n", "\n")

  if(is.null(output))
    unlink("output", recursive = TRUE) # delete temp once read

  return(model)
}
news-r/decipher documentation built on July 19, 2019, 5:58 p.m.