annotate service/reasoning/rdflibtrig.py @ 1040:2fa7daf06f34

rdflib can parse trig now Ignore-this: ad1feb1d88249f509d2906b6cdbe62c6 darcs-hash:c141fa6a86e7d395c4c80facc9ed7fcadcf40b29
author drewp <drewp@bigasterisk.com>
date Mon, 01 Feb 2016 02:15:23 -0800
parents 3bb18b7d21df
children 0c306e76d8c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
1 import re, time
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
2 import restkit
1040
2fa7daf06f34 rdflib can parse trig now
drewp <drewp@bigasterisk.com>
parents: 934
diff changeset
3 from rdflib.parser import StringInputSource
2fa7daf06f34 rdflib can parse trig now
drewp <drewp@bigasterisk.com>
parents: 934
diff changeset
4 from rdflib import ConjunctiveGraph
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
5
934
3bb18b7d21df reasoning actions: generalize them a bit but then add a bunch of special cases for mpd for now
drewp <drewp@bigasterisk.com>
parents: 923
diff changeset
6 def addTrig(graph, url, timeout=2):
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
7 t1 = time.time()
934
3bb18b7d21df reasoning actions: generalize them a bit but then add a bunch of special cases for mpd for now
drewp <drewp@bigasterisk.com>
parents: 923
diff changeset
8 response = restkit.request(url, timeout=timeout)
923
4ae49c6adecb errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents: 919
diff changeset
9 if response.status_int != 200:
4ae49c6adecb errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents: 919
diff changeset
10 raise ValueError("status %s from %s" % (response.status, url))
4ae49c6adecb errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents: 919
diff changeset
11 trig = response.body_string()
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
12 fetchTime = time.time() - t1
1040
2fa7daf06f34 rdflib can parse trig now
drewp <drewp@bigasterisk.com>
parents: 934
diff changeset
13 g = ConjunctiveGraph()
2fa7daf06f34 rdflib can parse trig now
drewp <drewp@bigasterisk.com>
parents: 934
diff changeset
14 g.parse(StringInputSource(trig), format='trig')
2fa7daf06f34 rdflib can parse trig now
drewp <drewp@bigasterisk.com>
parents: 934
diff changeset
15 graph.addN(g.quads())
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
16 return fetchTime