Mercurial > code > home > repos > light9
changeset 1055:6ce00faec207
move sequentialUri to the graph lib
Ignore-this: 3dc3fb4833a23a46b8cfea90788f25be
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 01 Jun 2014 10:39:17 +0000 |
parents | 4595a82f5a90 |
children | 547d65ea9902 |
files | bin/effecteval light9/rdfdb/currentstategraphapi.py |
diffstat | 2 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/effecteval Sun Jun 01 10:22:14 2014 +0000 +++ b/bin/effecteval Sun Jun 01 10:39:17 2014 +0000 @@ -31,21 +31,21 @@ 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),
--- a/light9/rdfdb/currentstategraphapi.py Sun Jun 01 10:22:14 2014 +0000 +++ b/light9/rdfdb/currentstategraphapi.py Sun Jun 01 10:39:17 2014 +0000 @@ -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 @@ 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")