R/setDict.R

#' Set the path to the dictionary
#'
#' @param path Path to the YARN dictionary
#' @examples \dontrun{
#' setDict("yarn.xml")
#' }
#' @export
setDict <- function(path) {
  if (!file.exists(path)) {
    stop("File doesn't exists")
  }
  
  yarn <- xmlParse(path, useInternalNodes = TRUE, options = HUGE)
  .yarn$root <- xmlRoot(yarn)
  if (xmlName(.yarn$root) != 'yarn') {
    .yarn$root <- NULL
    stop("Wrong dictionary")
  }
}


#' Download dictionary
#' 
#' @param url URL
#' @param set Set dictionary
#' @export
downloadDict <- function(url='http://russianword.net/yarn.xml', set=TRUE) {
  download.file(url, destfile = 'yarn.xml')
  if (set)
    setDict('yarn.xml')
}


getDict <- function() {
  if (!is.null(.yarn$root)) {
    .yarn$root
  } else {
    stop("Could not find YARN dictionary. For more details see ?setDict or ?downloadDict")
  }
}
Dementiy/yarn documentation built on May 6, 2019, 2:10 p.m.