@@ -63,6 +63,8 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
63
63
public = list (
64
64
# '@field rdf rdf
65
65
rdf = NULL ,
66
+ # '@field rdf_data rdf_data
67
+ rdf_data = NULL ,
66
68
# '@field endpoint endpoint
67
69
endpoint = NULL ,
68
70
@@ -125,6 +127,23 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
125
127
}
126
128
},
127
129
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
+
128
147
# '@description Ping query
129
148
ping = function (){
130
149
str = " SELECT ?s ?p ?o WHERE {
@@ -212,15 +231,7 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
212
231
dplyr :: filter(lang == language )
213
232
}
214
233
# 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()
224
235
# Create a hierarchy data.frame
225
236
out1 = sparql_result %> %
226
237
dplyr :: filter(p == " http://www.w3.org/2004/02/skos/core#broader" ) %> %
@@ -310,9 +321,17 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
310
321
# '@param uri uri
311
322
# '@param graphUri graphUri
312
323
# '@param mimetype mimetype
313
- # '@return the response of the SPARQL query
324
+ # '@return an object of class \link[tibble]{tibble}
314
325
query_from_uri = function (uri , graphUri = NULL , mimetype = " text/csv" ){
315
326
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
+
316
335
str = paste0(
317
336
" PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
318
337
SELECT ?concept ?lang ?prefLabel
@@ -346,9 +365,17 @@ geoflow_skos_vocabulary <- R6Class("geoflow_skos_vocabulary",
346
365
# '@param term term
347
366
# '@param graphUri graphUri
348
367
# '@param mimetype mimetype
349
- # '@return the response of the SPARQL query
368
+ # '@return an object of class \link[tibble]{tibble}
350
369
query_from_term = function (term , graphUri = NULL , mimetype = " text/csv" ){
351
370
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
+
352
379
str = paste0(
353
380
" PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
354
381
SELECT ?concept ?lang ?prefLabel ?collection ?collectionLabel
0 commit comments