pho 0.4.1 → 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +18 -1
- data/README +10 -0
- data/Rakefile +2 -1
- data/doc/rdoc/classes/Pho.html +33 -22
- data/doc/rdoc/classes/Pho/DatatypeProperty.html +12 -12
- data/doc/rdoc/classes/Pho/{RDF_JSON.html → Enrichment.html} +8 -7
- data/doc/rdoc/classes/Pho/Enrichment/ResourceEnricher.html +310 -0
- data/doc/rdoc/classes/Pho/Etags.html +42 -42
- 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 +110 -105
- data/doc/rdoc/classes/Pho/FieldWeighting.html +12 -12
- data/doc/rdoc/classes/Pho/FileManagement.html +121 -0
- data/doc/rdoc/classes/Pho/FileManagement/AbstractFileManager.html +443 -0
- data/doc/rdoc/classes/Pho/FileManagement/FileManager.html +258 -0
- data/doc/rdoc/classes/Pho/FileManagement/RDFManager.html +271 -0
- data/doc/rdoc/classes/Pho/Job.html +64 -64
- data/doc/rdoc/classes/Pho/Jobs.html +60 -60
- data/doc/rdoc/classes/Pho/QueryProfile.html +60 -60
- data/doc/rdoc/classes/Pho/RDFCollection.html +4 -378
- data/doc/rdoc/classes/Pho/ResourceHash.html +123 -0
- data/doc/rdoc/classes/Pho/ResourceHash/Converter.html +323 -0
- data/doc/rdoc/classes/Pho/{RDF_JSON → ResourceHash}/SetAlgebra.html +18 -18
- data/doc/rdoc/classes/Pho/Snapshot.html +35 -35
- data/doc/rdoc/classes/Pho/Sparql.html +137 -0
- data/doc/rdoc/classes/Pho/Sparql/SparqlClient.html +515 -0
- data/doc/rdoc/classes/Pho/Sparql/SparqlHelper.html +575 -0
- data/doc/rdoc/classes/Pho/Status.html +26 -26
- data/doc/rdoc/classes/Pho/Store.html +271 -241
- data/doc/rdoc/classes/Pho/Update/Changeset.html +73 -73
- data/doc/rdoc/classes/Pho/Update/ChangesetBuilder.html +34 -34
- data/doc/rdoc/classes/Pho/Update/Changesets.html +14 -14
- data/doc/rdoc/classes/Pho/Update/LiteralStatement.html +31 -23
- data/doc/rdoc/classes/Pho/Update/ResourceStatement.html +45 -21
- data/doc/rdoc/classes/Pho/Update/Statement.html +29 -29
- data/doc/rdoc/classes/String.html +1 -1
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +49 -3
- data/doc/rdoc/files/README.html +15 -1
- data/doc/rdoc/files/lib/pho/changeset_builder_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/changeset_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/converter_rb.html +108 -0
- data/doc/rdoc/files/lib/pho/enrichment_rb.html +101 -0
- data/doc/rdoc/files/lib/pho/etags_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/field_predicate_map_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/file_management_rb.html +101 -0
- data/doc/rdoc/files/lib/pho/file_manager_rb.html +108 -0
- data/doc/rdoc/files/lib/pho/rdf_collection_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/resource_hash_rb.html +101 -0
- data/doc/rdoc/files/lib/pho/{rdf_json_rb.html → sparql_rb.html} +4 -4
- data/doc/rdoc/files/lib/pho/store_rb.html +1 -1
- data/doc/rdoc/files/lib/pho_rb.html +7 -2
- data/doc/rdoc/fr_class_index.html +12 -2
- data/doc/rdoc/fr_file_index.html +6 -1
- data/doc/rdoc/fr_method_index.html +176 -139
- data/examples/sparql_construct_hash.rb +26 -0
- data/examples/sparql_select.rb +18 -0
- data/lib/pho.rb +6 -1
- data/lib/pho/changeset.rb +24 -9
- data/lib/pho/changeset_builder.rb +10 -10
- data/lib/pho/converter.rb +74 -0
- data/lib/pho/enrichment.rb +81 -0
- data/lib/pho/etags.rb +1 -0
- data/lib/pho/field_predicate_map.rb +6 -1
- data/lib/pho/file_management.rb +102 -0
- data/lib/pho/file_manager.rb +61 -0
- data/lib/pho/rdf_collection.rb +54 -120
- data/lib/pho/{rdf_json.rb → resource_hash.rb} +3 -4
- data/lib/pho/sparql.rb +332 -0
- data/lib/pho/store.rb +20 -14
- data/tests/tc_changeset.rb +46 -0
- data/tests/tc_changeset_builder.rb +122 -1
- data/tests/tc_converter.rb +95 -0
- data/tests/tc_enrichment.rb +83 -0
- data/tests/tc_file_manager.rb +88 -0
- data/tests/tc_rdf_collection.rb +3 -0
- data/tests/{tc_rdf_json.rb → tc_resource_hash.rb} +23 -23
- data/tests/tc_search.rb +1 -1
- data/tests/tc_sparql.rb +131 -6
- data/tests/tc_sparql_helper.rb +214 -0
- data/tests/ts_pho.rb +6 -2
- metadata +47 -8
|
@@ -0,0 +1,575 @@
|
|
|
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="#M000011">apply_initial_bindings</a>
|
|
97
|
+
<a href="#M000015">ask</a>
|
|
98
|
+
<a href="#M000018">construct_to_resource_hash</a>
|
|
99
|
+
<a href="#M000019">describe_to_resource_hash</a>
|
|
100
|
+
<a href="#M000020">multi_describe</a>
|
|
101
|
+
<a href="#M000012">result_to_query_binding</a>
|
|
102
|
+
<a href="#M000013">results_to_query_bindings</a>
|
|
103
|
+
<a href="#M000014">select</a>
|
|
104
|
+
<a href="#M000017">select_single_value</a>
|
|
105
|
+
<a href="#M000016">select_values</a>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
<!-- if includes -->
|
|
113
|
+
|
|
114
|
+
<div id="section">
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
<div id="constants-list">
|
|
118
|
+
<h3 class="section-bar">Constants</h3>
|
|
119
|
+
|
|
120
|
+
<div class="name-list">
|
|
121
|
+
<table summary="Constants">
|
|
122
|
+
<tr class="top-aligned-row context-row">
|
|
123
|
+
<td class="context-item-name">VARIABLE_MATCHER</td>
|
|
124
|
+
<td>=</td>
|
|
125
|
+
<td class="context-item-value">/(\?|\$)([a-zA-Z]+)/</td>
|
|
126
|
+
</tr>
|
|
127
|
+
</table>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
<!-- if method_list -->
|
|
137
|
+
<div id="methods">
|
|
138
|
+
<h3 class="section-bar">Public Class methods</h3>
|
|
139
|
+
|
|
140
|
+
<div id="method-M000011" class="method-detail">
|
|
141
|
+
<a name="M000011"></a>
|
|
142
|
+
|
|
143
|
+
<div class="method-heading">
|
|
144
|
+
<a href="#M000011" class="method-signature">
|
|
145
|
+
<span class="method-name">apply_initial_bindings</span><span class="method-args">(query, bindings={})</span>
|
|
146
|
+
</a>
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<div class="method-description">
|
|
150
|
+
<p>
|
|
151
|
+
Apply some initial bindings to parameters in a query
|
|
152
|
+
</p>
|
|
153
|
+
<p>
|
|
154
|
+
The keys in the values hash are used to replace variables in a query The
|
|
155
|
+
values are supplied as is, allowing them to be provided as URIs, or typed
|
|
156
|
+
literals according to Turtle syntax.
|
|
157
|
+
</p>
|
|
158
|
+
<p>
|
|
159
|
+
Any keys in the hash that are not in the query are ignored. Any variables
|
|
160
|
+
not found in the hash remain unbound.
|
|
161
|
+
</p>
|
|
162
|
+
<pre>
|
|
163
|
+
query:: the query whose initial bindings are to be set
|
|
164
|
+
values:: hash of query name to value
|
|
165
|
+
</pre>
|
|
166
|
+
<p><a class="source-toggle" href="#"
|
|
167
|
+
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
|
168
|
+
<div class="method-source-code" id="M000011-source">
|
|
169
|
+
<pre>
|
|
170
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 159</span>
|
|
171
|
+
<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
|
+
<span class="ruby-identifier">copy</span> = <span class="ruby-identifier">query</span>.<span class="ruby-identifier">clone</span>()
|
|
173
|
+
<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>
|
|
174
|
+
<span class="ruby-identifier">key</span> = <span class="ruby-identifier">$2</span>
|
|
175
|
+
<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>)
|
|
176
|
+
<span class="ruby-identifier">bindings</span>[<span class="ruby-identifier">key</span>].<span class="ruby-identifier">to_s</span>
|
|
177
|
+
<span class="ruby-keyword kw">else</span>
|
|
178
|
+
<span class="ruby-identifier">pattern</span>
|
|
179
|
+
<span class="ruby-keyword kw">end</span>
|
|
180
|
+
<span class="ruby-keyword kw">end</span>
|
|
181
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">copy</span>
|
|
182
|
+
<span class="ruby-keyword kw">end</span>
|
|
183
|
+
</pre>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<div id="method-M000015" class="method-detail">
|
|
189
|
+
<a name="M000015"></a>
|
|
190
|
+
|
|
191
|
+
<div class="method-heading">
|
|
192
|
+
<a href="#M000015" class="method-signature">
|
|
193
|
+
<span class="method-name">ask</span><span class="method-args">(query, sparql_client)</span>
|
|
194
|
+
</a>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div class="method-description">
|
|
198
|
+
<p>
|
|
199
|
+
Performs an ASK query on an endpoint, returing a boolean true/false
|
|
200
|
+
response
|
|
201
|
+
</p>
|
|
202
|
+
<p>
|
|
203
|
+
Will request the results using the SPARQL JSON results format, parse the
|
|
204
|
+
resulting JSON results, and extract the true/false response.
|
|
205
|
+
</p>
|
|
206
|
+
<pre>
|
|
207
|
+
query:: the SPARQL SELECT query
|
|
208
|
+
sparql_client:: a configured SparqlClient object
|
|
209
|
+
</pre>
|
|
210
|
+
<p><a class="source-toggle" href="#"
|
|
211
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
|
212
|
+
<div class="method-source-code" id="M000015-source">
|
|
213
|
+
<pre>
|
|
214
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 242</span>
|
|
215
|
+
<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
|
+
<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
|
+
<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>
|
|
218
|
+
<span class="ruby-keyword kw">end</span>
|
|
219
|
+
</pre>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
<div id="method-M000018" class="method-detail">
|
|
225
|
+
<a name="M000018"></a>
|
|
226
|
+
|
|
227
|
+
<div class="method-heading">
|
|
228
|
+
<a href="#M000018" class="method-signature">
|
|
229
|
+
<span class="method-name">construct_to_resource_hash</span><span class="method-args">(query, sparql_client)</span>
|
|
230
|
+
</a>
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
<div class="method-description">
|
|
234
|
+
<p>
|
|
235
|
+
Perform a SPARQL CONSTRUCT query against an endpoint, requesting the
|
|
236
|
+
results in JSON
|
|
237
|
+
</p>
|
|
238
|
+
<p>
|
|
239
|
+
Will request the results as application/json (with the expectation that it
|
|
240
|
+
returns RDF_JSON), and parses the resulting JSON document.
|
|
241
|
+
</p>
|
|
242
|
+
<pre>
|
|
243
|
+
query:: the SPARQL SELECT query
|
|
244
|
+
sparql_client:: a configured SparqlClient object
|
|
245
|
+
</pre>
|
|
246
|
+
<p><a class="source-toggle" href="#"
|
|
247
|
+
onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
|
|
248
|
+
<div class="method-source-code" id="M000018-source">
|
|
249
|
+
<pre>
|
|
250
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 290</span>
|
|
251
|
+
<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
|
+
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
|
253
|
+
<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>)
|
|
254
|
+
<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>
|
|
255
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}"</span>
|
|
256
|
+
<span class="ruby-keyword kw">end</span>
|
|
257
|
+
<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> )
|
|
258
|
+
<span class="ruby-keyword kw">end</span>
|
|
259
|
+
</pre>
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
<div id="method-M000019" class="method-detail">
|
|
265
|
+
<a name="M000019"></a>
|
|
266
|
+
|
|
267
|
+
<div class="method-heading">
|
|
268
|
+
<a href="#M000019" class="method-signature">
|
|
269
|
+
<span class="method-name">describe_to_resource_hash</span><span class="method-args">(query, sparql_client)</span>
|
|
270
|
+
</a>
|
|
271
|
+
</div>
|
|
272
|
+
|
|
273
|
+
<div class="method-description">
|
|
274
|
+
<p>
|
|
275
|
+
Perform a SPARQL DESCRIBE query against an endpoint, requesting the results
|
|
276
|
+
in JSON
|
|
277
|
+
</p>
|
|
278
|
+
<p>
|
|
279
|
+
Will request the results as application/json (with the expectation that it
|
|
280
|
+
returns RDF_JSON), and parses the resulting JSON document.
|
|
281
|
+
</p>
|
|
282
|
+
<pre>
|
|
283
|
+
query:: the SPARQL SELECT query
|
|
284
|
+
sparql_client:: a configured SparqlClient object
|
|
285
|
+
</pre>
|
|
286
|
+
<p><a class="source-toggle" href="#"
|
|
287
|
+
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
|
288
|
+
<div class="method-source-code" id="M000019-source">
|
|
289
|
+
<pre>
|
|
290
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 306</span>
|
|
291
|
+
<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
|
+
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
|
293
|
+
<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>)
|
|
294
|
+
<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>
|
|
295
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}"</span>
|
|
296
|
+
<span class="ruby-keyword kw">end</span>
|
|
297
|
+
<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> )
|
|
298
|
+
<span class="ruby-keyword kw">end</span>
|
|
299
|
+
</pre>
|
|
300
|
+
</div>
|
|
301
|
+
</div>
|
|
302
|
+
</div>
|
|
303
|
+
|
|
304
|
+
<div id="method-M000020" class="method-detail">
|
|
305
|
+
<a name="M000020"></a>
|
|
306
|
+
|
|
307
|
+
<div class="method-heading">
|
|
308
|
+
<a href="#M000020" class="method-signature">
|
|
309
|
+
<span class="method-name">multi_describe</span><span class="method-args">(uris, sparql_client)</span>
|
|
310
|
+
</a>
|
|
311
|
+
</div>
|
|
312
|
+
|
|
313
|
+
<div class="method-description">
|
|
314
|
+
<p>
|
|
315
|
+
DESCRIBE multiple resources in a single SPARQL request
|
|
316
|
+
</p>
|
|
317
|
+
<pre>
|
|
318
|
+
uris:: an array of URIs
|
|
319
|
+
sparql_client:: a configured SparqlClient objec
|
|
320
|
+
</pre>
|
|
321
|
+
<p><a class="source-toggle" href="#"
|
|
322
|
+
onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
|
|
323
|
+
<div class="method-source-code" id="M000020-source">
|
|
324
|
+
<pre>
|
|
325
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 319</span>
|
|
326
|
+
<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
|
+
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
|
328
|
+
<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>)
|
|
329
|
+
<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>
|
|
330
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}"</span>
|
|
331
|
+
<span class="ruby-keyword kw">end</span>
|
|
332
|
+
<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> )
|
|
333
|
+
<span class="ruby-keyword kw">end</span>
|
|
334
|
+
</pre>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
|
|
339
|
+
<div id="method-M000012" class="method-detail">
|
|
340
|
+
<a name="M000012"></a>
|
|
341
|
+
|
|
342
|
+
<div class="method-heading">
|
|
343
|
+
<a href="#M000012" class="method-signature">
|
|
344
|
+
<span class="method-name">result_to_query_binding</span><span class="method-args">(result)</span>
|
|
345
|
+
</a>
|
|
346
|
+
</div>
|
|
347
|
+
|
|
348
|
+
<div class="method-description">
|
|
349
|
+
<p>
|
|
350
|
+
Convert a SPARQL query result binding into a hash suitable for passing to
|
|
351
|
+
the <a href="SparqlHelper.html#M000011">apply_initial_bindings</a> method.
|
|
352
|
+
</p>
|
|
353
|
+
<p>
|
|
354
|
+
The result param is assumed to be a Ruby hash that reflects the structure
|
|
355
|
+
of a binding in a SELECT query result (i.e. the result of parsing the
|
|
356
|
+
<tt>application/sparql-results+json</tt> format and extracting an specific
|
|
357
|
+
result binding.
|
|
358
|
+
</p>
|
|
359
|
+
<p>
|
|
360
|
+
The method is intended to be used to support cases where an initial <a
|
|
361
|
+
href="SparqlHelper.html#M000014">select</a> query is performed to extract
|
|
362
|
+
some variables that can later be plugged into a subsequent query
|
|
363
|
+
</p>
|
|
364
|
+
<pre>
|
|
365
|
+
result:: hash conforming to structure of a <tt>binding</tt> in the SPARQL JSON format
|
|
366
|
+
</pre>
|
|
367
|
+
<p><a class="source-toggle" href="#"
|
|
368
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
|
369
|
+
<div class="method-source-code" id="M000012-source">
|
|
370
|
+
<pre>
|
|
371
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 184</span>
|
|
372
|
+
<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
|
+
<span class="ruby-identifier">hash</span> = {}
|
|
374
|
+
<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>
|
|
375
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">"type"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"uri"</span>
|
|
376
|
+
<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-node">"<#{value["value"]}>"</span>
|
|
377
|
+
<span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">value</span>[<span class="ruby-value str">"type"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"literal"</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">"datatype"</span>))
|
|
378
|
+
<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-node">"\"#{value["value"]}\""</span>
|
|
379
|
+
<span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">value</span>[<span class="ruby-value str">"type"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"literal"</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">"datatype"</span>))
|
|
380
|
+
<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-node">"\"#{value["value"]}\"^^#{value["datatype"]}"</span>
|
|
381
|
+
<span class="ruby-keyword kw">else</span>
|
|
382
|
+
<span class="ruby-comment cmt">#do nothing for bnodes</span>
|
|
383
|
+
<span class="ruby-keyword kw">end</span>
|
|
384
|
+
<span class="ruby-keyword kw">end</span>
|
|
385
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">hash</span>
|
|
386
|
+
<span class="ruby-keyword kw">end</span>
|
|
387
|
+
</pre>
|
|
388
|
+
</div>
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
|
|
392
|
+
<div id="method-M000013" class="method-detail">
|
|
393
|
+
<a name="M000013"></a>
|
|
394
|
+
|
|
395
|
+
<div class="method-heading">
|
|
396
|
+
<a href="#M000013" class="method-signature">
|
|
397
|
+
<span class="method-name">results_to_query_bindings</span><span class="method-args">(results)</span>
|
|
398
|
+
</a>
|
|
399
|
+
</div>
|
|
400
|
+
|
|
401
|
+
<div class="method-description">
|
|
402
|
+
<p>
|
|
403
|
+
Convert Ruby hash structured according to SPARQL JSON format into an array
|
|
404
|
+
of hashes by calling <a
|
|
405
|
+
href="SparqlHelper.html#M000012">result_to_query_binding</a> on each
|
|
406
|
+
binding into the results.
|
|
407
|
+
</p>
|
|
408
|
+
<p>
|
|
409
|
+
E.g:
|
|
410
|
+
</p>
|
|
411
|
+
<pre>
|
|
412
|
+
<tt>results = Pho::Sparql::SparqlHelper.select(query, sparql_client)</tt>
|
|
413
|
+
<tt>bindings = Pho::Sparql::SparqlHelper.results_to_query_bindings(results)</tt>
|
|
414
|
+
|
|
415
|
+
results:: hash conforming to SPARQL SELECT structure
|
|
416
|
+
</pre>
|
|
417
|
+
<p><a class="source-toggle" href="#"
|
|
418
|
+
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
|
419
|
+
<div class="method-source-code" id="M000013-source">
|
|
420
|
+
<pre>
|
|
421
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 209</span>
|
|
422
|
+
<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
|
+
<span class="ruby-identifier">bindings</span> = []
|
|
424
|
+
|
|
425
|
+
<span class="ruby-identifier">results</span>[<span class="ruby-value str">"results"</span>][<span class="ruby-value str">"bindings"</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>
|
|
426
|
+
<span class="ruby-identifier">bindings</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">result_to_query_binding</span>(<span class="ruby-identifier">result</span>)
|
|
427
|
+
<span class="ruby-keyword kw">end</span>
|
|
428
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">bindings</span>
|
|
429
|
+
<span class="ruby-keyword kw">end</span>
|
|
430
|
+
</pre>
|
|
431
|
+
</div>
|
|
432
|
+
</div>
|
|
433
|
+
</div>
|
|
434
|
+
|
|
435
|
+
<div id="method-M000014" class="method-detail">
|
|
436
|
+
<a name="M000014"></a>
|
|
437
|
+
|
|
438
|
+
<div class="method-heading">
|
|
439
|
+
<a href="#M000014" class="method-signature">
|
|
440
|
+
<span class="method-name">select</span><span class="method-args">(query, sparql_client)</span>
|
|
441
|
+
</a>
|
|
442
|
+
</div>
|
|
443
|
+
|
|
444
|
+
<div class="method-description">
|
|
445
|
+
<p>
|
|
446
|
+
Perform a simple SELECT query on an endpoint. Will request the results
|
|
447
|
+
using the SPARQL JSON results format, and parse the resulting JSON results.
|
|
448
|
+
The result will therefore be a simple ruby hash of the results
|
|
449
|
+
</p>
|
|
450
|
+
<p>
|
|
451
|
+
An error will be raised if the response is HTTP OK.
|
|
452
|
+
</p>
|
|
453
|
+
<pre>
|
|
454
|
+
query:: the SPARQL SELECT query
|
|
455
|
+
sparql_client:: a configured SparqlClient object
|
|
456
|
+
</pre>
|
|
457
|
+
<p><a class="source-toggle" href="#"
|
|
458
|
+
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
|
459
|
+
<div class="method-source-code" id="M000014-source">
|
|
460
|
+
<pre>
|
|
461
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 226</span>
|
|
462
|
+
<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
|
+
<span class="ruby-comment cmt">#TODO: test whether endpoint supports json, and if not, switch to parsing XML</span>
|
|
464
|
+
<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>)
|
|
465
|
+
<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>
|
|
466
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"Error performing sparql query: #{resp.status} #{resp.reason}\n#{resp.content}"</span>
|
|
467
|
+
<span class="ruby-keyword kw">end</span>
|
|
468
|
+
<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> )
|
|
469
|
+
<span class="ruby-keyword kw">end</span>
|
|
470
|
+
</pre>
|
|
471
|
+
</div>
|
|
472
|
+
</div>
|
|
473
|
+
</div>
|
|
474
|
+
|
|
475
|
+
<div id="method-M000017" class="method-detail">
|
|
476
|
+
<a name="M000017"></a>
|
|
477
|
+
|
|
478
|
+
<div class="method-heading">
|
|
479
|
+
<a href="#M000017" class="method-signature">
|
|
480
|
+
<span class="method-name">select_single_value</span><span class="method-args">(query, sparql_client)</span>
|
|
481
|
+
</a>
|
|
482
|
+
</div>
|
|
483
|
+
|
|
484
|
+
<div class="method-description">
|
|
485
|
+
<p>
|
|
486
|
+
Perform a simple SELECT query on an endpoint and return a single result
|
|
487
|
+
</p>
|
|
488
|
+
<p>
|
|
489
|
+
Will request the results using the SPARQL JSON results format, and parse
|
|
490
|
+
the resulting JSON results. The assumption is that the SELECT query returns
|
|
491
|
+
a single value (i.e single variable, with single binding)
|
|
492
|
+
</p>
|
|
493
|
+
<p>
|
|
494
|
+
Note this will lose any type information, only the value of the binding is
|
|
495
|
+
returned
|
|
496
|
+
</p>
|
|
497
|
+
<pre>
|
|
498
|
+
query:: the SPARQL SELECT query
|
|
499
|
+
sparql_client:: a configured SparqlClient object
|
|
500
|
+
</pre>
|
|
501
|
+
<p><a class="source-toggle" href="#"
|
|
502
|
+
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
|
503
|
+
<div class="method-source-code" id="M000017-source">
|
|
504
|
+
<pre>
|
|
505
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 277</span>
|
|
506
|
+
<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
|
+
<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
|
+
<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>];
|
|
509
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">results</span>[<span class="ruby-value str">"results"</span>][<span class="ruby-value str">"bindings"</span>][<span class="ruby-value">0</span>][<span class="ruby-identifier">v</span>][<span class="ruby-value str">"value"</span>]
|
|
510
|
+
<span class="ruby-keyword kw">end</span>
|
|
511
|
+
</pre>
|
|
512
|
+
</div>
|
|
513
|
+
</div>
|
|
514
|
+
</div>
|
|
515
|
+
|
|
516
|
+
<div id="method-M000016" class="method-detail">
|
|
517
|
+
<a name="M000016"></a>
|
|
518
|
+
|
|
519
|
+
<div class="method-heading">
|
|
520
|
+
<a href="#M000016" class="method-signature">
|
|
521
|
+
<span class="method-name">select_values</span><span class="method-args">(query, sparql_client)</span>
|
|
522
|
+
</a>
|
|
523
|
+
</div>
|
|
524
|
+
|
|
525
|
+
<div class="method-description">
|
|
526
|
+
<p>
|
|
527
|
+
Perform a simple SELECT query on an endpoint and return a simple array of
|
|
528
|
+
values
|
|
529
|
+
</p>
|
|
530
|
+
<p>
|
|
531
|
+
Will request the results using the SPARQL JSON results format, and parse
|
|
532
|
+
the resulting JSON results. The assumption is that the SELECT query
|
|
533
|
+
contains a single "column" of values, which will be returned as
|
|
534
|
+
an array
|
|
535
|
+
</p>
|
|
536
|
+
<p>
|
|
537
|
+
Note this will lose any type information, only the value of the bindings
|
|
538
|
+
are returned
|
|
539
|
+
</p>
|
|
540
|
+
<pre>
|
|
541
|
+
query:: the SPARQL SELECT query
|
|
542
|
+
sparql_client:: a configured SparqlClient object
|
|
543
|
+
</pre>
|
|
544
|
+
<p><a class="source-toggle" href="#"
|
|
545
|
+
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
|
546
|
+
<div class="method-source-code" id="M000016-source">
|
|
547
|
+
<pre>
|
|
548
|
+
<span class="ruby-comment cmt"># File lib/pho/sparql.rb, line 257</span>
|
|
549
|
+
<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
|
+
<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
|
+
<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>];
|
|
552
|
+
<span class="ruby-identifier">values</span> = [];
|
|
553
|
+
<span class="ruby-identifier">results</span>[<span class="ruby-value str">"results"</span>][<span class="ruby-value str">"bindings"</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>
|
|
554
|
+
<span class="ruby-identifier">values</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">binding</span>[<span class="ruby-identifier">v</span>][<span class="ruby-value str">"value"</span>]
|
|
555
|
+
<span class="ruby-keyword kw">end</span>
|
|
556
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">values</span>
|
|
557
|
+
<span class="ruby-keyword kw">end</span>
|
|
558
|
+
</pre>
|
|
559
|
+
</div>
|
|
560
|
+
</div>
|
|
561
|
+
</div>
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
</div>
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
</div>
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
<div id="validator-badges">
|
|
571
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
572
|
+
</div>
|
|
573
|
+
|
|
574
|
+
</body>
|
|
575
|
+
</html>
|