On 17/06/15 00:18, Holger Knublauch wrote:
On 6/16/2015 22:03, Osma Suominen wrote:
Here's a slightly relevant discussion about how to support something
like pre-bound variables / parametrized queries in YASQE, a graphical
SPARQL editor component in the YASGUI suite (and used by Fuseki among
others): https://github.com/YASGUI/YASQE/issues/24
Thanks for the pointer.
I'm not sure I understand all the issues here very deeply, but it
would seem useful to have a standard way of expressing and executing
parametrized SPARQL queries, which could then be applied by YASQE and
SHACL among others.
Indeed. Maybe the SHACL templates [1] could be one solution to that,
assuming SHACL becomes a W3C standard. In the current draft you would
specify a template as
ex:MyTemplate
a sh:Template ;
rdfs:label "My template" ;
rdfs:comment "Gets a list of all people born in a given country" ;
sh:argument [
sh:predicate ex:country ;
sh:valueType schema:Country ;
rdfs:comment "The country to get all people for" ;
] ;
sh:sparql """
SELECT ?person
WHERE {
?person ex:bornIn ?country .
} """ ;
.
This structure provides enough metadata to drive user interfaces, e.g.
input forms where users select a country from a list. The semantics in
the current draft are that variables become pre-bound (ex:country ->
?country). This approach has the advantage that each query can be
instantiated as a naturally valid RDF instance, e.g.
ex:ExampleQuery
a ex:MyTemplate ;
ex:country ex:Germany .
This can then be used as a high level language for all kinds of query
calls as constraints, rules or whatever - experts can prepare the SPARQL
while end users just fill in the blanks.
The semantics are intended to be like inserting a VALUES clause into the
"beginning" of the query, i.e. they wouldn't be visible in sub-selects
etc. In contrast to text-substitution algorithms, this also makes sure
that queries are always syntactically valid and can be pre-compiled.
"prepared queries" are certainly the way to go. The phrase
"text-substitution algorithms" is probably a placeholder for a spectrum
of possibilities from string bashing (i.e. before parsing) to modifying
the post-parser AST (so no firing up the parser - good for the
high-frequency queries I'm guessing that SHACL will be doing). In ARQ
you can modify the query plan (the algebra) in the same style as AST
modification making it post-optimizer.
Is anyone looking at a language (based on JSON, YAML whatever) as a DSL
targeting the RDF formal language?
Andy
Holger
[1] http://w3c.github.io/data-shapes/shacl/#templates