Skip to content

Commit 71409ec

Browse files
committed
#401 query_from_term/query_from_uri with RDF data file
1 parent 8ca5815 commit 71409ec

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

R/geoflow_vocabulary.R

+38-11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
6363
public = list(
6464
#'@field rdf rdf
6565
rdf = NULL,
66+
#'@field rdf_data rdf_data
67+
rdf_data = NULL,
6668
#'@field endpoint endpoint
6769
endpoint = NULL,
6870

@@ -125,6 +127,23 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
125127
}
126128
},
127129

130+
#'@description Queries full dataset
131+
#'@return an object of class \link[tibble]{tibble}
132+
query_full_dataset = function(){
133+
if(is.null(self$rdf_data)){
134+
self$rdf_data = self$query(
135+
str = "SELECT ?s ?p ?o ?lang WHERE {
136+
?s ?p ?o .
137+
OPTIONAL {
138+
BIND(LANG(?o) AS ?lang)
139+
}
140+
}",
141+
mimetype = "text/csv"
142+
)
143+
}
144+
return(self$rdf_data)
145+
},
146+
128147
#'@description Ping query
129148
ping = function(){
130149
str = "SELECT ?s ?p ?o WHERE {
@@ -212,15 +231,7 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
212231
dplyr::filter(lang == language)
213232
}
214233
#perform base sparql result
215-
sparql_result = self$query(
216-
str = "SELECT ?s ?p ?o ?lang WHERE {
217-
?s ?p ?o .
218-
OPTIONAL {
219-
BIND(LANG(?o) AS ?lang)
220-
}
221-
}",
222-
mimetype = "text/csv"
223-
)
234+
sparql_result = self$query_full_dataset()
224235
# Create a hierarchy data.frame
225236
out1 = sparql_result %>%
226237
dplyr::filter(p == "http://www.w3.org/2004/02/skos/core#broader") %>%
@@ -310,9 +321,17 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
310321
#'@param uri uri
311322
#'@param graphUri graphUri
312323
#'@param mimetype mimetype
313-
#'@return the response of the SPARQL query
324+
#'@return an object of class \link[tibble]{tibble}
314325
query_from_uri = function(uri, graphUri = NULL, mimetype = "text/csv"){
315326

327+
if(!is.null(self$rdf_data)){
328+
rec = self$rdf_data[self$rdf_data$s == uri &
329+
self$rdf_data$p == "http://www.w3.org/2004/02/skos/core#prefLabel",]
330+
rec = rec[,c("s", "lang", "o")]
331+
colnames(rec) = c("concept", "lang", "prefLabel")
332+
return(rec)
333+
}
334+
316335
str = paste0(
317336
"PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
318337
SELECT ?concept ?lang ?prefLabel
@@ -346,9 +365,17 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
346365
#'@param term term
347366
#'@param graphUri graphUri
348367
#'@param mimetype mimetype
349-
#'@return the response of the SPARQL query
368+
#'@return an object of class \link[tibble]{tibble}
350369
query_from_term = function(term, graphUri = NULL, mimetype = "text/csv"){
351370

371+
if(!is.null(self$rdf_data)){
372+
rec = self$rdf_data[self$rdf_data$o == term & !is.na(self$rdf_data$o) &
373+
self$rdf_data$p == "http://www.w3.org/2004/02/skos/core#prefLabel",]
374+
rec = rec[,c("s", "lang", "o")]
375+
colnames(rec) = c("concept", "lang", "prefLabel")
376+
return(rec)
377+
}
378+
352379
str = paste0(
353380
"PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
354381
SELECT ?concept ?lang ?prefLabel ?collection ?collectionLabel

man/geoflow_skos_vocabulary.Rd

+18-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)