pho 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +17 -0
- data/Rakefile +10 -2
- data/bin/talis_store +37 -92
- data/doc/rdoc/classes/Pho.html +11 -0
- data/doc/rdoc/classes/Pho/CommandLine.html +508 -0
- data/doc/rdoc/classes/Pho/DatatypeProperty.html +15 -15
- data/doc/rdoc/classes/Pho/Enrichment.html +1 -1
- data/doc/rdoc/classes/Pho/Enrichment/{ResourceEnricher.html → StoreEnricher.html} +158 -58
- data/doc/rdoc/classes/Pho/Etags.html +36 -36
- data/doc/rdoc/classes/Pho/Facet/Results.html +19 -19
- data/doc/rdoc/classes/Pho/Facet/Term.html +6 -6
- data/doc/rdoc/classes/Pho/FieldPredicateMap.html +94 -94
- data/doc/rdoc/classes/Pho/FieldWeighting.html +14 -14
- data/doc/rdoc/classes/Pho/FileManagement/AbstractFileManager.html +126 -91
- data/doc/rdoc/classes/Pho/FileManagement/FileManager.html +68 -62
- data/doc/rdoc/classes/Pho/FileManagement/RDFManager.html +22 -57
- data/doc/rdoc/classes/Pho/Job.html +68 -67
- data/doc/rdoc/classes/Pho/Jobs.html +62 -62
- data/doc/rdoc/classes/Pho/QueryProfile.html +64 -64
- data/doc/rdoc/classes/Pho/RDF.html +120 -0
- data/doc/rdoc/classes/Pho/RDF/Parser.html +277 -0
- data/doc/rdoc/classes/Pho/ResourceHash.html +1 -1
- data/doc/rdoc/classes/Pho/ResourceHash/Converter.html +48 -46
- data/doc/rdoc/classes/Pho/ResourceHash/SetAlgebra.html +15 -14
- data/doc/rdoc/classes/Pho/Snapshot.html +36 -36
- data/doc/rdoc/classes/Pho/Sparql.html +50 -0
- data/doc/rdoc/classes/Pho/Sparql/SparqlClient.html +147 -68
- data/doc/rdoc/classes/Pho/Sparql/SparqlHelper.html +195 -114
- data/doc/rdoc/classes/Pho/Status.html +26 -26
- data/doc/rdoc/classes/Pho/Store.html +271 -264
- data/doc/rdoc/classes/Pho/StoreSparqlClient.html +183 -0
- data/doc/rdoc/classes/Pho/Update.html +1 -0
- data/doc/rdoc/classes/Pho/Update/Changeset.html +69 -68
- data/doc/rdoc/classes/Pho/Update/ChangesetBuilder.html +24 -24
- data/doc/rdoc/classes/Pho/Update/Changesets.html +15 -14
- data/doc/rdoc/classes/Pho/Update/LiteralStatement.html +18 -18
- data/doc/rdoc/classes/Pho/Update/ResourceStatement.html +24 -24
- data/doc/rdoc/classes/Pho/Update/Statement.html +28 -27
- data/doc/rdoc/classes/String.html +1 -1
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +53 -1
- data/doc/rdoc/files/lib/pho/changeset_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/command_line_rb.html +101 -0
- data/doc/rdoc/files/lib/pho/converter_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/enrichment_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/file_management_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/file_manager_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/rdf_collection_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/rdf_rb.html +108 -0
- data/doc/rdoc/files/lib/pho/sparql_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/store_rb.html +8 -1
- data/doc/rdoc/files/lib/pho_rb.html +4 -2
- data/doc/rdoc/fr_class_index.html +6 -1
- data/doc/rdoc/fr_file_index.html +2 -0
- data/doc/rdoc/fr_method_index.html +192 -172
- data/examples/calais/bio.txt +7 -0
- data/examples/calais/dump.rb +17 -0
- data/examples/calais/enlighten.rb +23 -0
- data/examples/calais/output.rdf +25 -0
- data/examples/sinatra/viewer.rb +20 -0
- data/lib/pho.rb +4 -1
- data/lib/pho/changeset.rb +17 -1
- data/lib/pho/command_line.rb +166 -0
- data/lib/pho/converter.rb +8 -3
- data/lib/pho/enrichment.rb +93 -28
- data/lib/pho/file_management.rb +32 -19
- data/lib/pho/file_manager.rb +22 -26
- data/lib/pho/rdf.rb +74 -0
- data/lib/pho/rdf_collection.rb +2 -17
- data/lib/pho/sparql.rb +150 -38
- data/lib/pho/store.rb +28 -2
- data/tests/tc_contentbox.rb +41 -0
- data/tests/tc_enrichment.rb +41 -4
- data/tests/tc_file_manager.rb +97 -7
- data/tests/tc_rdf_collection.rb +25 -13
- data/tests/tc_rdf_parser.rb +37 -0
- data/tests/tc_sparql.rb +72 -2
- data/tests/tc_sparql_helper.rb +16 -0
- data/tests/ts_pho.rb +2 -1
- metadata +20 -3
@@ -93,16 +93,17 @@ manipulating the results
|
|
93
93
|
<h3 class="section-bar">Methods</h3>
|
94
94
|
|
95
95
|
<div class="name-list">
|
96
|
-
<a href="#
|
97
|
-
<a href="#
|
98
|
-
<a href="#
|
99
|
-
<a href="#
|
100
|
-
<a href="#
|
101
|
-
<a href="#
|
102
|
-
<a href="#M000013">
|
103
|
-
<a href="#M000014">
|
104
|
-
<a href="#
|
105
|
-
<a href="#
|
96
|
+
<a href="#M000012">apply_initial_bindings</a>
|
97
|
+
<a href="#M000016">ask</a>
|
98
|
+
<a href="#M000019">construct_to_resource_hash</a>
|
99
|
+
<a href="#M000020">describe_to_resource_hash</a>
|
100
|
+
<a href="#M000022">describe_uri</a>
|
101
|
+
<a href="#M000021">multi_describe</a>
|
102
|
+
<a href="#M000013">result_to_query_binding</a>
|
103
|
+
<a href="#M000014">results_to_query_bindings</a>
|
104
|
+
<a href="#M000015">select</a>
|
105
|
+
<a href="#M000018">select_single_value</a>
|
106
|
+
<a href="#M000017">select_values</a>
|
106
107
|
</div>
|
107
108
|
</div>
|
108
109
|
|
@@ -137,11 +138,11 @@ manipulating the results
|
|
137
138
|
<div id="methods">
|
138
139
|
<h3 class="section-bar">Public Class methods</h3>
|
139
140
|
|
140
|
-
<div id="method-
|
141
|
-
<a name="
|
141
|
+
<div id="method-M000012" class="method-detail">
|
142
|
+
<a name="M000012"></a>
|
142
143
|
|
143
144
|
<div class="method-heading">
|
144
|
-
<a href="#
|
145
|
+
<a href="#M000012" class="method-signature">
|
145
146
|
<span class="method-name">apply_initial_bindings</span><span class="method-args">(query, bindings={})</span>
|
146
147
|
</a>
|
147
148
|
</div>
|
@@ -159,15 +160,19 @@ literals according to Turtle syntax.
|
|
159
160
|
Any keys in the hash that are not in the query are ignored. Any variables
|
160
161
|
not found in the hash remain unbound.
|
161
162
|
</p>
|
162
|
-
<
|
163
|
-
|
164
|
-
|
165
|
-
</
|
163
|
+
<table>
|
164
|
+
<tr><td valign="top">query:</td><td>the query whose initial bindings are to be set
|
165
|
+
|
166
|
+
</td></tr>
|
167
|
+
<tr><td valign="top">values:</td><td>hash of query name to value
|
168
|
+
|
169
|
+
</td></tr>
|
170
|
+
</table>
|
166
171
|
<p><a class="source-toggle" href="#"
|
167
|
-
onclick="toggleCode('
|
168
|
-
<div class="method-source-code" id="
|
172
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
173
|
+
<div class="method-source-code" id="M000012-source">
|
169
174
|
<pre>
|
170
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
175
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 260</span>
|
171
176
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">apply_initial_bindings</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">bindings</span>={})
|
172
177
|
<span class="ruby-identifier">copy</span> = <span class="ruby-identifier">query</span>.<span class="ruby-identifier">clone</span>()
|
173
178
|
<span class="ruby-identifier">copy</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-constant">VARIABLE_MATCHER</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span>
|
@@ -185,11 +190,11 @@ not found in the hash remain unbound.
|
|
185
190
|
</div>
|
186
191
|
</div>
|
187
192
|
|
188
|
-
<div id="method-
|
189
|
-
<a name="
|
193
|
+
<div id="method-M000016" class="method-detail">
|
194
|
+
<a name="M000016"></a>
|
190
195
|
|
191
196
|
<div class="method-heading">
|
192
|
-
<a href="#
|
197
|
+
<a href="#M000016" class="method-signature">
|
193
198
|
<span class="method-name">ask</span><span class="method-args">(query, sparql_client)</span>
|
194
199
|
</a>
|
195
200
|
</div>
|
@@ -203,15 +208,19 @@ response
|
|
203
208
|
Will request the results using the SPARQL JSON results format, parse the
|
204
209
|
resulting JSON results, and extract the true/false response.
|
205
210
|
</p>
|
206
|
-
<
|
207
|
-
query
|
208
|
-
|
209
|
-
</
|
211
|
+
<table>
|
212
|
+
<tr><td valign="top">query:</td><td>the SPARQL SELECT query
|
213
|
+
|
214
|
+
</td></tr>
|
215
|
+
<tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
|
216
|
+
|
217
|
+
</td></tr>
|
218
|
+
</table>
|
210
219
|
<p><a class="source-toggle" href="#"
|
211
|
-
onclick="toggleCode('
|
212
|
-
<div class="method-source-code" id="
|
220
|
+
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
221
|
+
<div class="method-source-code" id="M000016-source">
|
213
222
|
<pre>
|
214
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
223
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 343</span>
|
215
224
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">ask</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
216
225
|
<span class="ruby-identifier">json</span> = <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
217
226
|
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">json</span>[<span class="ruby-value str">"boolean"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"true"</span>
|
@@ -221,11 +230,11 @@ resulting JSON results, and extract the true/false response.
|
|
221
230
|
</div>
|
222
231
|
</div>
|
223
232
|
|
224
|
-
<div id="method-
|
225
|
-
<a name="
|
233
|
+
<div id="method-M000019" class="method-detail">
|
234
|
+
<a name="M000019"></a>
|
226
235
|
|
227
236
|
<div class="method-heading">
|
228
|
-
<a href="#
|
237
|
+
<a href="#M000019" class="method-signature">
|
229
238
|
<span class="method-name">construct_to_resource_hash</span><span class="method-args">(query, sparql_client)</span>
|
230
239
|
</a>
|
231
240
|
</div>
|
@@ -239,15 +248,19 @@ results in JSON
|
|
239
248
|
Will request the results as application/json (with the expectation that it
|
240
249
|
returns RDF_JSON), and parses the resulting JSON document.
|
241
250
|
</p>
|
242
|
-
<
|
243
|
-
query
|
244
|
-
|
245
|
-
</
|
251
|
+
<table>
|
252
|
+
<tr><td valign="top">query:</td><td>the SPARQL SELECT query
|
253
|
+
|
254
|
+
</td></tr>
|
255
|
+
<tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
|
256
|
+
|
257
|
+
</td></tr>
|
258
|
+
</table>
|
246
259
|
<p><a class="source-toggle" href="#"
|
247
|
-
onclick="toggleCode('
|
248
|
-
<div class="method-source-code" id="
|
260
|
+
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
261
|
+
<div class="method-source-code" id="M000019-source">
|
249
262
|
<pre>
|
250
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
263
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 391</span>
|
251
264
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">construct_to_resource_hash</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
252
265
|
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
253
266
|
<span class="ruby-identifier">resp</span> = <span class="ruby-identifier">sparql_client</span>.<span class="ruby-identifier">construct</span>(<span class="ruby-identifier">query</span>, <span class="ruby-value str">"application/json"</span>)
|
@@ -261,11 +274,11 @@ returns RDF_JSON), and parses the resulting JSON document.
|
|
261
274
|
</div>
|
262
275
|
</div>
|
263
276
|
|
264
|
-
<div id="method-
|
265
|
-
<a name="
|
277
|
+
<div id="method-M000020" class="method-detail">
|
278
|
+
<a name="M000020"></a>
|
266
279
|
|
267
280
|
<div class="method-heading">
|
268
|
-
<a href="#
|
281
|
+
<a href="#M000020" class="method-signature">
|
269
282
|
<span class="method-name">describe_to_resource_hash</span><span class="method-args">(query, sparql_client)</span>
|
270
283
|
</a>
|
271
284
|
</div>
|
@@ -279,15 +292,19 @@ in JSON
|
|
279
292
|
Will request the results as application/json (with the expectation that it
|
280
293
|
returns RDF_JSON), and parses the resulting JSON document.
|
281
294
|
</p>
|
282
|
-
<
|
283
|
-
query
|
284
|
-
|
285
|
-
</
|
295
|
+
<table>
|
296
|
+
<tr><td valign="top">query:</td><td>the SPARQL SELECT query
|
297
|
+
|
298
|
+
</td></tr>
|
299
|
+
<tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
|
300
|
+
|
301
|
+
</td></tr>
|
302
|
+
</table>
|
286
303
|
<p><a class="source-toggle" href="#"
|
287
|
-
onclick="toggleCode('
|
288
|
-
<div class="method-source-code" id="
|
304
|
+
onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
|
305
|
+
<div class="method-source-code" id="M000020-source">
|
289
306
|
<pre>
|
290
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
307
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 407</span>
|
291
308
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">describe_to_resource_hash</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
292
309
|
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
293
310
|
<span class="ruby-identifier">resp</span> = <span class="ruby-identifier">sparql_client</span>.<span class="ruby-identifier">describe</span>(<span class="ruby-identifier">query</span>, <span class="ruby-value str">"application/json"</span>)
|
@@ -301,28 +318,75 @@ returns RDF_JSON), and parses the resulting JSON document.
|
|
301
318
|
</div>
|
302
319
|
</div>
|
303
320
|
|
304
|
-
<div id="method-
|
305
|
-
<a name="
|
321
|
+
<div id="method-M000022" class="method-detail">
|
322
|
+
<a name="M000022"></a>
|
306
323
|
|
307
324
|
<div class="method-heading">
|
308
|
-
<a href="#
|
309
|
-
<span class="method-name">
|
325
|
+
<a href="#M000022" class="method-signature">
|
326
|
+
<span class="method-name">describe_uri</span><span class="method-args">(uri, sparql_client, type=:cbd)</span>
|
310
327
|
</a>
|
311
328
|
</div>
|
312
329
|
|
313
330
|
<div class="method-description">
|
314
331
|
<p>
|
315
|
-
|
332
|
+
Describe a single URI using one of several forms of Bounded Description See
|
333
|
+
<a href="SparqlClient.html#M000006">SparqlClient.describe_uri</a>
|
316
334
|
</p>
|
335
|
+
<table>
|
336
|
+
<tr><td valign="top">uri:</td><td>resource to describe
|
337
|
+
|
338
|
+
</td></tr>
|
339
|
+
<tr><td valign="top">sparql_client:</td><td>configured SPARQL client
|
340
|
+
|
341
|
+
</td></tr>
|
342
|
+
<tr><td valign="top">type:</td><td>form of bounded description to generate
|
343
|
+
|
344
|
+
</td></tr>
|
345
|
+
</table>
|
346
|
+
<p><a class="source-toggle" href="#"
|
347
|
+
onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
|
348
|
+
<div class="method-source-code" id="M000022-source">
|
317
349
|
<pre>
|
318
|
-
|
319
|
-
sparql_client
|
350
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 435</span>
|
351
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">describe_uri</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">sparql_client</span>, <span class="ruby-identifier">type</span>=<span class="ruby-identifier">:cbd</span>)
|
352
|
+
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
353
|
+
<span class="ruby-identifier">resp</span> = <span class="ruby-identifier">sparql_client</span>.<span class="ruby-identifier">describe_uri</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-value str">"application/json"</span>, <span class="ruby-identifier">type</span>)
|
354
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">!=</span> <span class="ruby-value">200</span>
|
355
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}"</span>
|
356
|
+
<span class="ruby-keyword kw">end</span>
|
357
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-constant">Pho</span><span class="ruby-operator">::</span><span class="ruby-constant">ResourceHash</span><span class="ruby-operator">::</span><span class="ruby-constant">Converter</span>.<span class="ruby-identifier">parse_json</span>( <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">content</span> )
|
358
|
+
<span class="ruby-keyword kw">end</span>
|
320
359
|
</pre>
|
360
|
+
</div>
|
361
|
+
</div>
|
362
|
+
</div>
|
363
|
+
|
364
|
+
<div id="method-M000021" class="method-detail">
|
365
|
+
<a name="M000021"></a>
|
366
|
+
|
367
|
+
<div class="method-heading">
|
368
|
+
<a href="#M000021" class="method-signature">
|
369
|
+
<span class="method-name">multi_describe</span><span class="method-args">(uris, sparql_client)</span>
|
370
|
+
</a>
|
371
|
+
</div>
|
372
|
+
|
373
|
+
<div class="method-description">
|
374
|
+
<p>
|
375
|
+
DESCRIBE multiple resources in a single SPARQL request
|
376
|
+
</p>
|
377
|
+
<table>
|
378
|
+
<tr><td valign="top">uris:</td><td>an array of URIs
|
379
|
+
|
380
|
+
</td></tr>
|
381
|
+
<tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> objec
|
382
|
+
|
383
|
+
</td></tr>
|
384
|
+
</table>
|
321
385
|
<p><a class="source-toggle" href="#"
|
322
|
-
onclick="toggleCode('
|
323
|
-
<div class="method-source-code" id="
|
386
|
+
onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
|
387
|
+
<div class="method-source-code" id="M000021-source">
|
324
388
|
<pre>
|
325
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
389
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 420</span>
|
326
390
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">multi_describe</span>(<span class="ruby-identifier">uris</span>, <span class="ruby-identifier">sparql_client</span>)
|
327
391
|
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
328
392
|
<span class="ruby-identifier">resp</span> = <span class="ruby-identifier">sparql_client</span>.<span class="ruby-identifier">multi_describe</span>(<span class="ruby-identifier">uris</span>, <span class="ruby-value str">"application/json"</span>)
|
@@ -336,11 +400,11 @@ DESCRIBE multiple resources in a single SPARQL request
|
|
336
400
|
</div>
|
337
401
|
</div>
|
338
402
|
|
339
|
-
<div id="method-
|
340
|
-
<a name="
|
403
|
+
<div id="method-M000013" class="method-detail">
|
404
|
+
<a name="M000013"></a>
|
341
405
|
|
342
406
|
<div class="method-heading">
|
343
|
-
<a href="#
|
407
|
+
<a href="#M000013" class="method-signature">
|
344
408
|
<span class="method-name">result_to_query_binding</span><span class="method-args">(result)</span>
|
345
409
|
</a>
|
346
410
|
</div>
|
@@ -348,7 +412,7 @@ DESCRIBE multiple resources in a single SPARQL request
|
|
348
412
|
<div class="method-description">
|
349
413
|
<p>
|
350
414
|
Convert a SPARQL query result binding into a hash suitable for passing to
|
351
|
-
the <a href="SparqlHelper.html#
|
415
|
+
the <a href="SparqlHelper.html#M000012">apply_initial_bindings</a> method.
|
352
416
|
</p>
|
353
417
|
<p>
|
354
418
|
The result param is assumed to be a Ruby hash that reflects the structure
|
@@ -358,17 +422,20 @@ result binding.
|
|
358
422
|
</p>
|
359
423
|
<p>
|
360
424
|
The method is intended to be used to support cases where an initial <a
|
361
|
-
href="SparqlHelper.html#
|
425
|
+
href="SparqlHelper.html#M000015">select</a> query is performed to extract
|
362
426
|
some variables that can later be plugged into a subsequent query
|
363
427
|
</p>
|
364
|
-
<
|
365
|
-
result
|
366
|
-
|
428
|
+
<table>
|
429
|
+
<tr><td valign="top">result:</td><td>hash conforming to structure of a <tt>binding</tt> in the SPARQL JSON
|
430
|
+
format
|
431
|
+
|
432
|
+
</td></tr>
|
433
|
+
</table>
|
367
434
|
<p><a class="source-toggle" href="#"
|
368
|
-
onclick="toggleCode('
|
369
|
-
<div class="method-source-code" id="
|
435
|
+
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
436
|
+
<div class="method-source-code" id="M000013-source">
|
370
437
|
<pre>
|
371
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
438
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 285</span>
|
372
439
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">result_to_query_binding</span>(<span class="ruby-identifier">result</span>)
|
373
440
|
<span class="ruby-identifier">hash</span> = {}
|
374
441
|
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
|
@@ -389,11 +456,11 @@ some variables that can later be plugged into a subsequent query
|
|
389
456
|
</div>
|
390
457
|
</div>
|
391
458
|
|
392
|
-
<div id="method-
|
393
|
-
<a name="
|
459
|
+
<div id="method-M000014" class="method-detail">
|
460
|
+
<a name="M000014"></a>
|
394
461
|
|
395
462
|
<div class="method-heading">
|
396
|
-
<a href="#
|
463
|
+
<a href="#M000014" class="method-signature">
|
397
464
|
<span class="method-name">results_to_query_bindings</span><span class="method-args">(results)</span>
|
398
465
|
</a>
|
399
466
|
</div>
|
@@ -402,23 +469,25 @@ some variables that can later be plugged into a subsequent query
|
|
402
469
|
<p>
|
403
470
|
Convert Ruby hash structured according to SPARQL JSON format into an array
|
404
471
|
of hashes by calling <a
|
405
|
-
href="SparqlHelper.html#
|
472
|
+
href="SparqlHelper.html#M000013">result_to_query_binding</a> on each
|
406
473
|
binding into the results.
|
407
474
|
</p>
|
408
475
|
<p>
|
409
|
-
E.g:
|
476
|
+
E.g: <tt>results = <a
|
477
|
+
href="SparqlHelper.html#M000015">Pho::Sparql::SparqlHelper.select</a>(query,
|
478
|
+
sparql_client)</tt> <tt>bindings = <a
|
479
|
+
href="SparqlHelper.html#M000014">Pho::Sparql::SparqlHelper.results_to_query_bindings(results)</a></tt>
|
410
480
|
</p>
|
411
|
-
<
|
412
|
-
|
413
|
-
<tt>bindings = Pho::Sparql::SparqlHelper.results_to_query_bindings(results)</tt>
|
481
|
+
<table>
|
482
|
+
<tr><td valign="top">results:</td><td>hash conforming to SPARQL SELECT structure
|
414
483
|
|
415
|
-
|
416
|
-
</
|
484
|
+
</td></tr>
|
485
|
+
</table>
|
417
486
|
<p><a class="source-toggle" href="#"
|
418
|
-
onclick="toggleCode('
|
419
|
-
<div class="method-source-code" id="
|
487
|
+
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
488
|
+
<div class="method-source-code" id="M000014-source">
|
420
489
|
<pre>
|
421
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
490
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 310</span>
|
422
491
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">results_to_query_bindings</span>(<span class="ruby-identifier">results</span>)
|
423
492
|
<span class="ruby-identifier">bindings</span> = []
|
424
493
|
|
@@ -432,11 +501,11 @@ E.g:
|
|
432
501
|
</div>
|
433
502
|
</div>
|
434
503
|
|
435
|
-
<div id="method-
|
436
|
-
<a name="
|
504
|
+
<div id="method-M000015" class="method-detail">
|
505
|
+
<a name="M000015"></a>
|
437
506
|
|
438
507
|
<div class="method-heading">
|
439
|
-
<a href="#
|
508
|
+
<a href="#M000015" class="method-signature">
|
440
509
|
<span class="method-name">select</span><span class="method-args">(query, sparql_client)</span>
|
441
510
|
</a>
|
442
511
|
</div>
|
@@ -450,15 +519,19 @@ The result will therefore be a simple ruby hash of the results
|
|
450
519
|
<p>
|
451
520
|
An error will be raised if the response is HTTP OK.
|
452
521
|
</p>
|
453
|
-
<
|
454
|
-
query
|
455
|
-
|
456
|
-
</
|
522
|
+
<table>
|
523
|
+
<tr><td valign="top">query:</td><td>the SPARQL SELECT query
|
524
|
+
|
525
|
+
</td></tr>
|
526
|
+
<tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
|
527
|
+
|
528
|
+
</td></tr>
|
529
|
+
</table>
|
457
530
|
<p><a class="source-toggle" href="#"
|
458
|
-
onclick="toggleCode('
|
459
|
-
<div class="method-source-code" id="
|
531
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
532
|
+
<div class="method-source-code" id="M000015-source">
|
460
533
|
<pre>
|
461
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
534
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 327</span>
|
462
535
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
463
536
|
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
464
537
|
<span class="ruby-identifier">resp</span> = <span class="ruby-identifier">sparql_client</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">query</span>, <span class="ruby-constant">Pho</span><span class="ruby-operator">::</span><span class="ruby-constant">Sparql</span><span class="ruby-operator">::</span><span class="ruby-constant">SPARQL_RESULTS_JSON</span>)
|
@@ -472,11 +545,11 @@ An error will be raised if the response is HTTP OK.
|
|
472
545
|
</div>
|
473
546
|
</div>
|
474
547
|
|
475
|
-
<div id="method-
|
476
|
-
<a name="
|
548
|
+
<div id="method-M000018" class="method-detail">
|
549
|
+
<a name="M000018"></a>
|
477
550
|
|
478
551
|
<div class="method-heading">
|
479
|
-
<a href="#
|
552
|
+
<a href="#M000018" class="method-signature">
|
480
553
|
<span class="method-name">select_single_value</span><span class="method-args">(query, sparql_client)</span>
|
481
554
|
</a>
|
482
555
|
</div>
|
@@ -494,15 +567,19 @@ a single value (i.e single variable, with single binding)
|
|
494
567
|
Note this will lose any type information, only the value of the binding is
|
495
568
|
returned
|
496
569
|
</p>
|
497
|
-
<
|
498
|
-
query
|
499
|
-
|
500
|
-
</
|
570
|
+
<table>
|
571
|
+
<tr><td valign="top">query:</td><td>the SPARQL SELECT query
|
572
|
+
|
573
|
+
</td></tr>
|
574
|
+
<tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
|
575
|
+
|
576
|
+
</td></tr>
|
577
|
+
</table>
|
501
578
|
<p><a class="source-toggle" href="#"
|
502
|
-
onclick="toggleCode('
|
503
|
-
<div class="method-source-code" id="
|
579
|
+
onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
|
580
|
+
<div class="method-source-code" id="M000018-source">
|
504
581
|
<pre>
|
505
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
582
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 378</span>
|
506
583
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">select_single_value</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
507
584
|
<span class="ruby-identifier">results</span> = <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
508
585
|
<span class="ruby-identifier">v</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value str">"head"</span>][<span class="ruby-value str">"vars"</span>][<span class="ruby-value">0</span>];
|
@@ -513,11 +590,11 @@ returned
|
|
513
590
|
</div>
|
514
591
|
</div>
|
515
592
|
|
516
|
-
<div id="method-
|
517
|
-
<a name="
|
593
|
+
<div id="method-M000017" class="method-detail">
|
594
|
+
<a name="M000017"></a>
|
518
595
|
|
519
596
|
<div class="method-heading">
|
520
|
-
<a href="#
|
597
|
+
<a href="#M000017" class="method-signature">
|
521
598
|
<span class="method-name">select_values</span><span class="method-args">(query, sparql_client)</span>
|
522
599
|
</a>
|
523
600
|
</div>
|
@@ -537,15 +614,19 @@ an array
|
|
537
614
|
Note this will lose any type information, only the value of the bindings
|
538
615
|
are returned
|
539
616
|
</p>
|
540
|
-
<
|
541
|
-
query
|
542
|
-
|
543
|
-
</
|
617
|
+
<table>
|
618
|
+
<tr><td valign="top">query:</td><td>the SPARQL SELECT query
|
619
|
+
|
620
|
+
</td></tr>
|
621
|
+
<tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
|
622
|
+
|
623
|
+
</td></tr>
|
624
|
+
</table>
|
544
625
|
<p><a class="source-toggle" href="#"
|
545
|
-
onclick="toggleCode('
|
546
|
-
<div class="method-source-code" id="
|
626
|
+
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
627
|
+
<div class="method-source-code" id="M000017-source">
|
547
628
|
<pre>
|
548
|
-
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line
|
629
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 358</span>
|
549
630
|
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">select_values</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
550
631
|
<span class="ruby-identifier">results</span> = <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">query</span>, <span class="ruby-identifier">sparql_client</span>)
|
551
632
|
<span class="ruby-identifier">v</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value str">"head"</span>][<span class="ruby-value str">"vars"</span>][<span class="ruby-value">0</span>];
|