glitter icon indicating copy to clipboard operation
glitter copied to clipboard

spq_set should work with URIs (probably)

Open lvaudor opened this issue 2 years ago • 2 comments

When working on "combined queries" I often need to replace URIs with their abbreviated versions for use in spq_set(). For instance, I run a first query that returns a list of countries, such as:

country_id="http://www.wikidata.org/wiki/Q142"

Then I want to run a query to get the coordinates of each country, and to do that I define a function:

get_country_coords=function(country_id){
  country_id=stringr::str_replace(country_id, "http://www.wikidata.org/entity/", "wd:")
  result=spq_init() %>%
    spq_set(country=country_id) %>% 
    spq_add("?country wdt:P625 ?coords_country") %>%
    spq_select(-country) %>% 
    spq_perform() 
  result
}

Would that be possible to modify spq_set() so that it works with both "wd:Q142" and full URI ""http://www.wikidata.org/entity/Q142"" (and make that use of stringr::str_replace useless)?

lvaudor avatar Dec 07 '23 08:12 lvaudor

does it work for SPARQL itself, could you write an example SPARQL query?

maelle avatar Dec 21 '23 12:12 maelle

The idea would be (in R, not SPARQL) to generate the right VALUES based on a prefixed URI like wd:Q142.

lvaudor avatar Dec 21 '23 12:12 lvaudor