# HG changeset patch # User drewp@bigasterisk.com # Date 1555493014 0 # Node ID ad6b5804deb11f01bb2b7fc771286513ae9ab715 # Parent 919c23ed90ec3c72d9554f714a5e359379c35fd4 serious bugs with inGraph. the code is not consistent (still) about whether context is a URIRef or Graph-with-identifier Ignore-this: 3a750a3f9c40b1ec3e2a8fb0c96830 diff -r 919c23ed90ec -r ad6b5804deb1 rdfdb/grapheditapi.py --- a/rdfdb/grapheditapi.py Fri Jan 04 23:17:30 2019 +0000 +++ b/rdfdb/grapheditapi.py Wed Apr 17 09:23:34 2019 +0000 @@ -19,14 +19,11 @@ """ existing = [] - for spo in self._graph.triples((subject, predicate, None), - context=context): - existing.append(spo+(context,)) - # what layer is supposed to cull out no-op changes? - return Patch( - delQuads=existing, - addQuads=([(subject, predicate, newObject, context)] - if newObject is not None else [])) + for spoc in quadsWithContextUris(self._graph.quads((subject, predicate, None, context))): + existing.append(spoc) + toAdd = ([(subject, predicate, newObject, context)] + if newObject is not None else []) + return Patch(delQuads=existing, addQuads=toAdd).simplify() def patchObject(self, context, subject, predicate, newObject): p = self.getObjectPatch(context, subject, predicate, newObject) diff -r 919c23ed90ec -r ad6b5804deb1 rdfdb/rdflibpatch.py --- a/rdfdb/rdflibpatch.py Fri Jan 04 23:17:30 2019 +0000 +++ b/rdfdb/rdflibpatch.py Wed Apr 17 09:23:34 2019 +0000 @@ -53,11 +53,19 @@ c is just a URIRef. Workaround for https://github.com/RDFLib/rdflib/issues/398 """ - spoi = spoc[:3] + (Graph(identifier=spoc[3]),) - if spoi not in graph: - # this is a huge speedup, avoid many whole-graph scans - return False - return spoi in graph.quads() + + c = spoc[3] + if isinstance(c, Graph): + c = c.identifier + + for spoc2 in graph.quads(spoc[:3]): + if spoc[:3] == spoc2[:3]: + c2 = spoc2[3] + if isinstance(c2, Graph): + c2 = c2.identifier + if c == c2: + return True + return False # some of the following workarounds may be fixed in https://github.com/RDFLib/rdflib/issues/299 def graphFromQuads(q): @@ -129,6 +137,22 @@ # with identifier, which I've fixed without a test +class TestInGraph(unittest.TestCase): + def testSimpleMatch(self): + g = graphFromQuads([(A,A,A,A)]) + self.assert_(inGraph((A,A,A,A), g)) + + def testDontMatchDifferentStatement(self): + g = graphFromQuads([(A,A,A,A)]) + self.assertFalse(inGraph((B,B,B,B), g)) + + def testDontMatchStatementInAnotherContext(self): + g = graphFromQuads([(A,A,A,A)]) + self.assertFalse(inGraph((A,A,A,B), g)) + + self.assertFalse(inGraph((A,A,A,Graph(identifier=B)), g)) + + class TestGraphFromQuads(unittest.TestCase): nqOut = ' .\n' def testSerializes(self):