How can I insert variable into SPARQL query?

Question:

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> .

Asked By: irina_ikonn

||

Answers:

use


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

Answered By: Elvin Jafarov
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.