@@ -26,6 +26,12 @@ def _append(dct, identifier, action, items):
2626 changes .append ((action , items ))
2727 dct [identifier ] = changes
2828
29+ def _filterExistingTriples (g , triples ):
30+ return list (filter (lambda triple : triple not in g , triples ))
31+
32+ def _filterNonExistingTriples (g , triples ):
33+ return list (filter (lambda triple : triple in g , triples ))
34+
2935def evalLoad (ctx , u ):
3036 """
3137 http://www.w3.org/TR/sparql11-update/#load
@@ -69,7 +75,7 @@ def evalLoad(ctx, u):
6975evalClear = rdflib .plugins .sparql .update .evalClear
7076evalDrop = rdflib .plugins .sparql .update .evalDrop
7177
72- def evalInsertData (ctx , u ) :
78+ def evalInsertData (ctx : QueryContext , u : CompValue ) -> dict :
7379 """
7480 http://www.w3.org/TR/sparql11-update/#insertData
7581 """
@@ -80,46 +86,53 @@ def evalInsertData(ctx, u):
8086
8187 # add triples
8288 g = ctx .graph
83- filled = list ( filter ( lambda triple : triple not in g , u .triples ) )
89+ filled = _filterNonExistingTriples ( g , u .triples )
8490 if filled :
8591 _append (res ["delta" ], 'default' , 'additions' , filled )
86- g + = filled
92+ u . triples = filled
8793
8894 # add quads
8995 # u.quads is a dict of graphURI=>[triples]
9096 for g in u .quads :
91- cg = ctx .dataset .get_context (g )
92- filledq = list (filter (lambda triple : triple not in cg , u .quads [g ]))
97+ # type error: Argument 1 to "get_context" of "ConjunctiveGraph" has incompatible type "Optional[Graph]"; expected "Union[IdentifiedNode, str, None]"
98+ cg = ctx .dataset .get_context (g ) # type: ignore[arg-type]
99+ filledq = _filterExistingTriples (cg , u .quads [g ])
93100 if filledq :
94101 _append (res ["delta" ], cg .identifier , 'additions' , filledq )
95- cg += filledq
102+ u .quads [g ] = filledq
103+
104+ rdflib .plugins .sparql .update .evalInsertData (ctx , u )
96105
97106 return res
98107
99108
100- def evalDeleteData (ctx , u ) :
109+ def evalDeleteData (ctx : QueryContext , u : CompValue ) -> dict :
101110 """
102111 http://www.w3.org/TR/sparql11-update/#deleteData
103112 """
113+
104114 res = {}
105115 res ["type" ] = "DELETE"
106116 res ["delta" ] = {}
107117
108118 # remove triples
109119 g = ctx .graph
110- filled = list ( filter ( lambda triple : triple in g , u .triples ) )
120+ filled = _filterNonExistingTriples ( g , u .triples )
111121 if filled :
112122 _append (res ["delta" ], 'default' , 'removals' , filled )
113- g - = filled
123+ u . triples = filled
114124
115125 # remove quads
116126 # u.quads is a dict of graphURI=>[triples]
117127 for g in u .quads :
128+ # type error: Argument 1 to "get_context" of "ConjunctiveGraph" has incompatible type "Optional[Graph]"; expected "Union[IdentifiedNode, str, None]"
118129 cg = ctx .dataset .get_context (g )
119- filledq = list ( filter ( lambda triple : triple in cg , u .quads [g ]) )
130+ filledq = _filterNonExistingTriples ( cg , u .quads [g ])
120131 if filledq :
121132 _append (res ["delta" ], cg .identifier , 'removals' , filledq )
122- cg -= filledq
133+ u .quads [g ] = filledq
134+
135+ rdflib .plugins .sparql .update .evalDeleteData (ctx , u )
123136
124137 return res
125138
@@ -240,7 +253,6 @@ def evalModify(ctx, u):
240253evalMove = rdflib .plugins .sparql .update .evalMove
241254evalCopy = rdflib .plugins .sparql .update .evalCopy
242255
243-
244256def evalUpdate (graph , update , initBindings = None , actionLog = False ):
245257 """
246258 http://www.w3.org/TR/sparql11-update/#updateLanguage
0 commit comments