How to bind parameters to SPARQL query without a local graph?

22 visualitzacions
Ves al primer missatge no llegit

Dan Davis

no llegida,
17 de nov. 2017, 23:41:2117/11/17
a rdflib-dev
I want to do binding on a SPARQL query before sending it over the wire.   Consider this query:


SELECT ?descriptor ?label
WHERE {
  ?descriptor a meshv:Descriptor .
  ?descriptor rdfs:label ?label .
  FILTER(REGEX(?label, 'Cobra'))
ORDER BY ?label

How can I construct such a query without providing the expression literal, and then render it as a query?

I've gotten as far as this:

from rdflib.namespace import RDFS, Namespace
from rdflib.plugins.sparql import prepareQuery

MESHV = Namespace('http://id.nlm.nih.gov/mesh')
prefixen = { 'rdfs': RDFS, 'meshv': MESHV }

q = prepareQuery("""SELECT ?descriptor, ?label WHERE {
    ?descriptor a meshv:Descriptor .
    ?descriptor rdfs:label ?label .
    FILTER(REGEX(?label, ?expr)""", initNs=prefixen)

What do I do from here to bind the variable "expr" to the literal "Cobra" and then format back as a query?   What if I am attempting to construct or describe rather than select?  Looking at packages, rdfalchemy looks a lot better here than SPARQLWrapper, but rdfalchemy does not install in my Python 3 environment.

BTW - I'm the implementer and maintainer of the Medical Subject Headings (MeSH) in RDF, and the query I posit above can be run at https://id.nlm.nih.gov/mesh/query - enjoy.




Respon a tots
Respon a l'autor
Reenvia
0 missatges nous