rshar
rshar

Reputation: 1477

Insert triples in a graph using SPARQLWrapper

I am trying to insert triples in a graph using below SPARQL query:

for s, p, o in g:
    id = s
    rel = p
    med = o
    
    queryString = """ 
                    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
                    
                    INSERT DATA {
                    GRAPH <http://example.org/mapping> 
                    { %s skos:%s %s }} 
                    
                  """ %(id, rel, med)
    
    sparql = SPARQLWrapper("http://blazegraph/namespace/HC2/sparql/update")
    sparql.setQuery(queryString)
    sparql.method = 'POST'
    sparql.query()

However, when I try to run this, I get below error:

QueryBadFormed: QueryBadFormed: A bad request has been sent to the endpoint: probably the SPARQL query is badly formed. 

I am not able to figure out what is the error in the above code.

Upvotes: 0

Views: 147

Answers (0)

Related Questions