changeset 1305:1f3e105a893c

predicate_objects support on SyncedGraph Ignore-this: 9c2f3642e0601a9712c5c0ede8e9cc16
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 30 May 2016 21:41:01 +0000
parents ace07d2e971f
children b2745bcab19d
files light9/rdfdb/autodepgraphapi.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/light9/rdfdb/autodepgraphapi.py	Mon May 30 20:59:42 2016 +0000
+++ b/light9/rdfdb/autodepgraphapi.py	Mon May 30 21:41:01 2016 +0000
@@ -102,6 +102,11 @@
         self._watchers.addPredObjWatcher(func, predicate, object)
         return self._graph.subjects(predicate, object)
 
+    def predicate_objects(self, subject):
+        func = self._getCurrentFunc()
+        self._watchers.addSubjectWatcher(func, subject)
+        return self._graph.predicate_objects(subject)
+        
     def items(self, listUri):
         """generator. Having a chain of watchers on the results is not
         well-tested yet"""
@@ -142,6 +147,7 @@
         self._handlersSp = {} # (s,p): set(handlers)
         self._handlersPo = {} # (p,o): set(handlers)
         self._handlersSpo = {} # (s,p,o): set(handlers)
+        self._handlersS = {} # s: set(handlers)
 
     def addSubjPredWatcher(self, func, s, p):
         if func is None:
@@ -159,6 +165,9 @@
     def addTripleWatcher(self, func, triple):
         self._handlersSpo.setdefault(triple, set()).add(func)
 
+    def addSubjectWatcher(self, func, s):
+        self._handlersS.setdefault(s, set()).add(func)
+        
     def whoCares(self, patch):
         """what handler functions would care about the changes in this patch?
 
@@ -187,6 +196,13 @@
                 ret.update(funcs)
                 funcs.clear()
                 
+        affectedSubjs = set([s for s, p, o, c in patch.addQuads]+
+                            [s for s, p, o, c in patch.delQuads])
+        for subj, funcs in self._handlersS.iteritems():
+            if subj in affectedSubjs:
+                ret.update(funcs)
+                funcs.clear()
+                
         return ret
 
     def dependencies(self):