Parameterised SPARQL Construct web service

28 views
Skip to first unread message

David Habgood

unread,
Aug 11, 2022, 9:19:06 PM8/11/22
to TopBraid Suite Users
Hi,

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:
```
exfun:test5
a dash:ScriptFunction ;
dash:apiStatus dash:Stable ;
dash:canWrite true ;
dash:js """
function collectTriples(subject, triples) {
graph.triples(subject, null, null, true).forEach(t => {
triples.push(t);
if(t.object.isBlankNode()) {
collectTriples(t.object, triples);
}
})
}
let triples = [];
collectTriples(focusNode, triples);
IO.serializeRDF(triples)
""" ;
rdfs:label "test 5" ;
.
```
This is close to what I want (need to remove newline characters etc.: ""@prefix arg: <http://spinrdf.org/arg#> .\n@prefix dash: <http://datashapes.org/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).

Thanks

Holger Knublauch

unread,
Aug 12, 2022, 3:18:26 AM8/12/22
to topbrai...@googlegroups.com
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.

Holger



--
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 topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/ae6710aa-eb5a-4adb-891d-dbbb6fc47ce1n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages