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)?
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:
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)?