1616from itertools import tee
1717from quit .exceptions import UnSupportedQuery
1818
19+ import rdflib .plugins .sparql .update
20+
1921def _append (dct , identifier , action , items ):
2022 if items :
2123 if not isinstance (identifier , Node ):
@@ -24,29 +26,6 @@ def _append(dct, identifier, action, items):
2426 changes .append ((action , items ))
2527 dct [identifier ] = changes
2628
27-
28- def _graphOrDefault (ctx , g ):
29- if g == 'DEFAULT' :
30- return ctx .graph
31- else :
32- return ctx .dataset .get_context (g )
33-
34-
35- def _graphAll (ctx , g ):
36- """
37- return a list of graphs
38- """
39- if g == 'DEFAULT' :
40- return [ctx .graph ]
41- elif g == 'NAMED' :
42- return [c for c in ctx .dataset .contexts ()
43- if c .identifier != ctx .graph .identifier ]
44- elif g == 'ALL' :
45- return list (ctx .dataset .contexts ())
46- else :
47- return [ctx .dataset .get_context (g )]
48-
49-
5029def evalLoad (ctx , u ):
5130 """
5231 http://www.w3.org/TR/sparql11-update/#load
@@ -86,35 +65,9 @@ def evalLoad(ctx, u):
8665
8766 return res
8867
89-
90- def evalCreate (ctx , u ):
91- """
92- http://www.w3.org/TR/sparql11-update/#create
93- """
94- g = ctx .datset .get_context (u .graphiri )
95- if len (g ) > 0 :
96- raise Exception ("Graph %s already exists." % g .identifier )
97- raise Exception ("Create not implemented!" )
98-
99-
100- def evalClear (ctx , u ):
101- """
102- http://www.w3.org/TR/sparql11-update/#clear
103- """
104- for g in _graphAll (ctx , u .graphiri ):
105- g .remove ((None , None , None ))
106-
107-
108- def evalDrop (ctx , u ):
109- """
110- http://www.w3.org/TR/sparql11-update/#drop
111- """
112- if ctx .dataset .store .graph_aware :
113- for g in _graphAll (ctx , u .graphiri ):
114- ctx .dataset .store .remove_graph (g )
115- else :
116- evalClear (ctx , u )
117-
68+ evalCreate = rdflib .plugins .sparql .update .evalCreate
69+ evalClear = rdflib .plugins .sparql .update .evalClear
70+ evalDrop = rdflib .plugins .sparql .update .evalDrop
11871
11972def evalInsertData (ctx , u ):
12073 """
@@ -283,71 +236,9 @@ def evalModify(ctx, u):
283236
284237 return res
285238
286-
287- def evalAdd (ctx , u ):
288- """
289-
290- add all triples from src to dst
291-
292- http://www.w3.org/TR/sparql11-update/#add
293- """
294- src , dst = u .graph
295-
296- srcg = _graphOrDefault (ctx , src )
297- dstg = _graphOrDefault (ctx , dst )
298-
299- if srcg .identifier == dstg .identifier :
300- return
301-
302- dstg += srcg
303-
304-
305- def evalMove (ctx , u ):
306- """
307- remove all triples from dst
308- add all triples from src to dst
309- remove all triples from src
310-
311- http://www.w3.org/TR/sparql11-update/#move
312- """
313-
314- src , dst = u .graph
315-
316- srcg = _graphOrDefault (ctx , src )
317- dstg = _graphOrDefault (ctx , dst )
318-
319- if srcg .identifier == dstg .identifier :
320- return
321-
322- dstg .remove ((None , None , None ))
323-
324- dstg += srcg
325-
326- if ctx .dataset .store .graph_aware :
327- ctx .dataset .store .remove_graph (srcg )
328- else :
329- srcg .remove ((None , None , None ))
330-
331-
332- def evalCopy (ctx , u ):
333- """
334- remove all triples from dst
335- add all triples from src to dst
336-
337- http://www.w3.org/TR/sparql11-update/#copy
338- """
339-
340- src , dst = u .graph
341-
342- srcg = _graphOrDefault (ctx , src )
343- dstg = _graphOrDefault (ctx , dst )
344-
345- if srcg .identifier == dstg .identifier :
346- return
347-
348- dstg .remove ((None , None , None ))
349-
350- dstg += srcg
239+ evalAdd = rdflib .plugins .sparql .update .evalAdd
240+ evalMove = rdflib .plugins .sparql .update .evalMove
241+ evalCopy = rdflib .plugins .sparql .update .evalCopy
351242
352243
353244def evalUpdate (graph , update , initBindings = None , actionLog = False ):
0 commit comments