lvaudor / glitter

an R package which writes SPARQL queries
https://lvaudor.github.io/glitter
44 stars 5 forks source link

error with spq_label after adding skos:preflabel #191

Closed maelle closed 1 year ago

maelle commented 1 year ago
spq_init(endpoint = "hal") %>%      
    spq_add("?labo skos:prefLabel ?labo_label") %>%
    spq_add("?labo dcterms:identifier ?labo_id", .required = FALSE) %>% 
    spq_filter(str_detect(labo_label,"EVS|(UMR 5600)|(Environnement Ville Soc)")) %>%
    spq_perform()

works.

library("glitter")
spq_init(endpoint = "hal") %>%      
    spq_add("?labo skos:prefLabel ?labo_label") %>%
    spq_add("?labo dcterms:identifier ?labo_id", .required = FALSE) %>% 
    spq_filter(str_detect(labo_label,"EVS|(UMR 5600)|(Environnement Ville Soc)"))
#> PREFIX dcterms: <http://purl.org/dc/terms/>
#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
#> SELECT ?labo ?labo_label ?labo_id
#> WHERE {
#> 
#> ?labo skos:prefLabel ?labo_label.
#> OPTIONAL {?labo dcterms:identifier ?labo_id.}
#> FILTER(REGEX(?labo_label,"EVS|(UMR 5600)|(Environnement Ville Soc)"))
#> }

spq_init(endpoint = "hal") %>%      
    spq_label(labo, .languages = NULL, .required = TRUE) %>%
    spq_add("?labo dcterms:identifier ?labo_id", .required = FALSE) %>% 
    spq_filter(str_detect(labo_label,"EVS|(UMR 5600)|(Environnement Ville Soc)"))
#> Error in `purrr::map()` at glitter/R/spq_filter.R:22:3:
#> ℹ In index: 1.
#> Caused by error in `spq_translate_dsl()` at glitter/R/spq_filter.R:79:5:
#> ! ✖ Can't find SPARQL equivalent for spq().
#> ℹ If you think there should be one, open an issue in https://github.com/lvaudor/glitter.
#> Backtrace:
#>      ▆
#>   1. ├─... %>% ...
#>   2. ├─glitter::spq_filter(., str_detect(labo_label, "EVS|(UMR 5600)|(Environnement Ville Soc)"))
#>   3. │ └─purrr::reduce(normal_filters, track_filters, .init = .query) at glitter/R/spq_filter.R:29:5
#>   4. │   └─purrr:::reduce_impl(.x, .f, ..., .init = .init, .dir = .dir)
#>   5. │     └─purrr:::reduce_init(.x, .init, left = left, error_call = .purrr_error_call)
#>   6. ├─glitter::spq_add(., "?labo dcterms:identifier ?labo_id", .required = FALSE) at glitter/R/spq_filter.R:29:5
#>   7. │ └─.query %||% spq_init() at glitter/R/spq_add.R:57:3
#>   8. └─glitter::spq_label(., labo, .languages = NULL, .required = TRUE) at glitter/R/spq_add.R:57:3
#>   9.   └─purrr::reduce(...) at glitter/R/spq_label.R:52:3
#>  10.     └─purrr:::reduce_impl(.x, .f, ..., .init = .init, .dir = .dir)
#>  11.       └─glitter (local) fn(out, elt, ...)
#>  12.         └─glitter::spq_filter(q, spq(filter)) at glitter/R/spq_label.R:72:8
#>  13.           └─purrr::map(rlang::enquos(...), spq_treat_filter_argument) at glitter/R/spq_filter.R:22:3
#>  14.             └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>  15.               ├─purrr:::with_indexed_errors(...)
#>  16.               │ └─base::withCallingHandlers(...)
#>  17.               ├─purrr:::call_with_cleanup(...)
#>  18.               └─glitter (local) .f(.x[[i]], ...)
#>  19.                 └─glitter:::spq_translate_dsl(code) at glitter/R/spq_filter.R:79:5
#>  20.                   └─rlang::abort(...) at glitter/R/treat-argument.R:61:5

Created on 2023-09-28 with reprex v2.0.2

lvaudor commented 1 year ago

I have been trying a few things with that but can't seem to get anywhere. I haven't managed to use an argument .languages=NULL in spq_label which you implied you had implemented in Discord (and which is a possibility according to the documentation of spq_label).

The query:

spq_init() %>%      
  spq_add("?labo dcterms:identifier ?labo_id.") %>% 
  spq_label(labo, .required = TRUE,.languages=NULL) %>%
  spq_filter(str_detect(labo_label,"EVS")) %>% 
  spq_head(10)

returns a similar error

Error in `purrr::map()` at glitter/R/spq_filter.R:22:2:
ℹ In index: 1.
Caused by error in `spq_translate_dsl()` at glitter/R/spq_filter.R:79:4:
! ✖ Can't find SPARQL equivalent for spq().