# HG changeset patch # User Drew Perttula # Date 2016-05-30 21:41:01 # Node ID 1f3e105a893c0c69055210891c45adcb2a8aa515 # Parent ace07d2e971fd9bad96e11438ca4b6b47960d2d3 predicate_objects support on SyncedGraph Ignore-this: 9c2f3642e0601a9712c5c0ede8e9cc16 diff --git a/light9/rdfdb/autodepgraphapi.py b/light9/rdfdb/autodepgraphapi.py --- a/light9/rdfdb/autodepgraphapi.py +++ b/light9/rdfdb/autodepgraphapi.py @@ -102,6 +102,11 @@ class AutoDepGraphApi(object): 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 @@ class _GraphWatchers(object): 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 @@ class _GraphWatchers(object): 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 @@ class _GraphWatchers(object): 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):