lvaudor / glitter

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

spq_filter() has unexpected (absent) output #210

Closed lvaudor closed 10 months ago

lvaudor commented 10 months ago

Why does it return nothing?

flood_id="wd:Q101569184"
  result=spq_init() %>%
    spq_set(flood=flood_id) %>% 
    spq_add("?article schema:about ?flood") %>%  
    spq_filter(str_detect(article, "wikipedia")) %>%
    spq_perform()

The same query without spq_filter DOES return an article containing "wikipedia".

maelle commented 10 months ago

@lvaudor an spq_prefix() call is missing in the reprex, correct?

lvaudor commented 10 months ago

ah, no, I've added schema to my usual prefixes in the meantime so that's not the reason

maelle commented 10 months ago

@lvaudor it's not a glitter bug :tada: the article thing is not a string so one needs to convert it first:

library("glitter")
flood_id = "wd:Q101569184"
spq_init() %>%
    spq_set(flood = flood_id) %>% 
    spq_add("?article schema:about ?flood") %>%  
    spq_mutate(article = as.character(article)) %>%
    spq_filter(str_detect(article, "wikipedia")) %>%
    spq_perform()
#> # A tibble: 1 × 2
#>   flood                                     article                             
#>   <chr>                                     <chr>                               
#> 1 http://www.wikidata.org/entity/Q101569184 https://es.wikipedia.org/wiki/Inund…

Created on 2023-12-21 with reprex v2.0.2