diff --git a/bin/effecteval b/bin/effecteval --- a/bin/effecteval +++ b/bin/effecteval @@ -31,21 +31,21 @@ class EffectEdit(PrettyErrorHandler, cyc self.settings.graph.patch(Patch(delQuads=[ (song, L9['effect'], uri, ctx), ])) - + class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler): def post(self): song = URIRef(self.get_argument('uri')) drop = URIRef(self.get_argument('drop')) ctx = song - now = time.time() - effect = song + "/effect/e-%f" % now - curve = song + "/curve/c-%f" % now + graph = self.settings.graph + effect = graph.sequentialUri(song + "/effect/e-") + curve = graph.sequentialUri(song + "/curve/c-") - with self.settings.graph.currentState( + with graph.currentState( tripleFilter=(drop, RDFS.label, None)) as g: dropSubLabel = g.label(drop) - self.settings.graph.patch(Patch(addQuads=[ + graph.patch(Patch(addQuads=[ (song, L9['curve'], curve, ctx), (song, L9['effect'], effect, ctx), (effect, RDF.type, L9['Effect'], ctx), diff --git a/light9/rdfdb/currentstategraphapi.py b/light9/rdfdb/currentstategraphapi.py --- a/light9/rdfdb/currentstategraphapi.py +++ b/light9/rdfdb/currentstategraphapi.py @@ -1,4 +1,4 @@ -import logging, traceback, time +import logging, traceback, time, itertools from rdflib import ConjunctiveGraph from light9.rdfdb.rdflibpatch import contextsForStatement as rp_contextsForStatement log = logging.getLogger("currentstate") @@ -48,6 +48,18 @@ class CurrentStateGraphApi(object): return Mgr() + def sequentialUri(self, prefix): + """ + Prefix URIRef like http://example.com/r- will return + http://example.com/r-1 if that uri is not a subject in the graph, + or else http://example.com/r-2, etc + """ + for i in itertools.count(1): + newUri = prefix + str(i) + if not list(self._grap.triples((newUri, None, None))): + return newUri + + def contextsForStatementNoWildcards(g, triple): if None in triple: raise NotImplementedError("no wildcards")