Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spq_set should work with URIs (probably) #209

Open
lvaudor opened this issue Dec 7, 2023 · 2 comments · May be fixed by #214
Open

spq_set should work with URIs (probably) #209

lvaudor opened this issue Dec 7, 2023 · 2 comments · May be fixed by #214

Comments

@lvaudor
Copy link
Owner

lvaudor commented Dec 7, 2023

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

@maelle
Copy link
Collaborator

maelle commented Dec 21, 2023

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

@lvaudor
Copy link
Owner Author

lvaudor commented Dec 21, 2023

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

@maelle maelle linked a pull request Dec 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants