kasabi 0.0.1

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.
@@ -0,0 +1,262 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'kasabi'
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
+ RESULTS_NO_BINDING = <<-EOL
42
+ {
43
+ "head": { "vars": [ "name" ] } ,
44
+
45
+ "results": {
46
+ "bindings": [
47
+ { } ,
48
+ { "name": { "type": "literal" , "value": "Apollo 11 SIVB" }
49
+ }
50
+ ]
51
+ }
52
+ }
53
+ EOL
54
+
55
+ ASK_RESULTS = <<-EOL
56
+ {
57
+ "head": {},
58
+ "boolean": "true"
59
+ }
60
+ EOL
61
+
62
+ RDF_JSON_RESULTS = <<-EOL
63
+ {
64
+ "http://www.example.org" : {
65
+ "http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ]
66
+ }
67
+ }
68
+ EOL
69
+
70
+ RDF_JSON = <<-EOL
71
+ {
72
+ "head": { "vars": [ "name" ] } ,
73
+
74
+ "results": {
75
+ "bindings": [
76
+ { "name": { "type": "literal" , "value": "Apollo 11 Command and Service Module (CSM)" },
77
+ "uri": { "type": "uri" , "value": "http://nasa.dataincubator.org/spacecraft/12345" },
78
+ "mass": { "type": "literal" , "value": "5000.5", "datatype" : "http://www.w3.org/2001/XMLSchema#float" }
79
+ } ,
80
+ { "name": { "type": "literal" , "value": "Apollo 11 SIVB" },
81
+ "uri": { "type": "uri" , "value": "http://nasa.dataincubator.org/spacecraft/12345" }
82
+ }
83
+ ]
84
+ }
85
+ }
86
+ EOL
87
+
88
+ def test_apply_initial_bindings
89
+ query = "SELECT ?p ?o WHERE { ?s ?p ?o }"
90
+ values = { "s" => "<http://www.example.org>" }
91
+
92
+ bound = Kasabi::Sparql::SparqlHelper.apply_initial_bindings(query, values)
93
+ assert_not_nil(bound)
94
+ assert_equal( "SELECT ?p ?o WHERE { <http://www.example.org> ?p ?o }", bound )
95
+ end
96
+
97
+ def test_apply_initial_bindings_with_dollars
98
+ query = "SELECT $p $o WHERE { $s $p $o }"
99
+ values = { "s" => "<http://www.example.org>" }
100
+
101
+ bound = Kasabi::Sparql::SparqlHelper.apply_initial_bindings(query, values)
102
+ assert_not_nil(bound)
103
+ assert_equal( "SELECT $p $o WHERE { <http://www.example.org> $p $o }", bound )
104
+ end
105
+
106
+ def test_apply_initial_bindings_with_literal
107
+ query = "SELECT ?s WHERE { ?s ?p ?o }"
108
+ values = { "o" => "'some value'" }
109
+
110
+ bound = Kasabi::Sparql::SparqlHelper.apply_initial_bindings(query, values)
111
+ assert_not_nil(bound)
112
+ assert_equal( "SELECT ?s WHERE { ?s ?p 'some value' }", bound )
113
+ end
114
+
115
+ def test_select
116
+ mc = mock()
117
+ mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
118
+ HTTP::Message.new_response(RESULTS) )
119
+ json = Kasabi::Sparql::SparqlHelper.select(SELECT_QUERY, mc)
120
+ assert_not_nil(json)
121
+ assert_equal("name", json["head"]["vars"][0])
122
+ end
123
+
124
+ def test_failed_select
125
+ mc = mock()
126
+ resp = HTTP::Message.new_response("Error")
127
+ resp.status = 500
128
+ mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns( resp )
129
+ assert_raises RuntimeError do
130
+ json = Kasabi::Sparql::SparqlHelper.select(SELECT_QUERY, mc)
131
+ end
132
+ end
133
+
134
+ def test_ask
135
+ mc = mock()
136
+ mc.expects(:select).with(ASK_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
137
+ HTTP::Message.new_response(ASK_RESULTS) )
138
+ assert_equal( true, Kasabi::Sparql::SparqlHelper.ask(ASK_QUERY, mc) )
139
+ end
140
+
141
+ def test_select_values
142
+ mc = mock()
143
+ mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
144
+ HTTP::Message.new_response(RESULTS) )
145
+ results = Kasabi::Sparql::SparqlHelper.select_values(SELECT_QUERY, mc)
146
+ assert_not_nil( results )
147
+ assert_equal( 3, results.length )
148
+ end
149
+
150
+ def test_select_values_with_empty_binding
151
+ mc = mock()
152
+ mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
153
+ HTTP::Message.new_response(RESULTS_NO_BINDING) )
154
+ results = Kasabi::Sparql::SparqlHelper.select_values(SELECT_QUERY, mc)
155
+ assert_not_nil( results )
156
+ assert_equal( 1 , results.length )
157
+ end
158
+
159
+ def test_select_single_value
160
+ mc = mock()
161
+ mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
162
+ HTTP::Message.new_response(RESULTS) )
163
+ result = Kasabi::Sparql::SparqlHelper.select_single_value(SELECT_QUERY, mc)
164
+ assert_equal( "Apollo 11 Command and Service Module (CSM)", result )
165
+ end
166
+
167
+ def test_describe_to_resource_hash
168
+ mc = mock()
169
+ mc.expects(:describe).with(DESCRIBE_QUERY, "application/json").returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
170
+ result = Kasabi::Sparql::SparqlHelper.describe_to_resource_hash(DESCRIBE_QUERY, mc)
171
+ assert_not_nil(result)
172
+ assert_not_nil(result["http://www.example.org"])
173
+ end
174
+
175
+ def test_failed_describe
176
+ mc = mock()
177
+ resp = HTTP::Message.new_response("Error")
178
+ resp.status = 500
179
+ mc.expects(:describe).with(DESCRIBE_QUERY, "application/json").returns( resp )
180
+ assert_raises RuntimeError do
181
+ Kasabi::Sparql::SparqlHelper.describe_to_resource_hash(DESCRIBE_QUERY, mc)
182
+ end
183
+ end
184
+
185
+ def test_construct_to_resource_hash
186
+ mc = mock()
187
+ mc.expects(:construct).with(CONSTRUCT_QUERY, "application/json").returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
188
+ result = Kasabi::Sparql::SparqlHelper.construct_to_resource_hash(CONSTRUCT_QUERY, mc)
189
+ assert_not_nil(result)
190
+ assert_not_nil(result["http://www.example.org"])
191
+ end
192
+
193
+ def test_failed_construct
194
+ mc = mock()
195
+ resp = HTTP::Message.new_response("Error")
196
+ resp.status = 500
197
+ mc.expects(:construct).with(CONSTRUCT_QUERY, "application/json").returns( resp )
198
+ assert_raises RuntimeError do
199
+ Kasabi::Sparql::SparqlHelper.construct_to_resource_hash(CONSTRUCT_QUERY, mc)
200
+ end
201
+ end
202
+
203
+ def test_multi_describe
204
+ uris = []
205
+ uris << "http://www.example.org"
206
+ uris << "http://www.example.com"
207
+ mc = mock()
208
+ mc.expects(:multi_describe).with(uris, "application/json").returns(
209
+ HTTP::Message.new_response(RDF_JSON_RESULTS) )
210
+
211
+ result = Kasabi::Sparql::SparqlHelper.multi_describe(uris, mc)
212
+ assert_not_nil(result)
213
+ assert_not_nil(result["http://www.example.org"])
214
+ end
215
+
216
+ def test_binding_to_hash
217
+ json = JSON.parse(RDF_JSON)
218
+ binding = json["results"]["bindings"][0]
219
+
220
+ hash = Kasabi::Sparql::SparqlHelper.result_to_query_binding(binding)
221
+ assert_equal(3, hash.size)
222
+ assert_equal("\"Apollo 11 Command and Service Module (CSM)\"", hash["name"])
223
+ assert_equal("<http://nasa.dataincubator.org/spacecraft/12345>", hash["uri"])
224
+ assert_equal("\"5000.5\"^^http://www.w3.org/2001/XMLSchema#float", hash["mass"])
225
+ end
226
+
227
+ def test_results_to_bindings
228
+ json = JSON.parse(RDF_JSON)
229
+ bindings = Kasabi::Sparql::SparqlHelper.results_to_query_bindings(json)
230
+ assert_equal(2, bindings.size)
231
+ hash = bindings[0]
232
+ assert_equal("\"Apollo 11 Command and Service Module (CSM)\"", hash["name"])
233
+ assert_equal("<http://nasa.dataincubator.org/spacecraft/12345>", hash["uri"])
234
+ assert_equal("\"5000.5\"^^http://www.w3.org/2001/XMLSchema#float", hash["mass"])
235
+ end
236
+
237
+ def test_describe_uri
238
+ mc = mock()
239
+ mc.expects(:describe_uri).with("http://www.example.org", "application/json", :cbd).returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
240
+ result = Kasabi::Sparql::SparqlHelper.describe_uri("http://www.example.org", mc)
241
+ assert_not_nil(result)
242
+ assert_not_nil(result["http://www.example.org"])
243
+ end
244
+
245
+ def test_describe_uri_with_type
246
+ mc = mock()
247
+ mc.expects(:describe_uri).with("http://www.example.org", "application/json", :slcbd).returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
248
+ result = Kasabi::Sparql::SparqlHelper.describe_uri("http://www.example.org", mc, :slcbd)
249
+ assert_not_nil(result)
250
+ assert_not_nil(result["http://www.example.org"])
251
+ end
252
+
253
+ def test_exists
254
+ mc = mock()
255
+ mc.expects(:select).with("ASK { <http://www.example.org> ?p ?o }", Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
256
+ HTTP::Message.new_response(ASK_RESULTS) )
257
+ result = Kasabi::Sparql::SparqlHelper.exists("http://www.example.org", mc)
258
+ assert_equal( true, result )
259
+
260
+ end
261
+
262
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test/unit'
3
+
4
+ require 'api/tc_lookup.rb'
5
+ require 'api/tc_sparql.rb'
6
+ require 'api/tc_facet.rb'
7
+ require 'api/tc_search.rb'
8
+ require 'api/tc_augment.rb'
9
+ require 'api/tc_reconcile.rb'
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kasabi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Leigh Dodds
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-13 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httpclient
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 105
30
+ segments:
31
+ - 2
32
+ - 1
33
+ - 3
34
+ - 1
35
+ version: 2.1.3.1
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: json
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 21
47
+ segments:
48
+ - 1
49
+ - 1
50
+ - 3
51
+ version: 1.1.3
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: mocha
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 49
63
+ segments:
64
+ - 0
65
+ - 9
66
+ - 5
67
+ version: 0.9.5
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: mime-types
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 47
79
+ segments:
80
+ - 1
81
+ - 16
82
+ version: "1.16"
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: linkeddata
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :runtime
98
+ version_requirements: *id005
99
+ description: Ruby Client for Kasabi
100
+ email: leigh@kasabi.com
101
+ executables: []
102
+
103
+ extensions: []
104
+
105
+ extra_rdoc_files:
106
+ - CHANGES
107
+ files:
108
+ - README.md
109
+ - Rakefile
110
+ - CHANGES
111
+ - tests/api/tc_sparql.rb
112
+ - tests/api/tc_augment.rb
113
+ - tests/api/tc_reconcile.rb
114
+ - tests/api/tc_facet.rb
115
+ - tests/api/tc_sparqlhelper.rb
116
+ - tests/api/tc_lookup.rb
117
+ - tests/api/tc_search.rb
118
+ - tests/ts_kasabi.rb
119
+ - lib/kasabi/dataset/dataset.rb
120
+ - lib/kasabi/api/sparql.rb
121
+ - lib/kasabi/api/lookup.rb
122
+ - lib/kasabi/api/reconcile.rb
123
+ - lib/kasabi/api/augment.rb
124
+ - lib/kasabi/api/facet.rb
125
+ - lib/kasabi/api/base_client.rb
126
+ - lib/kasabi/api/search.rb
127
+ - lib/kasabi.rb
128
+ has_rdoc: true
129
+ homepage: http://github.com/kasabi/kasabi.rb
130
+ licenses: []
131
+
132
+ post_install_message:
133
+ rdoc_options:
134
+ - --quiet
135
+ - --title
136
+ - Kasabi Ruby Client Documentation
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 61
145
+ segments:
146
+ - 1
147
+ - 8
148
+ - 5
149
+ version: 1.8.5
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project: kasabi
162
+ rubygems_version: 1.3.7
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Ruby Client for Kasabi
166
+ test_files:
167
+ - tests/ts_kasabi.rb