Skip to content

Commit b5ad33b

Browse files
jefshenumbers
authored andcommitted
Read properties file in lib_location if it exists
1 parent fa0c65f commit b5ad33b

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

R/backend_corenlp.R

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,16 @@ cnlp_init_corenlp <- function(language, anno_level = 2, lib_location = NULL,
8888
lib_location <- file.path(system.file("extdata", package="cleanNLP"),
8989
"/stanford-corenlp-full-2018-10-05")
9090

91-
# set properties that are not "corenlp" properties
91+
# set properties
9292
volatiles$corenlp$language <- language
9393
volatiles$corenlp$lib_location <- lib_location
9494
volatiles$corenlp$mem <- mem
9595
volatiles$corenlp$verbose <- verbose
96+
volatiles$corenlp$properties <- list()
97+
98+
fin <- file.path(lib_location, "/properties.rds")
99+
if (file.exists(fin))
100+
volatiles$corenlp$properties <- readRDS(fin)
96101

97102
# German models
98103
if (language == "de" & anno_level == 0) {
@@ -377,22 +382,13 @@ setup_corenlp_backend_raw <- function(keys, values, clear = FALSE) {
377382
stop("values must be a character vector")
378383

379384
# read current parameter file
380-
if (!clear) {
381-
fin <- file.path(system.file("extdata", package="cleanNLP"),
382-
"properties.rds")
383-
if (file.exists(fin))
384-
prop <- readRDS(fin)
385-
else
386-
prop <- list()
387-
} else prop <- list()
385+
if (clear) {
386+
volatiles$corenlp$properties <- list()
387+
}
388388

389389
# insert new keys and values
390390
for (i in seq_along(keys))
391-
prop[[keys[i]]] <- values[i]
392-
393-
# save new parameter file
394-
saveRDS(prop, file.path(system.file("extdata",
395-
package="cleanNLP"), "properties.rds"))
391+
volatiles$corenlp$properties[[keys[i]]] <- values[i]
396392
}
397393

398394
init_corenlp_backend <- function() {
@@ -413,12 +409,11 @@ init_corenlp_backend <- function() {
413409
}
414410

415411
# Parse default parameters
416-
fp <- file.path(system.file("extdata",package="cleanNLP"),
417-
"properties.rds")
418-
if (!file.exists(fp)) {
412+
if (length(volatiles$corenlp$properties) == 0) {
419413
setup_corenlp_backend_raw("en")
420414
}
421-
properties <- readRDS(fp)
415+
416+
properties <- volatiles$corenlp$properties
422417
keys <- names(properties)
423418
values <- as.character(properties)
424419
lang <- volatiles$corenlp$language

0 commit comments

Comments
 (0)