Hi! Is it possible to send in more than one URI as parameter to a parameterized query? So I can run the query once with n-parameters instead of running the query n-times. Or is this depended on the SPARQL-endpoint implementation?
If you are using SPARQL 1.1, you can take advantage of the values keyword, which lets you pass multiple values in a parameter (and multiple parameters). For instance, in the following:
select ?title where {
?chapter a class:_Chapter.
?chapter chapter:title ?title.
filter(strstarts(?title,?letter))
values ?letter {“D” “M”}
}
The solution returns titles that begin with both “D” and “M”.
Bob Ducharme wrote up an excellent piece on how you can use values for all kinds of things:
@veronahe do you want to perform a kind of “vectorized” query, where the same query gets re-run with several values for a given parameter?
In lieu of using an endpoint for queries, it would depend on the RDF/SPARQL library being used, though most make it simple to apply a collection and iterate. I guess a question is whether a SPARQL query engine would cache intermediate results and reuse these as it iterates – that’s more complex.
For those of use writing open source distributed query engines, this is helpful feedback – will share with our team.
@veronahe I am not aware of something like query templates or parameter are part of the SPARQL 1.1 standard. Thus, such support would depend on the features of the endpoint you are using. Our implementation, e.g. supports jinja template syntax where you can use {{myParam}} placeholders in your query text that can be defined in the query UI and/or provided with your http request.
Hi all! Thanks for your inputs.
It seems like VALUES could have been a solution. However, as mentioned, parameterized SPARQL-queries are not a part of SPARQL 1.1. Maybe in 1.2. (https://github.com/w3c/sparql-12/issues/57)? And it differs between vendors/SPARQL-endpoints on how it’s implemented. The solution I was looking for in my particular case is something like Stardog’s UNNEST (Query Stardog | Stardog Documentation 7.5.0). But since I’m using a different provider than Stardog, I would have to go for a string-workaround. Which is not too unusual after all. I got a lot of nice feedback when posting the same question on Twitter as well. Maybe of interest to some? https://twitter.com/veronikaheim/status/1466678998885441536