title: Using Python rdflib: how to include literals in sparql queries?
body: <p>I can  include URIs and variables in  my queries, but I can't
  include literals in my queries.</p>
  
  <p>Here, I have some code which successfully reads an RDF file, finds
  all the RDF triples with skos:prefLabels, counts them, and then
  identifies a couple of specific ones from a set of keywords:</p>
  
  <pre><code>import rdflib.plugins.sparql as sparql
  import rdflib
  import rdflib.graph as g
  
  graph = g.Graph()
  # Read the RDF file
  graph.parse(
     'h:\......SKOSTaxonomy.rdf',
     format='xml')
  
  # Build and execute the query
  q = sparql.prepareQuery('SELECT ?s ?p ?o WHERE { ?s ?p ?o .}')
  p = rdflib.URIRef("http://www.w3.org/2004/02/skos/core#prefLabel")
  qres = graph.query(q, initBindings = {'p' : p})
  
  print len(qres)
  
  # Look for keywords among the results
  keywords = set([u'Jackknifing', 'Technology-mapping', 'Something random'])
  
  for (subj, pred, obj) in qres:
      if obj.value in keywords:
          print obj.value
  </code></pre>
  
  <p>As expected, this code prints:</p>
  
  <pre><code>2299
  Jackknifing
  Technology-mapping
  </code></pre>
  
  <p>since Jackknifing and Technology-mapping are prefLabels in the file.</p>
  
  <p>What I really want to do is to construct and execute a Sparql query to
  look for each keyword in turn. But this is where I come unstuck,
  because I can't put a string into the query. I have tried this, for
  example:</p>
  
  <pre><code>o = rdflib.Literal(u'Jackknifing')
  qres = graph.query(q, initBindings = {'p' : p, 'o' : o})
  </code></pre>
  
  <p>but qres is empty. I have also tried putting a literal explicitly into
  the query, e.g.</p>
  
  <pre><code>q = sparql.prepareQuery('SELECT ?s ?p WHERE { ?s ?p "Technology-mapping" .}')
  qres = graph.query(q, initBindings = {'p' : p})
  </code></pre>
  
  <p>but that returns an empty result too.</p>
  
  <p>How are literals included in a query?</p>