Skip to content

Commit

Permalink
dbpedia_spotlight_status() without warnings if docker not running #32
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Blätte authored and Andreas Blätte committed Feb 26, 2024
1 parent a2e2f8c commit d157ecd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* `xml_enrich()` now adds new attributes to pre-annotated features
* `get_dbpedia_uris()` method now includes argument `expand_to_token` for subcorpus_bundles as well
* `map_types_to_class()` works with the list representation in the types column
* `dbpedia_spotlight_status()` without warnings if docker not available / not running #32.

## dbpedia v0.1.1.9010
* new functions `to_annotation()`, `xml_enrich()` `namespaced_xpath()` and method `get_dbpedia_uris()` for xml docs.
Expand Down
25 changes: 19 additions & 6 deletions R/dbpedia.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' Check whether Docker container with DBpedia Spotlight is running locally
#' and set options 'dbpedia.lang' and 'dbpedia.endpoint' accordingly.
#' @return Object of class `dbpedia_spotlight_stats`, a `list` with elements
#' @return Object of class `dbpedia_spotlight_status`, a `list` with elements
#' "docker" (`TRUE`/`FALSE`), "lang" and "endpoint".
#' @rdname dbpedia_spotlight_status
#' @export
Expand All @@ -18,16 +18,28 @@ dbpedia_spotlight_status <- function(){
status <- list(docker = FALSE, lang = NA_character_, api = NA_character_)
class(status) <- c("dbpedia_spotlight_status", class(status))

# Check whether Docker is installed
stdout <- system2(command = "docker", stdout = FALSE, stderr = NULL)

if (stdout == 0){
stdout <- system2(
stdout <- suppressWarnings(system2(
command = "docker",
args = c("container", "ls"),
stdout = TRUE
)

if (grepl("dbpedia/dbpedia-spotlight", stdout[2])){
stdout = TRUE,
stderr = NULL
))

if (!is.null(attr(stdout, "status"))){ # Docker installed, but not running
if (attr(stdout, "status") == 1L){
status[["docker"]] <- FALSE
status[["lang"]] <- "en"
status[["endpoint"]] <- "http://api.dbpedia-spotlight.org/en/annotate"
} else {
cli_alert_warning(
"status of running `docker container ls`: {attr(stdout, 'status')}"
)
}
} else if (grepl("dbpedia/dbpedia-spotlight", stdout[2])){
status[["docker"]] <- TRUE
status[["lang"]] <- gsub(
'^.*"spotlight.sh\\s+(\\w{2})".*$',
Expand Down Expand Up @@ -62,6 +74,7 @@ print.dbpedia_spotlight_status <- function(x, ...){
cli_text(style_bold("DBpedia Spotlight settings:"))
cli_bullets(
c(
"*" = "docker engine: {col_cyan({if (x[['docker']]) 'running' else 'not running'})}",
"*" = "endpoint: {col_cyan({x[['endpoint']]})}",
"*" = "language: {col_cyan({x[['lang']]})}"
)
Expand Down

0 comments on commit d157ecd

Please sign in to comment.