Mercurial > code > home > repos > homeauto
diff service/reasoning/inference.py @ 114:4cd065b97fa1
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
Ignore-this: 81dc30256f5d2658e53fce60abea66db
author | drewp@bigasterisk.com |
---|---|
date | Tue, 10 Sep 2013 00:38:52 -0700 |
parents | 5b0f970e3d52 |
children | 0f2ac014d9ea |
line wrap: on
line diff
--- a/service/reasoning/inference.py Tue Sep 10 00:36:52 2013 -0700 +++ b/service/reasoning/inference.py Tue Sep 10 00:38:52 2013 -0700 @@ -4,8 +4,13 @@ import sys, re import restkit -from rdflib import StringInputSource, URIRef -from rdflib.Graph import Graph +from rdflib import URIRef +try: + from rdflib import StringInputSource + from rdflib.Graph import Graph +except ImportError: + from rdflib.parser import StringInputSource + from rdflib import Graph sys.path.append("/my/proj/room/fuxi/build/lib.linux-x86_64-2.6") from FuXi.Rete.Util import generateTokenSet @@ -13,20 +18,7 @@ from rdflib import plugin from rdflib.store import Store -def parseTrig(trig): - """ - yields quads - """ - m = re.match(r"<([^>]+)> \{(.*)\}\s*$", trig, re.DOTALL) - if m is None: - raise NotImplementedError("trig format was too tricky: %r..." % trig[:200]) - - ctx = URIRef(m.group(1)) - n3 = m.group(2) - g = Graph() - g.parse(StringInputSource(n3), format="n3") - for stmt in g: - yield stmt + (ctx,) +from rdflibtrig import parseTrig, addTrig def infer(graph, rules): """ @@ -56,10 +48,3 @@ func.__name__, 1000 * (time.time() - t1))) return ret return inner - -def addTrig(graph, url): - t1 = time.time() - trig = restkit.request(url).body_string() - fetchTime = time.time() - t1 - graph.addN(parseTrig(trig)) - return fetchTime