I can include URIs and variables in my queries, but I cannot include literals in my queries.
Here I have a code that successfully reads an RDF file, finds all RDF three times with skins: prefLabels, counts them, and then identifies a pair of keywords defined from a set of keywords:
import rdflib.plugins.sparql as sparql import rdflib import rdflib.graph as g graph = g.Graph()
As expected, this code prints:
2299 Jackknifing Technology-mapping
since Jackknifing and Technology-mapping are prefLabels in the file.
I really want to create and execute a Sparql query to find each keyword in turn. But this is where I peel off because I cannot put a string in the query. I tried this because Example:
o = rdflib.Literal(u'Jackknifing') qres = graph.query(q, initBindings = {'p' : p, 'o' : o})
but qres is empty. I also tried to directly indicate a literal query, for example.
q = sparql.prepareQuery('SELECT ?s ?p WHERE { ?s ?p "Technology-mapping" .}') qres = graph.query(q, initBindings = {'p' : p})
but also returns an empty result.
How are literals used in a query?
source share