Paul,

I tthink that was it - there is a very sophisticated traverse function in 
rdflib.plugins.sparql.algebra that can do what I want, and I think it can 
also do what you want with an io.StringIO.   I need to go farther to get it 
back into a SPARQL query, but it is beginning to seem like simply work, 
rather than discovery.

Here's what I was able to do:

from rdflib import Variable, Literal
from rdflib.nampsace import Namespace, RDFS
from rdflib.plugins.sparql.parser import parseQuery
from rdflib.plugins.sparql.algebra import traverse

query_string = """
SELECT ?s ?l
FROM <http://id.nlm.nih.gov/mesh>
WHERE {
    ?s a meshv:Descriptor .
    ?s rdfs:label ?l .
    FILTER(REGEX(?l, ?expr)) .
}
"""

query = parseQuery(query_string)

# I now want to bind ?expr to "Cobra" and search for desriptors whose label 
includes "Cobra" in them
bindings = { Variable('expr'): Literal('Cobra') }

def convertBoundVar(v):
    if instanceof(v, Variable) and v in bindings:
        return bindings[v]
    return None

new_query = traverse(query, visitPost=convertBoundVar)

So, if we have an io in a closure, we can convert it back to a SPARQL query 
as we traverse it.

from io import StringIO
qbuf = StringIO()

and so on...

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rdflib-dev/a647b95d-a530-4313-8d41-8f7fa60dc8d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to