-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.html
194 lines (155 loc) · 8.75 KB
/
doc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTTP SPARQL server for rdflib</title>
<style type="text/css">
#cake {
border-collapse: collapse;
border: 1px solid gray;
}
#cake td {
border: 1px solid black;
padding: 8px 15px;
}
#cake td span {
font-size: 90%;
font-style: italic;
}
pre {
border: 1px solid #aaa;
background: #edc;
padding: 1em;
overflow: auto;
}
pre.output {
background: #eee;
}
</style>
</head>
<body>
<h1>HTTP SPARQL server and client for twisted and rdflib</h1>
<p>
This library is for programs that use twisted for networking, use
rdflib for RDF, and want to do sparql over http. It contains a client
and a server, but you should be able to mix and match with other
sparql clients and servers.
</p>
<table id="cake">
<tr><th>Classes</th></tr>
<tr bgcolor="#f19e9e"><td>RemoteGraph <span>twisted web client that talks to SPARQLResource (or other sparql-over-http servers)</span></td></tr>
<tr bgcolor="#cbcbcb"><td align="center">⇑ HTTP ⇓ </td></tr>
<tr bgcolor="#e4f19e"><td>SPARQLResource <span>twisted web resource that supports various GET/POST commands</span></td></tr>
<tr bgcolor="#9ef1e4"><td>Graph2 <span>slightly different API for the rdflib graph class</span></td></tr>
<tr bgcolor="#9ebbf1"><td>ConjunctiveGraph <span>(from rdflib)</span></td></tr>
</table>
<p>
There is also a LocalGraph class, which presents exactly the same API
as RemoteGraph, but it talks to an in-process rdflib graph. This is
convenient for testing your async RemoteGraph code without bothering
to setup the http connection.
</p>
<pre>
# this code will work whether graph is a RemoteGraph or a LocalGraph
def method(self):
d = graph.remoteLabel(subj)
d.addCallback(self.withLabel)
def withLabel(self, label):
print label
</pre>
<h2>Download</h2>
<p><a href="http://bigasterisk.com/darcs/?r=sparqlhttp">Darcs source code repository</a></p>
<div><a href="sparqlhttp-1.14.tar.gz">sparqlhttp-1.14.tar.gz</a> (2014-11-10) add some compatibility with older rdflib; switch syncimport from pyxml to dateutil</div>
<div><a href="sparqlhttp-1.13.tar.gz">sparqlhttp-1.13.tar.gz</a> (2012-01-12) make dictquery.Graph2 be more compatible with the newer graph2.SyncGraph</div>
<div><a href="sparqlhttp-1.12.tar.gz">sparqlhttp-1.12.tar.gz</a> (2011-11-16) speed up parsing; a few other edge cases <a href="changelog-1.12">(full changelog)</a></div>
<div><a href="sparqlhttp-1.11.tar.gz">sparqlhttp-1.11.tar.gz</a> (2010-11-12) turn off the setuptools_trial dep <a href="changelog-1.11">(full changelog)</a></div>
<div><a href="sparqlhttp-1.10.tar.gz">sparqlhttp-1.10.tar.gz</a> (2010-07-13) some new methods: subgraphClear, subgraphStatements</div>
<div><a href="sparqlhttp-1.9.tar.gz">sparqlhttp-1.9.tar.gz</a> (2010-06-02) test version of my new API version (SyncGraph/AsyncGraph); server side is incomplete <a href="changelog-1.9">(full changelog)</a></div>
<div><a href="sparqlhttp-1.5.tar.gz">sparqlhttp-1.5.tar.gz</a> (2010-04-29) packaging; add some new sync and sesame variations <a href="changelog-1.5">(full changelog)</a></div>
<div><a href="sparqlhttp-1.4.tar.gz">sparqlhttp-1.4.tar.gz</a> (2010-03-20) minor packaging fixes <a href="changelog-1.4">(full changelog)</a></div>
<div><a href="sparqlhttp-1.3.tar.gz">sparqlhttp-1.3.tar.gz</a> (2009-10-12) <a href="changelog-1.3">changelog</a></div>
<div><a href="sparqlhttp-1.2.tar.gz">sparqlhttp-1.2.tar.gz</a> (2008-02-06) <a href="changelog-1.2">changelog</a></div>
<div><a href="sparqlhttp-1.1.tar.gz">sparqlhttp-1.1.tar.gz</a> (2007-08-07) <a href="changelog-1.1">changelog</a></div>
<div><a href="sparqlhttp-1.0.tar.gz">sparqlhttp-1.0.tar.gz</a> (2007-03-01)</div>
<h2>Requirements</h2>
<ul>
<li><a href="http://effbot.org/zone/element-index.htm">elementtree</a></li>
<li><a href="http://rdflib.net/">rdflib 2.3.3 +</a></li>
<li><a href="http://divmod.org/trac/wiki/DivmodNevow">nevow</a> (<a href="http://twistedmatrix.com/trac/">twisted</a>, zope.interface)</li>
</ul>
<h2>Future plans</h2>
<ul>
<li>Remove the ad-hoc update protocol and share <a href="http://www.openrdf.org/doc/sesame2/system/ch08.html#d0e304">sesame's</a> (does anyone want <a href="http://www.w3.org/TR/sparql11-update/">sparql 1.1 update</a> yet?)</li>
<li>Complete the support for reading and writing all the sparql results formats (xml, json, sesame binary), and try to share this code with other projects like <a href="http://sparql-wrapper.sourceforge.net/">sparql-wrapper</a></li>
<li>Clean up the RemoteGraph factory code</li>
<li>Incorporate the sync version of Graph2 that I have, and organize all the local/remote sync/async versions of everything</li>
</ul>
<h2>Demo</h2>
<ol>
<li>Start a server, creating a new berkeleydb instance in <code>./db/</code>
<pre>./<a href="sparqlserve">sparqlserve</a> --home db</pre>
<pre class="output">
2007/01/22 00:58 -0700 [-] Log opened.
2007/01/22 00:58 -0700 [-] twisted.web.server.Site starting on 9991
2007/01/22 00:58 -0700 [-] Starting factory <twisted.web.server.Site instance at 0xb7646aac>
</pre>
</li>
<li>In another shell, parse some NT and POST it to the server. The
post will be to "/add?context=http://example.org#context" with data
consisting of NT statements. That part of my protocol is not part of
any standard.
<pre>./<a href="graphimport">graphimport</a> hello.nt</pre>
Server says:
<pre class="output">
2007/01/22 01:14 -0700 [HTTPChannel,0,127.0.0.1] 127.0.0.1 - - [22/Jan/2007:08:14:08 +0000] "POST /add?context=http%3A//example.org/%23context HTTP/1.0" 200 2 "-" "Twisted PageGetter"</pre>
</li>
<li>GET the query "SELECT ?s ?p ?o WHERE { ?s ?p ?o }" from the
server. This uses the standard SPARQL query and results formats.
<pre>./<a href="dumpgraph">dumpgraph</a></pre>
Server says:
<pre class="output">
2007/01/22 01:15 -0700 [HTTPChannel,1,127.0.0.1] 127.0.0.1 - - [22/Jan/2007:08:15:32 +0000] "GET /?query=SELECT%20%3Fs%20%3Fp%20%3Fo%20WHERE%20%7B%20%3Fs%20%3Fp%20%3Fo%20%7D HTTP/1.0" 200 617 "-" "Twisted PageGetter"</pre>
Client says:
<pre class="output">
[(u'http://example.org/hello',
u'http://example.org/to',
rdflib.Literal('world',language=None,datatype=None)),
(u'http://example.org/hello',
u'http://www.w3.org/2000/01/rdf-schema#label',
rdflib.Literal('Hello',language=None,datatype=None))]
</pre>
</li>
<li>Do an arbitrary query on the server.
<pre>./<a href="query">query</a> "SELECT ?label WHERE { ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label }"</pre>
<pre class="output">
[{'label': rdflib.Literal('Hello',language=None,datatype=None)}]
</pre>
</li>
<li>Check out the server diagnostics at http://localhost:9991/
<p>I deliberately made an error request to cause the the traceback
below. The table at the bottom is really nice for large programs,
since it shows what lines in your code made the various queries.</p>
<div style="border: 3px solid black">
<h1>sparqlhttp server status</h1><ul><li>2<span> queries</span></li><li><span>Last error:</span><div><span>query: </span><pre style="background: white">SELECT ?broken { ?typo here }</pre></div><div><span>error: </span><pre style="background: white">Traceback (most recent call last):
File "sparqlhttp-1.0/sparqlhttp/serve.py", line 48, in getQuery
results = self.graph.queryd(query)
File "sparqlhttp-1.0/sparqlhttp/dictquery.py", line 80, in queryd
initNs=self.initNs)
File "/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/Graph.py", line 644, in query
return plugin.get('SPARQLQueryResult',QueryResult)(p.query(strOrQuery, initBindings, initNs, DEBUG))
File "/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/sparql/bison/Processor.py", line 26, in query
strOrQuery = Parse(strOrQuery, DEBUG)
File "/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/sparql/bison/Processor.py", line 16, in Parse
return p.parse(unicode(query,'utf-8'))
SyntaxError: lexical error at line 1, column 30: no action found for 'here }'
</pre></div></li><li><span>Last query:</span><pre style="background: white">SELECT ?broken { ?typo here }</pre><span>Again, as one line:</span><div>SELECT ?broken { ?typo here }</div></li><li><span>All query types, by total time spent</span><table style="border: 1px solid black;border-collapse: collapse;"><tr><th>total secs (per)</th><th>count</th><th>query (with sample initBindings)</th><th>bound</th><th>avg rows</th><th>sources</th></tr><tr><td>0.01 (0.0110)</td><td>1</td><td><pre style="background: white">SELECT ?s ?p ?o WHERE { ?s ?p ?o }</pre></td><td>()</td><td>2.0</td><td><div>dumpgraph:9</div></td></tr></table></li></ul></div>
</li>
<li>Try running the tests. They use twisted trial and they run from
the test directory:
<pre>
cd test
trial test_dictquery.py test_remotegraph.py # all these should work
trial test_syncimport.py # this one might not do as well
</pre>
</li>
</ol>
</body>
</html>