diff --git a/R/jiebar.R b/R/jiebar.R index 724c5dd..eff2955 100644 --- a/R/jiebar.R +++ b/R/jiebar.R @@ -143,6 +143,16 @@ worker <- function(type = "mix", dict = DICTPATH, hmm = HMMPATH, if(!any(type == c("mix","mp","hmm","query","simhash","keywords","tag"))){ stop("Unkown worker type") } + jiebapath <- find.package("jiebaR") + if(!file.exists(file.path(jiebapath,"dict","jieba.dict.utf8"))){ + unzip(file.path(jiebapath,"dict","jieba.dict.zip"),exdir =file.path( jiebapath,"dict") ) + } + if(!file.exists(file.path(jiebapath,"dict","hmm_model.utf8"))){ + unzip(file.path(jiebapath,"dict","hmm_model.zip"),exdir =file.path( jiebapath,"dict") ) + } + if(!file.exists(file.path(jiebapath,"dict","idf.utf8"))){ + unzip(file.path(jiebapath,"dict","idf.zip"),exdir =file.path( jiebapath,"dict") ) + } result = new.env(parent = emptyenv()) switch(type, diff --git a/R/zzz.R b/R/zzz.R index 4136e04..cbbb22c 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -31,16 +31,7 @@ STOPPATH<-NULL # if (.Platform$OS.type == "windows") { # Sys.setlocale( locale = "English") # } - if(!file.exists(file.path(find.package("jiebaR"),"dict","jieba.dict.utf8"))){ - unzip(file.path(find.package("jiebaR"),"dict","jieba.dict.zip"),exdir =file.path(find.package("jiebaR"),"dict") ) - } - if(!file.exists(file.path(find.package("jiebaR"),"dict","hmm_model.utf8"))){ - unzip(file.path(find.package("jiebaR"),"dict","hmm_model.zip"),exdir =file.path(find.package("jiebaR"),"dict") ) - } - if(!file.exists(file.path(find.package("jiebaR"),"dict","idf.utf8"))){ - unzip(file.path(find.package("jiebaR"),"dict","idf.zip"),exdir =file.path(find.package("jiebaR"),"dict") ) - } - + assign(x = "DICTPATH", file.path(find.package("jiebaR"),"dict","jieba.dict.utf8"),asNamespace('jiebaR')) assign(x = "HMMPATH", file.path(find.package("jiebaR"),"dict","hmm_model.utf8"),asNamespace('jiebaR')) assign(x = "USERPATH", file.path(find.package("jiebaR"),"dict","user.dict.utf8"),asNamespace('jiebaR'))