pythonsparqlrdflib

How can I insert variable into SPARQL query?


I use the rdflib library. I need to insert a variable into a SPARQL query. I do this:

    q = prepareUpdate("""INSERT DATA { <r> a <owl:Ontology> }""")
    g.update(q, initBindings={'r': uri})
    uri = 'http://www.example.org/ontologies/example/example.owl'
    g - object class Graph()

Output result: <r:> a <owl:Ontology> .

Required result: <http://www.example.org/ontologies/example/example.owl> a <owl:Ontology> .


Solution

  • use

    
    q = prepareUpdate("""INSERT DATA { <%s> a <owl:Ontology> }""" % uri)
    g.update(q)