Hello,

I am trying to intercept an incoming SPARQL-UPDATE query string and insert some 
additional statements. More precisely, I want to add some triples in the WHERE 
clause. 

E.g. if I have this update query coming from a user request:


DELETE {
  <urn:res:dummy> a <urn:type:A> , <urn:type:b> ;
     <urn:p:a> ?x .
} INSERT {
  <urn:res:dummy> <urn:p:a> "hello" .
} WHERE {
  ?s <urn:p:a> ?x .
}

I want it to become: 

DELETE {
  <urn:res:dummy> a <urn:type:A> , <urn:type:b> ;
     <urn:p:a> ?x .
} INSERT {
  <urn:res:dummy> <urn:p:a> "hello" .
} WHERE {
  <urn:res:dummy> ?p ?o .
  ?s <urn:p:a> ?x .
}

(I cannot control anything that is in the query so I can't just bind ?s.)


Parsing the above original query:

parseUpdate(qs)

Returns: 

Update_{'prologue': [([], {})], 'request': [Modify_{'insert': 
InsertClause_{'quads': Quads_{'triples': 
[([rdflib.term.URIRef('urn:res:dummy'), rdflib.term.URIRef('urn:p:a'), 
literal_{'string': rdflib.term.Literal('hello')}], {})]}}, 'delete': 
DeleteClause_{'quads': Quads_{'triples': 
[([rdflib.term.URIRef('urn:res:dummy'), 
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), 
rdflib.term.URIRef('urn:type:A'), rdflib.term.URIRef('urn:res:dummy'), 
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), 
rdflib.term.URIRef('urn:type:b'), rdflib.term.URIRef('urn:res:dummy'), 
rdflib.term.URIRef('urn:p:a'), rdflib.term.Variable('x')], {})]}}, 'where': 
GroupGraphPatternSub_{'part': [TriplesBlock_{'triples': 
[([rdflib.term.URIRef('urn:res:dummy'), PathAlternative_{'part': 
[PathSequence_{'part': [PathElt_{'part': rdflib.term.URIRef('urn:p:a')}]}]}, 
rdflib.term.Variable('x')], {})]}]}}]}


Precisely, where I want to add my additional triple is the very beginning of 
the "request[0].where" part. 

Is there a way to do this in a manner that works predictably with any possibly 
complex query? I.e. without using string-based hacks, but possibly the 
structure offered above, which alas, loks unfathomable to me. 

Thanks,
Stefano

-- 
http://github.com/RDFLib
--- 
You received this message because you are subscribed to the Google Groups 
"rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rdflib-dev/e0f93730-fb81-4289-a5aa-a5893bb35330%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to