[redland-dev] sparql queries and contexts

Kai Bielenberg kai at bielenberg.info
Sat Feb 12 19:10:59 GMT 2005


Hi,

I am wondering if it is possible to use sparql queries and contexts 
together. A quick example:

import RDF
model=RDF.Model(storage=RDF.MemoryStorage(options_string="contexts='yes'"))
parser=RDF.Parser()
uri=RDF.Uri(string="http://del.icio.us/rss/kaiman")
stream=parser.parse_as_stream(uri)

context=RDF.Node(uri_string="http://foo.de/bar")

while not stream.end():
     model.append(stream.current(),context)
     stream.next()

query = RDF.SPARQLQuery("""PREFIX dc: <http://purl.org/dc/elements/1.1/>
                            SELECT ?creator, ?date
                            WHERE (?item dc:creator ?creator)
                                  (?item dc:date ?date)
                                  """)

results=query.execute(model)

Now I can access the results like this:

for r in results:
     print r

But how to get information about the current context? I cannot convert 
results into a stream (because QueryResults is not a graph) and do 
something like stream.context().

Any suggestions?

Kai


More information about the redland-dev mailing list