I want to do binding on a SPARQL query before sending it over the wire.  
 Consider this query:


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>

SELECT ?descriptor ?label
FROM <http://id.nlm.nih.gov/mesh>
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.




-- 
http://github.com/RDFLib
--- 
You received this message because you are subscribed to the Google Groups 
"rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rdflib-dev+unsubscr...@googlegroups.com.
To post to this group, send email to rdflib-dev@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rdflib-dev/0cd930c1-462d-4012-9414-03e1c77c1758%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to