#!/bin/env python print "==== Example 6 - RDQL query / bound variable results" print "==== Get the titles of the books" import joseki import sys from joseki import JosekiRequest from rdflib.URIRef import URIRef from rdflib.Namespace import Namespace from resultset import ResultSet, ResultBinding # A better name for the "wildcard" in a triple match ANY = None # Declare constants: better to use namespaces DC = Namespace("http://purl.org/dc/elements/1.1/") dcTitle = DC['title'] # The target model URL # This is the Joseki online demo modelURL = "http://jena.hpl.hp.com:2020/books" if len(sys.argv) > 1: modelURL = sys.argv[1] print "Data source =", modelURL book1 = URIRef("http://example.org/book/book1") book2 = URIRef("http://example.org/book/book2") book3 = URIRef("http://example.org/book/book3") book4 = URIRef("http://example.org/book/book4") book5 = URIRef("http://example.org/book/book5") # ---------------------------------------- rdql="SELECT ?book, ?title WHERE "+\ "(?book ?title)" BV="http://jena.hpl.hp.com/2003/07/query/BV" #BV="BV" store = joseki.query(modelURL, "RDQL", q=rdql, format=BV) store.prefix_mapping("rs", "http://jena.hpl.hp.com/2003/03/result-set#") ## print ## store.output(sys.stdout) ## print resultSet = ResultSet(store) for rb in resultSet.iter(): vBook = rb["book"] vTitle = rb["title"] print vBook," has title" print " '%s'" % vTitle