Skip to content

Commit

Permalink
utf8-ize in format.rdf rather than print.rdf
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed May 16, 2018
1 parent d5105ed commit 793d33e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
42 changes: 29 additions & 13 deletions R/rdf_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,21 @@ length.rdf <- function(x){
redland::librdf_model_size(x$model@librdf_model)
}

#' @export
print.rdf <- function(x, ...){
cat(format.rdf(x, ...), sep = "\n")
}


#' @importFrom stringi stri_unescape_unicode
#' @export
# @param max_print maximum number of lines to print of rdf preview
# @param max_preview if number of triples exceeds this, no preview
# will be displayed, since preview method must currently serialize
# entire triplestore.
format.rdf <- function(x,
format = getOption("rdf_print_format", "nquads"),
max_print = getOption("rdf_max_print", 10L),
max_preview = 1e5,
...){
print.rdf <- function(x,
format = getOption("rdf_print_format", "nquads"),
max_print = getOption("rdf_max_print", 10L),
max_preview = 1e5,
...){

n <- redland::librdf_model_size(x$model@librdf_model)
header <- paste0("Total of ", n, " triples, stored in ", x$storage@type, "\n",
"-------------------------------\n")
"-------------------------------\n")

if(n < max_preview){
tmp <- tempfile()
rdf_serialize(x,
Expand All @@ -70,5 +65,26 @@ format.rdf <- function(x,
} else {
txt <- paste(header, "\n (preview supressed for performance)")
}

cat(txt, sep = "\n")
}


#' @importFrom stringi stri_unescape_unicode
#' @export
format.rdf <- function(x,
format = getOption("rdf_print_format", "nquads"),
...){
tmp <- tempfile()
rdf_serialize(x,
tmp,
format = format,
...)
## Fix encoding on nquads, ntriples

txt <- paste0(header, stringi::stri_unescape_unicode(
paste(readLines(tmp, n = max_print), collapse = "\n")),
footer)
unlink(tmp)
txt
}
1 change: 1 addition & 0 deletions man/rdflib-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 793d33e

Please sign in to comment.