Parameterised SPARQL Construct web service

Skip to first unread message

David Habgood

Aug 11, 2022, 9:19:06 PMAug 11
to TopBraid Suite Users

I have a use case to expose web services (on EDG i.e. appearing in the Swagger page) which are basically parameterised SPARQL queries. I've got this working for SELECT and ASK queries, using dash:SPARQLMultiFunction and dash:ScriptFunction respectively. I'd like something similar for CONSTRUCT, that can return RDF. So far, I've only been able to get close using a dash:ScriptFunction e.g. using the below:
a dash:ScriptFunction ;
dash:apiStatus dash:Stable ;
dash:canWrite true ;
dash:js """
function collectTriples(subject, triples) {
graph.triples(subject, null, null, true).forEach(t => {
if(t.object.isBlankNode()) {
collectTriples(t.object, triples);
let triples = [];
collectTriples(focusNode, triples);
""" ;
rdfs:label "test 5" ;
This is close to what I want (need to remove newline characters etc.: ""@prefix arg: <> .\n@prefix dash: <> .\n@prefix dc:")

However the above ADS script is more complex than the SELECT and ASK cases, which are just wrapped  SPARQL. It seems unnecessarily complex for what could be a parameterised SPARQL CONSTRUCT. Is there a simpler way to achieve this? (and ideally obey content negotiation/deliver other RDF serialisations, as per the SPARQL endpoint).


Holger Knublauch

Aug 12, 2022, 3:18:26 AMAug 12
Hi David,

I have been thinking about this for a while but don't have a generic solution yet. I assume you would like to declare parameters too, so that these parameters are listed on the Swagger page. The best approximation is similar to your code, but if you want to store the CONSTRUCT queries better you could represent them as instances of dash:SPARQLConstructTemplate which are also instances of dash:ScriptFunction, where the dash:js may simply call a generic helper function from a dash:IncludedScript. Store the CONSTRUCT body in sh:construct and pass it into the helper function for execution. Not perfect and this would not solve content negotiation.

A proper solution would require a new feature request/ticket. I am not sure when I could realistically get to this given that we are pulled in so many directions ATM.

NB: We do have an old SPIN templates servlet that does handle CONSTRUCT queries, but it's not using DASH vocabulary and wouldn't show up on Swagger.


You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Reply all
Reply to author
0 new messages