pho 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGES +5 -0
  2. data/Rakefile +1 -1
  3. data/lib/pho/snapshot.rb +6 -1
  4. data/lib/pho/sparql.rb +4 -1
  5. data/tests/tc_snapshots.rb +14 -1
  6. data/tests/tc_sparql_helper.rb +23 -0
  7. metadata +60 -160
  8. data/doc/rdoc/classes/Pho/Analyzers.html +0 -310
  9. data/doc/rdoc/classes/Pho/CommandLine.html +0 -770
  10. data/doc/rdoc/classes/Pho/DatatypeProperty.html +0 -241
  11. data/doc/rdoc/classes/Pho/Enrichment/StoreEnricher.html +0 -410
  12. data/doc/rdoc/classes/Pho/Enrichment.html +0 -119
  13. data/doc/rdoc/classes/Pho/Etags.html +0 -310
  14. data/doc/rdoc/classes/Pho/Facet/Results.html +0 -299
  15. data/doc/rdoc/classes/Pho/Facet/Term.html +0 -177
  16. data/doc/rdoc/classes/Pho/Facet.html +0 -119
  17. data/doc/rdoc/classes/Pho/FieldPredicateMap.html +0 -668
  18. data/doc/rdoc/classes/Pho/FieldWeighting.html +0 -230
  19. data/doc/rdoc/classes/Pho/FileManagement/AbstractFileManager.html +0 -478
  20. data/doc/rdoc/classes/Pho/FileManagement/FileManager.html +0 -264
  21. data/doc/rdoc/classes/Pho/FileManagement/RDFManager.html +0 -259
  22. data/doc/rdoc/classes/Pho/FileManagement.html +0 -121
  23. data/doc/rdoc/classes/Pho/Job.html +0 -627
  24. data/doc/rdoc/classes/Pho/JobUpdate.html +0 -141
  25. data/doc/rdoc/classes/Pho/Jobs.html +0 -538
  26. data/doc/rdoc/classes/Pho/Namespaces.html +0 -164
  27. data/doc/rdoc/classes/Pho/OAI/Record.html +0 -165
  28. data/doc/rdoc/classes/Pho/OAI/Records.html +0 -331
  29. data/doc/rdoc/classes/Pho/OAI.html +0 -118
  30. data/doc/rdoc/classes/Pho/QueryProfile.html +0 -497
  31. data/doc/rdoc/classes/Pho/RDF/Parser.html +0 -279
  32. data/doc/rdoc/classes/Pho/RDF.html +0 -120
  33. data/doc/rdoc/classes/Pho/RDFCollection.html +0 -119
  34. data/doc/rdoc/classes/Pho/ResourceHash/Converter.html +0 -325
  35. data/doc/rdoc/classes/Pho/ResourceHash/SetAlgebra.html +0 -241
  36. data/doc/rdoc/classes/Pho/ResourceHash.html +0 -123
  37. data/doc/rdoc/classes/Pho/Snapshot.html +0 -397
  38. data/doc/rdoc/classes/Pho/Sparql/SparqlClient.html +0 -594
  39. data/doc/rdoc/classes/Pho/Sparql/SparqlHelper.html +0 -692
  40. data/doc/rdoc/classes/Pho/Sparql.html +0 -187
  41. data/doc/rdoc/classes/Pho/Status.html +0 -296
  42. data/doc/rdoc/classes/Pho/Store.html +0 -1560
  43. data/doc/rdoc/classes/Pho/StoreSparqlClient.html +0 -183
  44. data/doc/rdoc/classes/Pho/Update/Changeset.html +0 -521
  45. data/doc/rdoc/classes/Pho/Update/ChangesetBuilder.html +0 -330
  46. data/doc/rdoc/classes/Pho/Update/ChangesetHelper.html +0 -159
  47. data/doc/rdoc/classes/Pho/Update/Changesets.html +0 -205
  48. data/doc/rdoc/classes/Pho/Update/LiteralStatement.html +0 -257
  49. data/doc/rdoc/classes/Pho/Update/ResourceStatement.html +0 -237
  50. data/doc/rdoc/classes/Pho/Update/Statement.html +0 -303
  51. data/doc/rdoc/classes/Pho/Update.html +0 -128
  52. data/doc/rdoc/classes/Pho.html +0 -283
  53. data/doc/rdoc/classes/String.html +0 -146
  54. data/doc/rdoc/created.rid +0 -1
  55. data/doc/rdoc/files/CHANGES.html +0 -351
  56. data/doc/rdoc/files/README.html +0 -191
  57. data/doc/rdoc/files/lib/pho/changeset_builder_rb.html +0 -108
  58. data/doc/rdoc/files/lib/pho/changeset_rb.html +0 -108
  59. data/doc/rdoc/files/lib/pho/command_line_rb.html +0 -101
  60. data/doc/rdoc/files/lib/pho/converter_rb.html +0 -108
  61. data/doc/rdoc/files/lib/pho/enrichment_rb.html +0 -101
  62. data/doc/rdoc/files/lib/pho/etags_rb.html +0 -108
  63. data/doc/rdoc/files/lib/pho/facet_rb.html +0 -101
  64. data/doc/rdoc/files/lib/pho/field_predicate_map_rb.html +0 -101
  65. data/doc/rdoc/files/lib/pho/file_management_rb.html +0 -101
  66. data/doc/rdoc/files/lib/pho/file_manager_rb.html +0 -108
  67. data/doc/rdoc/files/lib/pho/job_rb.html +0 -101
  68. data/doc/rdoc/files/lib/pho/oai_rb.html +0 -101
  69. data/doc/rdoc/files/lib/pho/query_profile_rb.html +0 -101
  70. data/doc/rdoc/files/lib/pho/rdf_collection_rb.html +0 -101
  71. data/doc/rdoc/files/lib/pho/rdf_rb.html +0 -108
  72. data/doc/rdoc/files/lib/pho/resource_hash_rb.html +0 -101
  73. data/doc/rdoc/files/lib/pho/snapshot_rb.html +0 -109
  74. data/doc/rdoc/files/lib/pho/sparql_rb.html +0 -101
  75. data/doc/rdoc/files/lib/pho/status_rb.html +0 -101
  76. data/doc/rdoc/files/lib/pho/store_rb.html +0 -108
  77. data/doc/rdoc/files/lib/pho_rb.html +0 -133
  78. data/doc/rdoc/fr_class_index.html +0 -72
  79. data/doc/rdoc/fr_file_index.html +0 -49
  80. data/doc/rdoc/fr_method_index.html +0 -237
  81. data/doc/rdoc/index.html +0 -24
  82. data/doc/rdoc/rdoc-style.css +0 -208
@@ -1,692 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Class: Pho::Sparql::SparqlHelper</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Class</strong></td>
53
- <td class="class-name-in-header">Pho::Sparql::SparqlHelper</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../../../files/lib/pho/sparql_rb.html">
59
- lib/pho/sparql.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- <tr class="top-aligned-row">
66
- <td><strong>Parent:</strong></td>
67
- <td>
68
- Object
69
- </td>
70
- </tr>
71
- </table>
72
- </div>
73
- <!-- banner header -->
74
-
75
- <div id="bodyContent">
76
-
77
-
78
-
79
- <div id="contextContent">
80
-
81
- <div id="description">
82
- <p>
83
- Simple helper class for manipulating and executing SPARQL queries and
84
- manipulating the results
85
- </p>
86
-
87
- </div>
88
-
89
-
90
- </div>
91
-
92
- <div id="method-list">
93
- <h3 class="section-bar">Methods</h3>
94
-
95
- <div class="name-list">
96
- <a href="#M000012">apply_initial_bindings</a>&nbsp;&nbsp;
97
- <a href="#M000016">ask</a>&nbsp;&nbsp;
98
- <a href="#M000020">construct_to_resource_hash</a>&nbsp;&nbsp;
99
- <a href="#M000021">describe_to_resource_hash</a>&nbsp;&nbsp;
100
- <a href="#M000023">describe_uri</a>&nbsp;&nbsp;
101
- <a href="#M000017">exists</a>&nbsp;&nbsp;
102
- <a href="#M000022">multi_describe</a>&nbsp;&nbsp;
103
- <a href="#M000013">result_to_query_binding</a>&nbsp;&nbsp;
104
- <a href="#M000014">results_to_query_bindings</a>&nbsp;&nbsp;
105
- <a href="#M000015">select</a>&nbsp;&nbsp;
106
- <a href="#M000019">select_single_value</a>&nbsp;&nbsp;
107
- <a href="#M000018">select_values</a>&nbsp;&nbsp;
108
- </div>
109
- </div>
110
-
111
- </div>
112
-
113
-
114
- <!-- if includes -->
115
-
116
- <div id="section">
117
-
118
-
119
- <div id="constants-list">
120
- <h3 class="section-bar">Constants</h3>
121
-
122
- <div class="name-list">
123
- <table summary="Constants">
124
- <tr class="top-aligned-row context-row">
125
- <td class="context-item-name">VARIABLE_MATCHER</td>
126
- <td>=</td>
127
- <td class="context-item-value">/(\?|\$)([a-zA-Z]+)/</td>
128
- </tr>
129
- </table>
130
- </div>
131
- </div>
132
-
133
-
134
-
135
-
136
-
137
-
138
- <!-- if method_list -->
139
- <div id="methods">
140
- <h3 class="section-bar">Public Class methods</h3>
141
-
142
- <div id="method-M000012" class="method-detail">
143
- <a name="M000012"></a>
144
-
145
- <div class="method-heading">
146
- <a href="#M000012" class="method-signature">
147
- <span class="method-name">apply_initial_bindings</span><span class="method-args">(query, bindings={})</span>
148
- </a>
149
- </div>
150
-
151
- <div class="method-description">
152
- <p>
153
- Apply some initial bindings to parameters in a query
154
- </p>
155
- <p>
156
- The keys in the values hash are used to replace variables in a query The
157
- values are supplied as is, allowing them to be provided as URIs, or typed
158
- literals according to Turtle syntax.
159
- </p>
160
- <p>
161
- Any keys in the hash that are not in the query are ignored. Any variables
162
- not found in the hash remain unbound.
163
- </p>
164
- <table>
165
- <tr><td valign="top">query:</td><td>the query whose initial bindings are to be set
166
-
167
- </td></tr>
168
- <tr><td valign="top">values:</td><td>hash of query name to value
169
-
170
- </td></tr>
171
- </table>
172
- <p><a class="source-toggle" href="#"
173
- onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
174
- <div class="method-source-code" id="M000012-source">
175
- <pre>
176
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 260</span>
177
- <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>={})
178
- <span class="ruby-identifier">copy</span> = <span class="ruby-identifier">query</span>.<span class="ruby-identifier">clone</span>()
179
- <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>
180
- <span class="ruby-identifier">key</span> = <span class="ruby-identifier">$2</span>
181
- <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">bindings</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">key</span>)
182
- <span class="ruby-identifier">bindings</span>[<span class="ruby-identifier">key</span>].<span class="ruby-identifier">to_s</span>
183
- <span class="ruby-keyword kw">else</span>
184
- <span class="ruby-identifier">pattern</span>
185
- <span class="ruby-keyword kw">end</span>
186
- <span class="ruby-keyword kw">end</span>
187
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">copy</span>
188
- <span class="ruby-keyword kw">end</span>
189
- </pre>
190
- </div>
191
- </div>
192
- </div>
193
-
194
- <div id="method-M000016" class="method-detail">
195
- <a name="M000016"></a>
196
-
197
- <div class="method-heading">
198
- <a href="#M000016" class="method-signature">
199
- <span class="method-name">ask</span><span class="method-args">(query, sparql_client)</span>
200
- </a>
201
- </div>
202
-
203
- <div class="method-description">
204
- <p>
205
- Performs an ASK query on an endpoint, returing a boolean true/false
206
- response
207
- </p>
208
- <p>
209
- Will request the results using the SPARQL JSON results format, parse the
210
- resulting JSON results, and extract the true/false response.
211
- </p>
212
- <table>
213
- <tr><td valign="top">query:</td><td>the SPARQL SELECT query
214
-
215
- </td></tr>
216
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
217
-
218
- </td></tr>
219
- </table>
220
- <p><a class="source-toggle" href="#"
221
- onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
222
- <div class="method-source-code" id="M000016-source">
223
- <pre>
224
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 343</span>
225
- <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>)
226
- <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>)
227
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">json</span>[<span class="ruby-value str">&quot;boolean&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;true&quot;</span>
228
- <span class="ruby-keyword kw">end</span>
229
- </pre>
230
- </div>
231
- </div>
232
- </div>
233
-
234
- <div id="method-M000020" class="method-detail">
235
- <a name="M000020"></a>
236
-
237
- <div class="method-heading">
238
- <a href="#M000020" class="method-signature">
239
- <span class="method-name">construct_to_resource_hash</span><span class="method-args">(query, sparql_client)</span>
240
- </a>
241
- </div>
242
-
243
- <div class="method-description">
244
- <p>
245
- Perform a SPARQL CONSTRUCT query against an endpoint, requesting the
246
- results in JSON
247
- </p>
248
- <p>
249
- Will request the results as application/json (with the expectation that it
250
- returns RDF_JSON), and parses the resulting JSON document.
251
- </p>
252
- <table>
253
- <tr><td valign="top">query:</td><td>the SPARQL SELECT query
254
-
255
- </td></tr>
256
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
257
-
258
- </td></tr>
259
- </table>
260
- <p><a class="source-toggle" href="#"
261
- onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
262
- <div class="method-source-code" id="M000020-source">
263
- <pre>
264
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 400</span>
265
- <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>)
266
- <span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
267
- <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">&quot;application/json&quot;</span>)
268
- <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>
269
- <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}&quot;</span>
270
- <span class="ruby-keyword kw">end</span>
271
- <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> )
272
- <span class="ruby-keyword kw">end</span>
273
- </pre>
274
- </div>
275
- </div>
276
- </div>
277
-
278
- <div id="method-M000021" class="method-detail">
279
- <a name="M000021"></a>
280
-
281
- <div class="method-heading">
282
- <a href="#M000021" class="method-signature">
283
- <span class="method-name">describe_to_resource_hash</span><span class="method-args">(query, sparql_client)</span>
284
- </a>
285
- </div>
286
-
287
- <div class="method-description">
288
- <p>
289
- Perform a SPARQL DESCRIBE query against an endpoint, requesting the results
290
- in JSON
291
- </p>
292
- <p>
293
- Will request the results as application/json (with the expectation that it
294
- returns RDF_JSON), and parses the resulting JSON document.
295
- </p>
296
- <table>
297
- <tr><td valign="top">query:</td><td>the SPARQL SELECT query
298
-
299
- </td></tr>
300
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
301
-
302
- </td></tr>
303
- </table>
304
- <p><a class="source-toggle" href="#"
305
- onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
306
- <div class="method-source-code" id="M000021-source">
307
- <pre>
308
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 416</span>
309
- <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>)
310
- <span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
311
- <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">&quot;application/json&quot;</span>)
312
- <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>
313
- <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}&quot;</span>
314
- <span class="ruby-keyword kw">end</span>
315
- <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> )
316
- <span class="ruby-keyword kw">end</span>
317
- </pre>
318
- </div>
319
- </div>
320
- </div>
321
-
322
- <div id="method-M000023" class="method-detail">
323
- <a name="M000023"></a>
324
-
325
- <div class="method-heading">
326
- <a href="#M000023" class="method-signature">
327
- <span class="method-name">describe_uri</span><span class="method-args">(uri, sparql_client, type=:cbd)</span>
328
- </a>
329
- </div>
330
-
331
- <div class="method-description">
332
- <p>
333
- Describe a single URI using one of several forms of Bounded Description See
334
- <a href="SparqlClient.html#M000006">SparqlClient.describe_uri</a>
335
- </p>
336
- <table>
337
- <tr><td valign="top">uri:</td><td>resource to describe
338
-
339
- </td></tr>
340
- <tr><td valign="top">sparql_client:</td><td>configured SPARQL client
341
-
342
- </td></tr>
343
- <tr><td valign="top">type:</td><td>form of bounded description to generate
344
-
345
- </td></tr>
346
- </table>
347
- <p><a class="source-toggle" href="#"
348
- onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
349
- <div class="method-source-code" id="M000023-source">
350
- <pre>
351
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 444</span>
352
- <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>)
353
- <span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
354
- <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">&quot;application/json&quot;</span>, <span class="ruby-identifier">type</span>)
355
- <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>
356
- <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}&quot;</span>
357
- <span class="ruby-keyword kw">end</span>
358
- <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> )
359
- <span class="ruby-keyword kw">end</span>
360
- </pre>
361
- </div>
362
- </div>
363
- </div>
364
-
365
- <div id="method-M000017" class="method-detail">
366
- <a name="M000017"></a>
367
-
368
- <div class="method-heading">
369
- <a href="#M000017" class="method-signature">
370
- <span class="method-name">exists</span><span class="method-args">(uri, sparql_client)</span>
371
- </a>
372
- </div>
373
-
374
- <div class="method-description">
375
- <p>
376
- Performs an ASK query on the SPARQL endpoint to test whether there are any
377
- statements in the triple store about the specified uri.
378
- </p>
379
- <table>
380
- <tr><td valign="top">uri:</td><td>the uri to test for
381
-
382
- </td></tr>
383
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
384
-
385
- </td></tr>
386
- </table>
387
- <p><a class="source-toggle" href="#"
388
- onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
389
- <div class="method-source-code" id="M000017-source">
390
- <pre>
391
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 353</span>
392
- <span class="ruby-keyword kw">def</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">exists</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">sparql_client</span>)
393
- <span class="ruby-keyword kw">return</span> <span class="ruby-constant">SparqlHelper</span>.<span class="ruby-identifier">ask</span>(<span class="ruby-node">&quot;ASK { &lt;#{uri}&gt; ?p ?o }&quot;</span>, <span class="ruby-identifier">sparql_client</span>)
394
- <span class="ruby-keyword kw">end</span>
395
- </pre>
396
- </div>
397
- </div>
398
- </div>
399
-
400
- <div id="method-M000022" class="method-detail">
401
- <a name="M000022"></a>
402
-
403
- <div class="method-heading">
404
- <a href="#M000022" class="method-signature">
405
- <span class="method-name">multi_describe</span><span class="method-args">(uris, sparql_client)</span>
406
- </a>
407
- </div>
408
-
409
- <div class="method-description">
410
- <p>
411
- DESCRIBE multiple resources in a single SPARQL request
412
- </p>
413
- <table>
414
- <tr><td valign="top">uris:</td><td>an array of URIs
415
-
416
- </td></tr>
417
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> objec
418
-
419
- </td></tr>
420
- </table>
421
- <p><a class="source-toggle" href="#"
422
- onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
423
- <div class="method-source-code" id="M000022-source">
424
- <pre>
425
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 429</span>
426
- <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>)
427
- <span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
428
- <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">&quot;application/json&quot;</span>)
429
- <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>
430
- <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}&quot;</span>
431
- <span class="ruby-keyword kw">end</span>
432
- <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> )
433
- <span class="ruby-keyword kw">end</span>
434
- </pre>
435
- </div>
436
- </div>
437
- </div>
438
-
439
- <div id="method-M000013" class="method-detail">
440
- <a name="M000013"></a>
441
-
442
- <div class="method-heading">
443
- <a href="#M000013" class="method-signature">
444
- <span class="method-name">result_to_query_binding</span><span class="method-args">(result)</span>
445
- </a>
446
- </div>
447
-
448
- <div class="method-description">
449
- <p>
450
- Convert a SPARQL query result binding into a hash suitable for passing to
451
- the <a href="SparqlHelper.html#M000012">apply_initial_bindings</a> method.
452
- </p>
453
- <p>
454
- The result param is assumed to be a Ruby hash that reflects the structure
455
- of a binding in a SELECT query result (i.e. the result of parsing the
456
- <tt>application/sparql-results+json</tt> format and extracting an specific
457
- result binding.
458
- </p>
459
- <p>
460
- The method is intended to be used to support cases where an initial <a
461
- href="SparqlHelper.html#M000015">select</a> query is performed to extract
462
- some variables that can later be plugged into a subsequent query
463
- </p>
464
- <table>
465
- <tr><td valign="top">result:</td><td>hash conforming to structure of a <tt>binding</tt> in the SPARQL JSON
466
- format
467
-
468
- </td></tr>
469
- </table>
470
- <p><a class="source-toggle" href="#"
471
- onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
472
- <div class="method-source-code" id="M000013-source">
473
- <pre>
474
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 285</span>
475
- <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>)
476
- <span class="ruby-identifier">hash</span> = {}
477
- <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>
478
- <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">&quot;type&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;uri&quot;</span>
479
- <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-node">&quot;&lt;#{value[&quot;value&quot;]}&gt;&quot;</span>
480
- <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">value</span>[<span class="ruby-value str">&quot;type&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;literal&quot;</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">&quot;datatype&quot;</span>))
481
- <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-node">&quot;\&quot;#{value[&quot;value&quot;]}\&quot;&quot;</span>
482
- <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">value</span>[<span class="ruby-value str">&quot;type&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;literal&quot;</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">&quot;datatype&quot;</span>))
483
- <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-node">&quot;\&quot;#{value[&quot;value&quot;]}\&quot;^^#{value[&quot;datatype&quot;]}&quot;</span>
484
- <span class="ruby-keyword kw">else</span>
485
- <span class="ruby-comment cmt">#do nothing for bnodes</span>
486
- <span class="ruby-keyword kw">end</span>
487
- <span class="ruby-keyword kw">end</span>
488
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">hash</span>
489
- <span class="ruby-keyword kw">end</span>
490
- </pre>
491
- </div>
492
- </div>
493
- </div>
494
-
495
- <div id="method-M000014" class="method-detail">
496
- <a name="M000014"></a>
497
-
498
- <div class="method-heading">
499
- <a href="#M000014" class="method-signature">
500
- <span class="method-name">results_to_query_bindings</span><span class="method-args">(results)</span>
501
- </a>
502
- </div>
503
-
504
- <div class="method-description">
505
- <p>
506
- Convert Ruby hash structured according to SPARQL JSON format into an array
507
- of hashes by calling <a
508
- href="SparqlHelper.html#M000013">result_to_query_binding</a> on each
509
- binding into the results.
510
- </p>
511
- <p>
512
- E.g: <tt>results = <a
513
- href="SparqlHelper.html#M000015">Pho::Sparql::SparqlHelper.select</a>(query,
514
- sparql_client)</tt> <tt>bindings = <a
515
- href="SparqlHelper.html#M000014">Pho::Sparql::SparqlHelper.results_to_query_bindings(results)</a></tt>
516
- </p>
517
- <table>
518
- <tr><td valign="top">results:</td><td>hash conforming to SPARQL SELECT structure
519
-
520
- </td></tr>
521
- </table>
522
- <p><a class="source-toggle" href="#"
523
- onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
524
- <div class="method-source-code" id="M000014-source">
525
- <pre>
526
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 310</span>
527
- <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>)
528
- <span class="ruby-identifier">bindings</span> = []
529
-
530
- <span class="ruby-identifier">results</span>[<span class="ruby-value str">&quot;results&quot;</span>][<span class="ruby-value str">&quot;bindings&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">result</span><span class="ruby-operator">|</span>
531
- <span class="ruby-identifier">bindings</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">result_to_query_binding</span>(<span class="ruby-identifier">result</span>)
532
- <span class="ruby-keyword kw">end</span>
533
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">bindings</span>
534
- <span class="ruby-keyword kw">end</span>
535
- </pre>
536
- </div>
537
- </div>
538
- </div>
539
-
540
- <div id="method-M000015" class="method-detail">
541
- <a name="M000015"></a>
542
-
543
- <div class="method-heading">
544
- <a href="#M000015" class="method-signature">
545
- <span class="method-name">select</span><span class="method-args">(query, sparql_client)</span>
546
- </a>
547
- </div>
548
-
549
- <div class="method-description">
550
- <p>
551
- Perform a simple SELECT query on an endpoint. Will request the results
552
- using the SPARQL JSON results format, and parse the resulting JSON results.
553
- The result will therefore be a simple ruby hash of the results
554
- </p>
555
- <p>
556
- An error will be raised if the response is HTTP OK.
557
- </p>
558
- <table>
559
- <tr><td valign="top">query:</td><td>the SPARQL SELECT query
560
-
561
- </td></tr>
562
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
563
-
564
- </td></tr>
565
- </table>
566
- <p><a class="source-toggle" href="#"
567
- onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
568
- <div class="method-source-code" id="M000015-source">
569
- <pre>
570
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 327</span>
571
- <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>)
572
- <span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
573
- <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>)
574
- <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>
575
- <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}&quot;</span>
576
- <span class="ruby-keyword kw">end</span>
577
- <span class="ruby-keyword kw">return</span> <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>( <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">content</span> )
578
- <span class="ruby-keyword kw">end</span>
579
- </pre>
580
- </div>
581
- </div>
582
- </div>
583
-
584
- <div id="method-M000019" class="method-detail">
585
- <a name="M000019"></a>
586
-
587
- <div class="method-heading">
588
- <a href="#M000019" class="method-signature">
589
- <span class="method-name">select_single_value</span><span class="method-args">(query, sparql_client)</span>
590
- </a>
591
- </div>
592
-
593
- <div class="method-description">
594
- <p>
595
- Perform a simple SELECT query on an endpoint and return a single result
596
- </p>
597
- <p>
598
- Will request the results using the SPARQL JSON results format, and parse
599
- the resulting JSON results. The assumption is that the SELECT query returns
600
- a single value (i.e single variable, with single binding)
601
- </p>
602
- <p>
603
- Note this will lose any type information, only the value of the binding is
604
- returned
605
- </p>
606
- <table>
607
- <tr><td valign="top">query:</td><td>the SPARQL SELECT query
608
-
609
- </td></tr>
610
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
611
-
612
- </td></tr>
613
- </table>
614
- <p><a class="source-toggle" href="#"
615
- onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
616
- <div class="method-source-code" id="M000019-source">
617
- <pre>
618
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 387</span>
619
- <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>)
620
- <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>)
621
- <span class="ruby-identifier">v</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value str">&quot;head&quot;</span>][<span class="ruby-value str">&quot;vars&quot;</span>][<span class="ruby-value">0</span>];
622
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">results</span>[<span class="ruby-value str">&quot;results&quot;</span>][<span class="ruby-value str">&quot;bindings&quot;</span>][<span class="ruby-value">0</span>][<span class="ruby-identifier">v</span>][<span class="ruby-value str">&quot;value&quot;</span>]
623
- <span class="ruby-keyword kw">end</span>
624
- </pre>
625
- </div>
626
- </div>
627
- </div>
628
-
629
- <div id="method-M000018" class="method-detail">
630
- <a name="M000018"></a>
631
-
632
- <div class="method-heading">
633
- <a href="#M000018" class="method-signature">
634
- <span class="method-name">select_values</span><span class="method-args">(query, sparql_client)</span>
635
- </a>
636
- </div>
637
-
638
- <div class="method-description">
639
- <p>
640
- Perform a simple SELECT query on an endpoint and return a simple array of
641
- values
642
- </p>
643
- <p>
644
- Will request the results using the SPARQL JSON results format, and parse
645
- the resulting JSON results. The assumption is that the SELECT query
646
- contains a single &quot;column&quot; of values, which will be returned as
647
- an array
648
- </p>
649
- <p>
650
- Note this will lose any type information, only the value of the bindings
651
- are returned
652
- </p>
653
- <table>
654
- <tr><td valign="top">query:</td><td>the SPARQL SELECT query
655
-
656
- </td></tr>
657
- <tr><td valign="top">sparql_client:</td><td>a configured <a href="SparqlClient.html">SparqlClient</a> object
658
-
659
- </td></tr>
660
- </table>
661
- <p><a class="source-toggle" href="#"
662
- onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
663
- <div class="method-source-code" id="M000018-source">
664
- <pre>
665
- <span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 367</span>
666
- <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>)
667
- <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>)
668
- <span class="ruby-identifier">v</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value str">&quot;head&quot;</span>][<span class="ruby-value str">&quot;vars&quot;</span>][<span class="ruby-value">0</span>];
669
- <span class="ruby-identifier">values</span> = [];
670
- <span class="ruby-identifier">results</span>[<span class="ruby-value str">&quot;results&quot;</span>][<span class="ruby-value str">&quot;bindings&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">binding</span><span class="ruby-operator">|</span>
671
- <span class="ruby-identifier">values</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">binding</span>[<span class="ruby-identifier">v</span>][<span class="ruby-value str">&quot;value&quot;</span>]
672
- <span class="ruby-keyword kw">end</span>
673
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">values</span>
674
- <span class="ruby-keyword kw">end</span>
675
- </pre>
676
- </div>
677
- </div>
678
- </div>
679
-
680
-
681
- </div>
682
-
683
-
684
- </div>
685
-
686
-
687
- <div id="validator-badges">
688
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
689
- </div>
690
-
691
- </body>
692
- </html>