pho 0.4.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/tests/tc_rdf_collection.rb
CHANGED
@@ -3,6 +3,8 @@ require 'pho'
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'mocha'
|
5
5
|
|
6
|
+
#TODO factor out tests for AbstractFileManager
|
7
|
+
#TODO alter so we're testing the non-deprecated version of the Class
|
6
8
|
class RDFCollectionTest < Test::Unit::TestCase
|
7
9
|
|
8
10
|
def setup()
|
@@ -56,6 +58,7 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
56
58
|
|
57
59
|
success = collection.successes()
|
58
60
|
success.sort!
|
61
|
+
|
59
62
|
assert_equal(4, success.size)
|
60
63
|
assert_equal("/tmp/0.rdf", success[0])
|
61
64
|
assert_equal("/tmp/1.rdf", success[1])
|
@@ -5,7 +5,7 @@ require 'mocha'
|
|
5
5
|
require 'rexml/document'
|
6
6
|
require 'uri'
|
7
7
|
|
8
|
-
class
|
8
|
+
class ResourceHashTest < Test::Unit::TestCase
|
9
9
|
SINGLE_TRIPLE_RESOURCE = <<-EOL
|
10
10
|
{
|
11
11
|
"http://www.example.org" : {
|
@@ -99,7 +99,7 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
99
99
|
|
100
100
|
def test_minus_with_iso_graphs()
|
101
101
|
|
102
|
-
difference = Pho::
|
102
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE), JSON.parse(SINGLE_TRIPLE_RESOURCE) )
|
103
103
|
assert_not_nil(difference)
|
104
104
|
assert_equal(0, difference.keys.length)
|
105
105
|
|
@@ -107,7 +107,7 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
107
107
|
|
108
108
|
def test_minus_with_single_resource_value_change()
|
109
109
|
|
110
|
-
difference = Pho::
|
110
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE), JSON.parse(SINGLE_TRIPLE_RESOURCE2) )
|
111
111
|
assert_not_nil(difference)
|
112
112
|
assert_equal(1, difference.keys.length)
|
113
113
|
assert_equal( "http://www.example.org/page",
|
@@ -115,7 +115,7 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
115
115
|
|
116
116
|
#reverse
|
117
117
|
|
118
|
-
difference = Pho::
|
118
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE2), JSON.parse(SINGLE_TRIPLE_RESOURCE) )
|
119
119
|
assert_not_nil(difference)
|
120
120
|
assert_equal(1, difference.keys.length)
|
121
121
|
assert_equal( "http://www.example.org/other-page",
|
@@ -125,14 +125,14 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
125
125
|
|
126
126
|
def test_minus_with_single_literal_value_change()
|
127
127
|
|
128
|
-
difference = Pho::
|
128
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_LITERAL2) )
|
129
129
|
assert_not_nil(difference)
|
130
130
|
assert_equal(1, difference.keys.length)
|
131
131
|
assert_equal( "Title",
|
132
132
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
|
133
133
|
|
134
134
|
#reverse
|
135
|
-
difference = Pho::
|
135
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL2), JSON.parse(SINGLE_TRIPLE_LITERAL) )
|
136
136
|
assert_not_nil(difference)
|
137
137
|
assert_equal(1, difference.keys.length)
|
138
138
|
assert_equal( "Other Title",
|
@@ -142,14 +142,14 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
142
142
|
|
143
143
|
def test_minus_with_different_typed_predicate_values()
|
144
144
|
|
145
|
-
difference = Pho::
|
145
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_DIFF_TYPE) )
|
146
146
|
assert_not_nil(difference)
|
147
147
|
assert_equal(1, difference.keys.length)
|
148
148
|
assert_equal( "Title",
|
149
149
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
|
150
150
|
|
151
151
|
#reverse
|
152
|
-
difference = Pho::
|
152
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_DIFF_TYPE), JSON.parse(SINGLE_TRIPLE_LITERAL) )
|
153
153
|
assert_not_nil(difference)
|
154
154
|
assert_equal(1, difference.keys.length)
|
155
155
|
assert_equal( "http://www.example.com",
|
@@ -159,12 +159,12 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
159
159
|
|
160
160
|
def test_minus_with_different_size_graphs()
|
161
161
|
|
162
|
-
difference = Pho::
|
162
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE), JSON.parse(TWO_TRIPLES) )
|
163
163
|
assert_not_nil(difference)
|
164
164
|
assert_equal(0, difference.keys.length)
|
165
165
|
|
166
166
|
#reverse
|
167
|
-
difference = Pho::
|
167
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(TWO_TRIPLES), JSON.parse(SINGLE_TRIPLE_RESOURCE) )
|
168
168
|
assert_not_nil(difference)
|
169
169
|
assert_equal(1, difference.keys.length)
|
170
170
|
assert_equal( "Title",
|
@@ -174,12 +174,12 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
174
174
|
|
175
175
|
def test_minus_with_repeated_properties()
|
176
176
|
|
177
|
-
difference = Pho::
|
177
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(REPEATED_TRIPLES) )
|
178
178
|
assert_not_nil(difference)
|
179
179
|
assert_equal(0, difference.keys.length)
|
180
180
|
|
181
181
|
#reverse
|
182
|
-
difference = Pho::
|
182
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(REPEATED_TRIPLES), JSON.parse(SINGLE_TRIPLE_LITERAL) )
|
183
183
|
assert_not_nil(difference)
|
184
184
|
assert_equal(1, difference.keys.length)
|
185
185
|
assert_equal( "Other Title",
|
@@ -189,22 +189,22 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
189
189
|
|
190
190
|
def test_minus_with_language_qualified_literals()
|
191
191
|
|
192
|
-
difference = Pho::
|
192
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_LITERAL) )
|
193
193
|
assert_not_nil(difference)
|
194
194
|
assert_equal(0, difference.keys.length)
|
195
195
|
|
196
|
-
difference = Pho::
|
196
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH), JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH) )
|
197
197
|
assert_not_nil(difference)
|
198
198
|
assert_equal(0, difference.keys.length)
|
199
199
|
|
200
|
-
difference = Pho::
|
200
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH) )
|
201
201
|
assert_not_nil(difference)
|
202
202
|
assert_equal(1, difference.keys.length)
|
203
203
|
assert_equal( "Title",
|
204
204
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
|
205
205
|
|
206
206
|
#reverse no lang and english
|
207
|
-
difference = Pho::
|
207
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH), JSON.parse(SINGLE_TRIPLE_LITERAL) )
|
208
208
|
assert_not_nil(difference)
|
209
209
|
assert_equal(1, difference.keys.length)
|
210
210
|
assert_equal( "English",
|
@@ -212,7 +212,7 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
212
212
|
assert_equal( "en",
|
213
213
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["lang"] )
|
214
214
|
|
215
|
-
difference = Pho::
|
215
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH), JSON.parse(SINGLE_TRIPLE_LITERAL_FRENCH) )
|
216
216
|
assert_not_nil(difference)
|
217
217
|
assert_equal(1, difference.keys.length)
|
218
218
|
assert_equal( "English",
|
@@ -221,7 +221,7 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
221
221
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["lang"] )
|
222
222
|
|
223
223
|
#reverse no lang and english
|
224
|
-
difference = Pho::
|
224
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_FRENCH), JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH) )
|
225
225
|
assert_not_nil(difference)
|
226
226
|
assert_equal(1, difference.keys.length)
|
227
227
|
assert_equal( "French",
|
@@ -233,18 +233,18 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
233
233
|
|
234
234
|
def test_minus_with_typed_literals()
|
235
235
|
|
236
|
-
difference = Pho::
|
236
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_INT), JSON.parse(SINGLE_TYPED_TRIPLE_INT) )
|
237
237
|
assert_not_nil(difference)
|
238
238
|
assert_equal(0, difference.keys.length)
|
239
239
|
|
240
|
-
difference = Pho::
|
240
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TYPED_TRIPLE_INT) )
|
241
241
|
assert_not_nil(difference)
|
242
242
|
assert_equal(1, difference.keys.length)
|
243
243
|
assert_equal( "Title",
|
244
244
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
|
245
245
|
|
246
246
|
#reverse no type and int
|
247
|
-
difference = Pho::
|
247
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_INT), JSON.parse(SINGLE_TRIPLE_LITERAL) )
|
248
248
|
assert_not_nil(difference)
|
249
249
|
assert_equal(1, difference.keys.length)
|
250
250
|
assert_equal( "1",
|
@@ -252,7 +252,7 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
252
252
|
assert_equal( "http://www.w3.org/2001/XMLSchema#int",
|
253
253
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["datatype"] )
|
254
254
|
|
255
|
-
difference = Pho::
|
255
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_INT), JSON.parse(SINGLE_TYPED_TRIPLE_FLOAT) )
|
256
256
|
assert_not_nil(difference)
|
257
257
|
assert_equal(1, difference.keys.length)
|
258
258
|
assert_equal( "1",
|
@@ -261,7 +261,7 @@ class RDFJSONTest < Test::Unit::TestCase
|
|
261
261
|
difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["datatype"] )
|
262
262
|
|
263
263
|
#reverse float and int
|
264
|
-
difference = Pho::
|
264
|
+
difference = Pho::ResourceHash::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_FLOAT), JSON.parse(SINGLE_TYPED_TRIPLE_INT) )
|
265
265
|
assert_not_nil(difference)
|
266
266
|
assert_equal(1, difference.keys.length)
|
267
267
|
assert_equal( "2.5",
|
data/tests/tc_search.rb
CHANGED
@@ -45,7 +45,7 @@ class SearchTest < Test::Unit::TestCase
|
|
45
45
|
def test_augment
|
46
46
|
mc = mock()
|
47
47
|
mc.expects(:set_auth)
|
48
|
-
|
48
|
+
mc.expects(:post).with("http://api.talis.com/stores/testing/services/augment", "data", anything)
|
49
49
|
|
50
50
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
51
51
|
response = store.augment("data")
|
data/tests/tc_sparql.rb
CHANGED
@@ -5,7 +5,7 @@ require 'mocha'
|
|
5
5
|
|
6
6
|
class SparqlTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
def
|
8
|
+
def test_simple_store_sparql
|
9
9
|
|
10
10
|
mc = mock()
|
11
11
|
mc.expects(:set_auth)
|
@@ -29,7 +29,7 @@ class SparqlTest < Test::Unit::TestCase
|
|
29
29
|
assert_equal("RESULTS", response.content)
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def test_store_sparql_with_mimetype
|
33
33
|
|
34
34
|
mc = mock()
|
35
35
|
mc.expects(:set_auth)
|
@@ -41,7 +41,7 @@ class SparqlTest < Test::Unit::TestCase
|
|
41
41
|
assert_equal("RESULTS", response.content)
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def test_store_sparql_ask
|
45
45
|
mc = mock()
|
46
46
|
mc.expects(:set_auth)
|
47
47
|
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/sparql-results+xml"} ).returns(
|
@@ -52,7 +52,7 @@ class SparqlTest < Test::Unit::TestCase
|
|
52
52
|
assert_equal("RESULTS", response.content)
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
55
|
+
def test_store_sparql_select
|
56
56
|
mc = mock()
|
57
57
|
mc.expects(:set_auth)
|
58
58
|
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/sparql-results+xml"} ).returns(
|
@@ -63,7 +63,7 @@ class SparqlTest < Test::Unit::TestCase
|
|
63
63
|
assert_equal("RESULTS", response.content)
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def test_store_sparql_construct
|
67
67
|
mc = mock()
|
68
68
|
mc.expects(:set_auth)
|
69
69
|
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/rdf+xml"} ).returns(
|
@@ -74,7 +74,7 @@ class SparqlTest < Test::Unit::TestCase
|
|
74
74
|
assert_equal("RESULTS", response.content)
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
77
|
+
def test_store_sparql_describe
|
78
78
|
mc = mock()
|
79
79
|
mc.expects(:set_auth)
|
80
80
|
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/rdf+xml"} ).returns(
|
@@ -84,5 +84,130 @@ class SparqlTest < Test::Unit::TestCase
|
|
84
84
|
response = store.sparql_describe("SPARQL")
|
85
85
|
assert_equal("RESULTS", response.content)
|
86
86
|
end
|
87
|
+
|
88
|
+
def test_get_store_sparql_client
|
89
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing/", "user", "pass")
|
90
|
+
sparql_client = store.sparql_client()
|
91
|
+
assert_equal( true, sparql_client.supports_rdf_json )
|
92
|
+
assert_equal( true, sparql_client.supports_sparql_json )
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_simple_query
|
96
|
+
|
97
|
+
mc = mock()
|
98
|
+
mc.expects(:get).with("http://www.example.org/sparql", {"query" => "SPARQL"}, {})
|
99
|
+
|
100
|
+
sparql_client = Pho::Sparql::SparqlClient.new("http://www.example.org/sparql", mc)
|
101
|
+
sparql_client.query("SPARQL")
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_query_with_default_graph
|
106
|
+
|
107
|
+
mc = mock()
|
108
|
+
mc.expects(:get).with("http://www.example.org/sparql", {"query" => "SPARQL", "default-graph-uri" => ["http://www.example.com"]}, {})
|
109
|
+
|
110
|
+
sparql_client = Pho::Sparql::SparqlClient.new("http://www.example.org/sparql", mc)
|
111
|
+
sparql_client.add_default_graph("http://www.example.com")
|
112
|
+
sparql_client.query("SPARQL")
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_query_with_named_graph
|
117
|
+
|
118
|
+
mc = mock()
|
119
|
+
mc.expects(:get).with("http://www.example.org/sparql", {"query" => "SPARQL", "named-graph-uri" => ["http://www.example.com"]}, {})
|
120
|
+
|
121
|
+
sparql_client = Pho::Sparql::SparqlClient.new("http://www.example.org/sparql", mc)
|
122
|
+
sparql_client.add_named_graph("http://www.example.com")
|
123
|
+
sparql_client.query("SPARQL")
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_query_with_both_graphs
|
128
|
+
|
129
|
+
mc = mock()
|
130
|
+
mc.expects(:get).with("http://www.example.org/sparql", {"query" => "SPARQL", "named-graph-uri" => ["http://www.example.com"], "default-graph-uri" => ["http://www.example.org"]}, {})
|
131
|
+
|
132
|
+
sparql_client = Pho::Sparql::SparqlClient.new("http://www.example.org/sparql", mc)
|
133
|
+
sparql_client.add_named_graph("http://www.example.com")
|
134
|
+
sparql_client.add_default_graph("http://www.example.org")
|
135
|
+
sparql_client.query("SPARQL")
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_sparql_with_mimetype
|
140
|
+
mc = mock()
|
141
|
+
mc.expects(:get).with("http://www.example.org/sparql", {"query" => "SPARQL"}, {"Accept" => "application/sparql-results+xml"})
|
142
|
+
|
143
|
+
sparql_client = Pho::Sparql::SparqlClient.new("http://www.example.org/sparql", mc)
|
144
|
+
sparql_client.query("SPARQL", "application/sparql-results+xml")
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_sparql_with_output_parameter
|
149
|
+
mc = mock()
|
150
|
+
mc.expects(:get).with("http://www.example.org/sparql", {"query" => "SPARQL", "output" => "json"}, {})
|
151
|
+
|
152
|
+
sparql_client = Pho::Sparql::SparqlClient.new("http://www.example.org/sparql", mc)
|
153
|
+
sparql_client.output_parameter_name="output"
|
154
|
+
sparql_client.query("SPARQL", "json")
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_ask
|
159
|
+
mc = mock()
|
160
|
+
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/sparql-results+xml"} ).returns(
|
161
|
+
HTTP::Message.new_response("RESULTS"))
|
162
|
+
|
163
|
+
client = Pho::Sparql::SparqlClient.new("http://api.talis.com/stores/testing/services/sparql", mc)
|
164
|
+
response = client.ask("SPARQL")
|
165
|
+
assert_equal("RESULTS", response.content)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_store_sparql_select
|
169
|
+
mc = mock()
|
170
|
+
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/sparql-results+xml"} ).returns(
|
171
|
+
HTTP::Message.new_response("RESULTS"))
|
172
|
+
|
173
|
+
client = Pho::Sparql::SparqlClient.new("http://api.talis.com/stores/testing/services/sparql", mc)
|
174
|
+
response = client.select("SPARQL")
|
175
|
+
assert_equal("RESULTS", response.content)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_construct
|
179
|
+
mc = mock()
|
180
|
+
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/rdf+xml"} ).returns(
|
181
|
+
HTTP::Message.new_response("RESULTS"))
|
182
|
+
|
183
|
+
client = Pho::Sparql::SparqlClient.new("http://api.talis.com/stores/testing/services/sparql", mc)
|
184
|
+
response = client.construct("SPARQL")
|
185
|
+
assert_equal("RESULTS", response.content)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_describe
|
189
|
+
mc = mock()
|
190
|
+
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql", {"query" => "SPARQL"}, {"Accept" => "application/rdf+xml"} ).returns(
|
191
|
+
HTTP::Message.new_response("RESULTS"))
|
192
|
+
|
193
|
+
client = Pho::Sparql::SparqlClient.new("http://api.talis.com/stores/testing/services/sparql", mc)
|
194
|
+
response = client.describe("SPARQL")
|
195
|
+
assert_equal("RESULTS", response.content)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_multi_describe
|
199
|
+
mc = mock()
|
200
|
+
mc.expects(:get).with("http://api.talis.com/stores/testing/services/sparql",
|
201
|
+
{"query" => "DESCRIBE <http://www.example.org> <http://www.example.com>"},
|
202
|
+
{"Accept" => "application/rdf+xml"} ).returns( HTTP::Message.new_response("RESULTS"))
|
203
|
+
|
204
|
+
client = Pho::Sparql::SparqlClient.new("http://api.talis.com/stores/testing/services/sparql", mc)
|
205
|
+
uris = []
|
206
|
+
uris << "http://www.example.org"
|
207
|
+
uris << "http://www.example.com"
|
208
|
+
response = client.multi_describe(uris)
|
209
|
+
assert_equal("RESULTS", response.content)
|
210
|
+
|
211
|
+
end
|
87
212
|
|
88
213
|
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'pho'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class SparqlHelperTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
SELECT_QUERY = <<-EOL
|
9
|
+
SELECT ?name WHERE { ?s rdfs:label ?name. }
|
10
|
+
EOL
|
11
|
+
|
12
|
+
ASK_QUERY = <<-EOL
|
13
|
+
ASK WHERE { ?s rdfs:label "Something". }
|
14
|
+
EOL
|
15
|
+
|
16
|
+
DESCRIBE_QUERY = <<-EOL
|
17
|
+
DESCRIBE <http://www.example.org>
|
18
|
+
EOL
|
19
|
+
|
20
|
+
CONSTRUCT_QUERY = <<-EOL
|
21
|
+
CONSTRUCT { ?s ?p ?o. } WHERE { ?s ?p ?o. }
|
22
|
+
EOL
|
23
|
+
|
24
|
+
RESULTS = <<-EOL
|
25
|
+
{
|
26
|
+
"head": { "vars": [ "name" ] } ,
|
27
|
+
|
28
|
+
"results": {
|
29
|
+
"bindings": [
|
30
|
+
{ "name": { "type": "literal" , "value": "Apollo 11 Command and Service Module (CSM)" }
|
31
|
+
} ,
|
32
|
+
{ "name": { "type": "literal" , "value": "Apollo 11 SIVB" }
|
33
|
+
} ,
|
34
|
+
{ "name": { "type": "literal" , "value": "Apollo 11 Lunar Module / EASEP" }
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
}
|
39
|
+
EOL
|
40
|
+
|
41
|
+
ASK_RESULTS = <<-EOL
|
42
|
+
{
|
43
|
+
"head": {},
|
44
|
+
"boolean": "true"
|
45
|
+
}
|
46
|
+
EOL
|
47
|
+
|
48
|
+
RDF_JSON_RESULTS = <<-EOL
|
49
|
+
{
|
50
|
+
"http://www.example.org" : {
|
51
|
+
"http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
EOL
|
55
|
+
|
56
|
+
RDF_JSON = <<-EOL
|
57
|
+
{
|
58
|
+
"head": { "vars": [ "name" ] } ,
|
59
|
+
|
60
|
+
"results": {
|
61
|
+
"bindings": [
|
62
|
+
{ "name": { "type": "literal" , "value": "Apollo 11 Command and Service Module (CSM)" },
|
63
|
+
"uri": { "type": "uri" , "value": "http://nasa.dataincubator.org/spacecraft/12345" },
|
64
|
+
"mass": { "type": "literal" , "value": "5000.5", "datatype" : "http://www.w3.org/2001/XMLSchema#float" }
|
65
|
+
} ,
|
66
|
+
{ "name": { "type": "literal" , "value": "Apollo 11 SIVB" },
|
67
|
+
"uri": { "type": "uri" , "value": "http://nasa.dataincubator.org/spacecraft/12345" }
|
68
|
+
}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
}
|
72
|
+
EOL
|
73
|
+
|
74
|
+
def test_apply_initial_bindings
|
75
|
+
query = "SELECT ?p ?o WHERE { ?s ?p ?o }"
|
76
|
+
values = { "s" => "<http://www.example.org>" }
|
77
|
+
|
78
|
+
bound = Pho::Sparql::SparqlHelper.apply_initial_bindings(query, values)
|
79
|
+
assert_not_nil(bound)
|
80
|
+
assert_equal( "SELECT ?p ?o WHERE { <http://www.example.org> ?p ?o }", bound )
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_apply_initial_bindings_with_dollars
|
84
|
+
query = "SELECT $p $o WHERE { $s $p $o }"
|
85
|
+
values = { "s" => "<http://www.example.org>" }
|
86
|
+
|
87
|
+
bound = Pho::Sparql::SparqlHelper.apply_initial_bindings(query, values)
|
88
|
+
assert_not_nil(bound)
|
89
|
+
assert_equal( "SELECT $p $o WHERE { <http://www.example.org> $p $o }", bound )
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_apply_initial_bindings_with_literal
|
93
|
+
query = "SELECT ?s WHERE { ?s ?p ?o }"
|
94
|
+
values = { "o" => "'some value'" }
|
95
|
+
|
96
|
+
bound = Pho::Sparql::SparqlHelper.apply_initial_bindings(query, values)
|
97
|
+
assert_not_nil(bound)
|
98
|
+
assert_equal( "SELECT ?s WHERE { ?s ?p 'some value' }", bound )
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_select
|
102
|
+
mc = mock()
|
103
|
+
mc.expects(:select).with(SELECT_QUERY, Pho::Sparql::SPARQL_RESULTS_JSON).returns(
|
104
|
+
HTTP::Message.new_response(RESULTS) )
|
105
|
+
json = Pho::Sparql::SparqlHelper.select(SELECT_QUERY, mc)
|
106
|
+
assert_not_nil(json)
|
107
|
+
assert_equal("name", json["head"]["vars"][0])
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_failed_select
|
111
|
+
mc = mock()
|
112
|
+
resp = HTTP::Message.new_response("Error")
|
113
|
+
resp.status = 500
|
114
|
+
mc.expects(:select).with(SELECT_QUERY, Pho::Sparql::SPARQL_RESULTS_JSON).returns( resp )
|
115
|
+
assert_raises RuntimeError do
|
116
|
+
json = Pho::Sparql::SparqlHelper.select(SELECT_QUERY, mc)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_ask
|
121
|
+
mc = mock()
|
122
|
+
mc.expects(:select).with(ASK_QUERY, Pho::Sparql::SPARQL_RESULTS_JSON).returns(
|
123
|
+
HTTP::Message.new_response(ASK_RESULTS) )
|
124
|
+
assert_equal( true, Pho::Sparql::SparqlHelper.ask(ASK_QUERY, mc) )
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_select_values
|
128
|
+
mc = mock()
|
129
|
+
mc.expects(:select).with(SELECT_QUERY, Pho::Sparql::SPARQL_RESULTS_JSON).returns(
|
130
|
+
HTTP::Message.new_response(RESULTS) )
|
131
|
+
results = Pho::Sparql::SparqlHelper.select_values(SELECT_QUERY, mc)
|
132
|
+
assert_not_nil( results )
|
133
|
+
assert_equal( 3, results.length )
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_select_single_value
|
137
|
+
mc = mock()
|
138
|
+
mc.expects(:select).with(SELECT_QUERY, Pho::Sparql::SPARQL_RESULTS_JSON).returns(
|
139
|
+
HTTP::Message.new_response(RESULTS) )
|
140
|
+
result = Pho::Sparql::SparqlHelper.select_single_value(SELECT_QUERY, mc)
|
141
|
+
assert_equal( "Apollo 11 Command and Service Module (CSM)", result )
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_describe_to_resource_hash
|
145
|
+
mc = mock()
|
146
|
+
mc.expects(:describe).with(DESCRIBE_QUERY, "application/json").returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
147
|
+
result = Pho::Sparql::SparqlHelper.describe_to_resource_hash(DESCRIBE_QUERY, mc)
|
148
|
+
assert_not_nil(result)
|
149
|
+
assert_not_nil(result["http://www.example.org"])
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_failed_describe
|
153
|
+
mc = mock()
|
154
|
+
resp = HTTP::Message.new_response("Error")
|
155
|
+
resp.status = 500
|
156
|
+
mc.expects(:describe).with(DESCRIBE_QUERY, "application/json").returns( resp )
|
157
|
+
assert_raises RuntimeError do
|
158
|
+
Pho::Sparql::SparqlHelper.describe_to_resource_hash(DESCRIBE_QUERY, mc)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_construct_to_resource_hash
|
163
|
+
mc = mock()
|
164
|
+
mc.expects(:construct).with(CONSTRUCT_QUERY, "application/json").returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
165
|
+
result = Pho::Sparql::SparqlHelper.construct_to_resource_hash(CONSTRUCT_QUERY, mc)
|
166
|
+
assert_not_nil(result)
|
167
|
+
assert_not_nil(result["http://www.example.org"])
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_failed_construct
|
171
|
+
mc = mock()
|
172
|
+
resp = HTTP::Message.new_response("Error")
|
173
|
+
resp.status = 500
|
174
|
+
mc.expects(:construct).with(CONSTRUCT_QUERY, "application/json").returns( resp )
|
175
|
+
assert_raises RuntimeError do
|
176
|
+
Pho::Sparql::SparqlHelper.construct_to_resource_hash(CONSTRUCT_QUERY, mc)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_multi_describe
|
181
|
+
uris = []
|
182
|
+
uris << "http://www.example.org"
|
183
|
+
uris << "http://www.example.com"
|
184
|
+
mc = mock()
|
185
|
+
mc.expects(:multi_describe).with(uris, "application/json").returns(
|
186
|
+
HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
187
|
+
|
188
|
+
result = Pho::Sparql::SparqlHelper.multi_describe(uris, mc)
|
189
|
+
assert_not_nil(result)
|
190
|
+
assert_not_nil(result["http://www.example.org"])
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_binding_to_hash
|
194
|
+
json = JSON.parse(RDF_JSON)
|
195
|
+
binding = json["results"]["bindings"][0]
|
196
|
+
|
197
|
+
hash = Pho::Sparql::SparqlHelper.result_to_query_binding(binding)
|
198
|
+
assert_equal(3, hash.size)
|
199
|
+
assert_equal("\"Apollo 11 Command and Service Module (CSM)\"", hash["name"])
|
200
|
+
assert_equal("<http://nasa.dataincubator.org/spacecraft/12345>", hash["uri"])
|
201
|
+
assert_equal("\"5000.5\"^^http://www.w3.org/2001/XMLSchema#float", hash["mass"])
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_results_to_bindings
|
205
|
+
json = JSON.parse(RDF_JSON)
|
206
|
+
bindings = Pho::Sparql::SparqlHelper.results_to_query_bindings(json)
|
207
|
+
assert_equal(2, bindings.size)
|
208
|
+
hash = bindings[0]
|
209
|
+
assert_equal("\"Apollo 11 Command and Service Module (CSM)\"", hash["name"])
|
210
|
+
assert_equal("<http://nasa.dataincubator.org/spacecraft/12345>", hash["uri"])
|
211
|
+
assert_equal("\"5000.5\"^^http://www.w3.org/2001/XMLSchema#float", hash["mass"])
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|