annotate service/reasoning/rdflibtrig.py @ 240:0c306e76d8c5

ipv6 fetch support. refactor Actions to new class and file Ignore-this: 200d7093919cf001706ad9c02347fabb
author drewp@bigasterisk.com
date Mon, 01 Feb 2016 03:28:17 -0800
parents 5ad229334a88
children e5c27d2f11ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
240
0c306e76d8c5 ipv6 fetch support. refactor Actions to new class and file
drewp@bigasterisk.com
parents: 235
diff changeset
1 import time
0c306e76d8c5 ipv6 fetch support. refactor Actions to new class and file
drewp@bigasterisk.com
parents: 235
diff changeset
2 import requests
235
5ad229334a88 rdflib can parse trig now
drewp@bigasterisk.com
parents: 129
diff changeset
3 from rdflib import ConjunctiveGraph
114
4cd065b97fa1 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp@bigasterisk.com
parents:
diff changeset
4
129
745eff67ad40 reasoning actions: generalize them a bit but then add a bunch of special cases for mpd for now
drewp@bigasterisk.com
parents: 118
diff changeset
5 def addTrig(graph, url, timeout=2):
114
4cd065b97fa1 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp@bigasterisk.com
parents:
diff changeset
6 t1 = time.time()
240
0c306e76d8c5 ipv6 fetch support. refactor Actions to new class and file
drewp@bigasterisk.com
parents: 235
diff changeset
7 response = requests.get(url, stream=True, timeout=timeout)
0c306e76d8c5 ipv6 fetch support. refactor Actions to new class and file
drewp@bigasterisk.com
parents: 235
diff changeset
8 if response.status_code != 200:
118
7179284779fd errors and logging in reasoning
drewp@bigasterisk.com
parents: 114
diff changeset
9 raise ValueError("status %s from %s" % (response.status, url))
240
0c306e76d8c5 ipv6 fetch support. refactor Actions to new class and file
drewp@bigasterisk.com
parents: 235
diff changeset
10 g = ConjunctiveGraph()
0c306e76d8c5 ipv6 fetch support. refactor Actions to new class and file
drewp@bigasterisk.com
parents: 235
diff changeset
11 g.parse(response.raw, format='trig')
114
4cd065b97fa1 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp@bigasterisk.com
parents:
diff changeset
12 fetchTime = time.time() - t1
235
5ad229334a88 rdflib can parse trig now
drewp@bigasterisk.com
parents: 129
diff changeset
13 graph.addN(g.quads())
114
4cd065b97fa1 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp@bigasterisk.com
parents:
diff changeset
14 return fetchTime