rdf-virtuoso 0.1.2 → 0.1.7

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.
@@ -1,48 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
- require_relative '../lib/rdf/virtuoso/prefixes'
3
-
4
- describe RDF::Virtuoso::Prefixes do
5
- subject { RDF::Virtuoso::Prefixes.new(foo: 'bar', baz: 'quux') }
6
-
7
- it "takes a hash when initialized" do
8
- subject.should be_a RDF::Virtuoso::Prefixes
9
- end
10
-
11
- it "responds to to_a" do
12
- subject.should respond_to :to_a
13
- end
14
-
15
- it "returns a nice array" do
16
- subject.to_a.should == ["foo: <bar>", "baz: <quux>"]
17
- end
18
-
19
- it "presents itself nicely" do
20
- subject.to_s.should == "{:foo=>\"bar\", :baz=>\"quux\"}"
21
- end
22
-
23
- context "when creating prefixes" do
24
- let(:uris) { [RDF::DC.title.to_s, "http://example.org/foo/bar", "http://hash.org/foo#bar"] }
25
-
26
- it "creates prefixes from uris" do
27
- RDF::Virtuoso::Prefixes.parse(uris).should == [
28
- "purl: <http://purl.org/dc/terms/>",
29
- "example: <http://example.org/foo/>",
30
- "hash: <http://hash.org/foo#>"
31
- ]
32
- end
33
-
34
- it "only creates unique prefixes from uris" do
35
- uris << 'http://example.org/foo/baz'
36
- RDF::Virtuoso::Prefixes.parse(uris).should == [
37
- "purl: <http://purl.org/dc/terms/>",
38
- "example: <http://example.org/foo/>",
39
- "hash: <http://hash.org/foo#>"
40
- ]
41
- end
42
-
43
- it "returns an error object if a disallowed param is sent" do
44
- RDF::Virtuoso::Prefixes.parse({}).should be_a RDF::Virtuoso::UnProcessable
45
- end
46
-
47
- end
48
- end
@@ -1,377 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe RDF::Virtuoso::Query do
4
- before :each do
5
- @query = RDF::Virtuoso::Query
6
- end
7
-
8
- context "when building queries" do
9
- it "should support ASK queries" do
10
- @query.should respond_to(:ask)
11
- end
12
-
13
- it "should support SELECT queries" do
14
- @query.should respond_to(:select)
15
- end
16
-
17
- it "should support DESCRIBE queries" do
18
- @query.should respond_to(:describe)
19
- end
20
-
21
- it "should support CONSTRUCT queries" do
22
- @query.should respond_to(:construct)
23
- end
24
-
25
- it "should support INSERT DATA queries" do
26
- @query.should respond_to(:insert_data)
27
- end
28
-
29
- it "should support INSERT WHERE queries" do
30
- @query.should respond_to(:insert)
31
- end
32
-
33
- it "should support DELETE DATA queries" do
34
- @query.should respond_to(:delete_data)
35
- end
36
-
37
- it "should support DELETE WHERE queries" do
38
- @query.should respond_to(:delete)
39
- end
40
-
41
- it "should support CREATE GRAPH queries" do
42
- @query.should respond_to(:create)
43
- end
44
-
45
- end
46
-
47
- context "when building update queries" do
48
- before :each do
49
- @graph = "http://example.org/"
50
- @uri = RDF::Vocabulary.new "http://example.org/"
51
- end
52
- # TODO add support for advanced inserts (moving copying between different graphs)
53
- it "should support INSERT DATA queries" do
54
- @query.insert_data([@uri.ola, @uri.type, @uri.something]).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . }"
55
- @query.insert_data([@uri.ola, @uri.name, "two words"]).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <#{@graph}ola> <#{@graph}name> \"two words\" . }"
56
- end
57
-
58
- it "should support INSERT DATA queries with arrays" do
59
- @query.insert_data([@uri.ola, @uri.type, @uri.something],[@uri.ola, @uri.type, @uri.something_else]).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . <#{@graph}ola> <#{@graph}type> <#{@graph}something_else> . }"
60
- end
61
-
62
- it "should support INSERT DATA queries with RDF::Statements" do
63
- statements = [RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type')), RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type2'))]
64
- @query.insert_data(statements).graph(RDF::URI.new(@graph)).to_s.should == "INSERT DATA INTO GRAPH <#{@graph}> { <http://test> <#{RDF.type}> <http://type> .\n <http://test> <#{RDF.type}> <http://type2> .\n }"
65
- end
66
-
67
- it "should support INSERT WHERE queries with symbols and patterns" do
68
- @query.insert([:s, :p, :o]).graph(RDF::URI.new(@graph)).where([:s, :p, :o]).to_s.should == "INSERT INTO GRAPH <#{@graph}> { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
69
- @query.insert([:s, @uri.newtype, :o]).graph(RDF::URI.new(@graph)).where([:s, @uri.type, :o]).to_s.should == "INSERT INTO GRAPH <#{@graph}> { ?s <#{@graph}newtype> ?o . } WHERE { ?s <#{@graph}type> ?o . }"
70
- end
71
-
72
- it "should support DELETE DATA queries" do
73
- @query.delete_data([@uri.ola, @uri.type, @uri.something]).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . }"
74
- @query.delete_data([@uri.ola, @uri.name, RDF::Literal.new("myname")]).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <#{@graph}ola> <#{@graph}name> \"myname\" . }"
75
- end
76
-
77
- it "should support DELETE DATA queries with arrays" do
78
- @query.delete_data([@uri.ola, @uri.type, @uri.something],[@uri.ola, @uri.type, @uri.something_else]).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <#{@graph}ola> <#{@graph}type> <#{@graph}something> . <#{@graph}ola> <#{@graph}type> <#{@graph}something_else> . }"
79
- end
80
-
81
- it "should support DELETE DATA queries with RDF::Statements" do
82
- statements = [RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type')), RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type2'))]
83
- @query.delete_data(statements).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <http://test> <#{RDF.type}> <http://type> .\n <http://test> <#{RDF.type}> <http://type2> .\n }"
84
- end
85
-
86
- it "should support DELETE DATA queries with appendable objects" do
87
- statements = []
88
- statements << RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type'))
89
- statements << RDF::Statement.new(RDF::URI('http://test'), RDF.type, RDF::URI('http://type2'))
90
- @query.delete_data(statements).graph(RDF::URI.new(@graph)).to_s.should == "DELETE DATA FROM <#{@graph}> { <http://test> <#{RDF.type}> <http://type> .\n <http://test> <#{RDF.type}> <http://type2> .\n }"
91
- end
92
-
93
- it "should support DELETE WHERE queries with symbols and patterns" do
94
- @query.delete([:s, :p, :o]).graph(RDF::URI.new(@graph)).where([:s, :p, :o]).to_s.should == "DELETE FROM <#{@graph}> { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
95
- @query.delete([:s, @uri.newtype, :o]).graph(RDF::URI.new(@graph)).where([:s, @uri.newtype, :o]).to_s.should == "DELETE FROM <#{@graph}> { ?s <#{@graph}newtype> ?o . } WHERE { ?s <#{@graph}newtype> ?o . }"
96
- end
97
-
98
- it "should support CREATE GRAPH queries" do
99
- @query.create(RDF::URI.new(@graph)).to_s.should == "CREATE GRAPH <#{@graph}>"
100
- @query.create(RDF::URI.new(@graph), :silent => true).to_s.should == "CREATE SILENT GRAPH <#{@graph}>"
101
- end
102
-
103
- it "should support DROP GRAPH queries" do
104
- @query.drop(RDF::URI.new(@graph)).to_s.should == "DROP GRAPH <#{@graph}>"
105
- @query.drop(RDF::URI.new(@graph), :silent => true).to_s.should == "DROP SILENT GRAPH <#{@graph}>"
106
-
107
- end
108
-
109
- end
110
-
111
- context "when building ASK queries" do
112
- it "should support basic graph patterns" do
113
- @query.ask.where([:s, :p, :o]).to_s.should == "ASK WHERE { ?s ?p ?o . }"
114
- @query.ask.whether([:s, :p, :o]).to_s.should == "ASK WHERE { ?s ?p ?o . }"
115
- end
116
- end
117
-
118
- context "when building SELECT queries" do
119
- it "should support basic graph patterns" do
120
- @query.select.where([:s, :p, :o]).to_s.should == "SELECT * WHERE { ?s ?p ?o . }"
121
- end
122
-
123
- it "should support projection" do
124
- @query.select(:s).where([:s, :p, :o]).to_s.should == "SELECT ?s WHERE { ?s ?p ?o . }"
125
- @query.select(:s, :p).where([:s, :p, :o]).to_s.should == "SELECT ?s ?p WHERE { ?s ?p ?o . }"
126
- @query.select(:s, :p, :o).where([:s, :p, :o]).to_s.should == "SELECT ?s ?p ?o WHERE { ?s ?p ?o . }"
127
- end
128
-
129
- it "should support SELECT FROM" do
130
- @graph = RDF::URI("http://example.org/")
131
- @query.select(:s).where([:s, :p, :o]).from(@graph).to_s.should == "SELECT ?s FROM <#{@graph}> WHERE { ?s ?p ?o . }"
132
- end
133
-
134
- it "should support SELECT FROM and FROM NAMED" do
135
- @graph1 = RDF::URI("a")
136
- @graph2 = RDF::URI("b")
137
- @query.select(:s).where([:s, :p, :o, :context => @graph2]).from(@graph1).from_named(@graph2).to_s.should ==
138
- "SELECT ?s FROM <#{@graph1}> FROM NAMED <#{@graph2}> WHERE { GRAPH <#{@graph2}> { ?s ?p ?o . } }"
139
- end
140
-
141
-
142
- it "should support SELECT with complex WHERE patterns" do
143
- @query.select.where(
144
- [:s, :p, :o],
145
- [:s, RDF.type, RDF::DC.Document]
146
- ).to_s.should ==
147
- "SELECT * WHERE { ?s ?p ?o . ?s <#{RDF.type}> <#{RDF::DC.Document}> . }"
148
- end
149
-
150
- it "should support SELECT WHERE patterns from different GRAPH contexts" do
151
- @graph1 = "http://example1.org/"
152
- @graph2 = "http://example2.org/"
153
- @query.select.where([:s, :p, :o, :context => @graph1],[:s, RDF.type, RDF::DC.Document, :context => @graph2]).to_s.should ==
154
- "SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.Document}> . } }"
155
- end
156
-
157
- it "should support string objects in SPARQL queries" do
158
- @query.select.where([:s, :p, "dummyobject"]).to_s.should == "SELECT * WHERE { ?s ?p \"dummyobject\" . }"
159
- end
160
-
161
- #it "should support raw string SPARQL queries" do
162
- # q = "SELECT * WHERE { ?s <#{RDF.type}> ?o . }"
163
- # @query.query(q).should == "SELECT * WHERE { ?s <#{RDF.type}> ?o . }"
164
- #end
165
-
166
- it "should support FROM" do
167
- uri = "http://example.org/dft.ttl"
168
- @query.select.from(RDF::URI.new(uri)).where([:s, :p, :o]).to_s.should ==
169
- "SELECT * FROM <#{uri}> WHERE { ?s ?p ?o . }"
170
- end
171
-
172
- it "should support DISTINCT" do
173
- @query.select(:s, :distinct => true).where([:s, :p, :o]).to_s.should == "SELECT DISTINCT ?s WHERE { ?s ?p ?o . }"
174
- @query.select(:s).distinct.where([:s, :p, :o]).to_s.should == "SELECT DISTINCT ?s WHERE { ?s ?p ?o . }"
175
- end
176
-
177
- it "should support REDUCED" do
178
- @query.select(:s, :reduced => true).where([:s, :p, :o]).to_s.should == "SELECT REDUCED ?s WHERE { ?s ?p ?o . }"
179
- @query.select(:s).reduced.where([:s, :p, :o]).to_s.should == "SELECT REDUCED ?s WHERE { ?s ?p ?o . }"
180
- end
181
-
182
- it "should support aggregate COUNT" do
183
- @query.select.where([:s, :p, :o]).count(:s).to_s.should == "SELECT (COUNT (?s) AS ?s) WHERE { ?s ?p ?o . }"
184
- @query.select.count(:s).where([:s, :p, :o]).to_s.should == "SELECT (COUNT (?s) AS ?s) WHERE { ?s ?p ?o . }"
185
- end
186
-
187
- it "should support aggregates SUM, MIN, MAX, AVG, SAMPLE, GROUP_CONCAT, GROUP_DIGEST" do
188
- @query.select.where([:s, :p, :o]).sum(:s).to_s.should == "SELECT (SUM (?s) AS ?s) WHERE { ?s ?p ?o . }"
189
- @query.select.where([:s, :p, :o]).min(:s).to_s.should == "SELECT (MIN (?s) AS ?s) WHERE { ?s ?p ?o . }"
190
- @query.select.where([:s, :p, :o]).max(:s).to_s.should == "SELECT (MAX (?s) AS ?s) WHERE { ?s ?p ?o . }"
191
- @query.select.where([:s, :p, :o]).avg(:s).to_s.should == "SELECT (AVG (?s) AS ?s) WHERE { ?s ?p ?o . }"
192
- @query.select.where([:s, :p, :o]).sample(:s).to_s.should == "SELECT (sql:SAMPLE (?s) AS ?s) WHERE { ?s ?p ?o . }"
193
- @query.select.where([:s, :p, :o]).group_concat(:s, '_').to_s.should == "SELECT (sql:GROUP_CONCAT (?s, '_' ) AS ?s) WHERE { ?s ?p ?o . }"
194
- @query.select.where([:s, :p, :o]).group_digest(:s, '_', 1000, 1).to_s.should == "SELECT (sql:GROUP_DIGEST (?s, '_', 1000, 1 ) AS ?s) WHERE { ?s ?p ?o . }"
195
- end
196
-
197
- it "should support multiple instances of SAMPLE" do
198
- @query.select.where([:s, :p, :o]).sample(:s).sample(:p).to_s.should == "SELECT (sql:SAMPLE (?s) AS ?s) (sql:SAMPLE (?p) AS ?p) WHERE { ?s ?p ?o . }"
199
- end
200
-
201
- it "should support multiple instances of MIN/MAX/AVG/SUM" do
202
- @query.select.where([:s, :p, :o]).min(:s).min(:p).to_s.should == "SELECT (MIN (?s) AS ?s) (MIN (?p) AS ?p) WHERE { ?s ?p ?o . }"
203
- @query.select.where([:s, :p, :o]).max(:s).max(:p).to_s.should == "SELECT (MAX (?s) AS ?s) (MAX (?p) AS ?p) WHERE { ?s ?p ?o . }"
204
- @query.select.where([:s, :p, :o]).avg(:s).avg(:p).to_s.should == "SELECT (AVG (?s) AS ?s) (AVG (?p) AS ?p) WHERE { ?s ?p ?o . }"
205
- @query.select.where([:s, :p, :o]).sum(:s).sum(:p).to_s.should == "SELECT (SUM (?s) AS ?s) (SUM (?p) AS ?p) WHERE { ?s ?p ?o . }"
206
- end
207
-
208
- it "should support multiple instances of GROUP_CONCAT" do
209
- @query.select.where([:s, :p, :o]).group_concat(:s, '_').group_concat(:p, '-').to_s.should == "SELECT (sql:GROUP_CONCAT (?s, '_' ) AS ?s) (sql:GROUP_CONCAT (?p, '-' ) AS ?p) WHERE { ?s ?p ?o . }"
210
- end
211
-
212
- it "should support multiple instances of GROUP_DIGEST" do
213
- @query.select.where([:s, :p, :o]).group_digest(:s, '_', 1000, 1).group_digest(:p, '-', 1000, 1).to_s.should == "SELECT (sql:GROUP_DIGEST (?s, '_', 1000, 1 ) AS ?s) (sql:GROUP_DIGEST (?p, '-', 1000, 1 ) AS ?p) WHERE { ?s ?p ?o . }"
214
- end
215
-
216
- it "should support aggregates in addition to SELECT variables" do
217
- @query.select(:s).where([:s, :p, :o]).group_digest(:o, '_', 1000, 1).to_s.should == "SELECT (sql:GROUP_DIGEST (?o, '_', 1000, 1 ) AS ?o) ?s WHERE { ?s ?p ?o . }"
218
- end
219
-
220
- it "should support multiple instances of aggregates AND select variables" do
221
- @query.select(:s).where([:s, :p, :o]).sample(:p).sample(:o).to_s.should == "SELECT (sql:SAMPLE (?p) AS ?p) (sql:SAMPLE (?o) AS ?o) ?s WHERE { ?s ?p ?o . }"
222
- end
223
-
224
- it "should support ORDER BY" do
225
- @query.select.where([:s, :p, :o]).order_by(:o).to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o"
226
- @query.select.where([:s, :p, :o]).order_by('?o').to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o"
227
- # @query.select.where([:s, :p, :o]).order_by(:o => :asc).to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o ASC"
228
- @query.select.where([:s, :p, :o]).order_by('ASC(?o)').to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ASC(?o)"
229
- # @query.select.where([:s, :p, :o]).order_by(:o => :desc).to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o DESC"
230
- @query.select.where([:s, :p, :o]).order_by('DESC(?o)').to_s.should == "SELECT * WHERE { ?s ?p ?o . } ORDER BY DESC(?o)"
231
- end
232
-
233
- it "should support OFFSET" do
234
- @query.select.where([:s, :p, :o]).offset(100).to_s.should == "SELECT * WHERE { ?s ?p ?o . } OFFSET 100"
235
- end
236
-
237
- it "should support LIMIT" do
238
- @query.select.where([:s, :p, :o]).limit(10).to_s.should == "SELECT * WHERE { ?s ?p ?o . } LIMIT 10"
239
- end
240
-
241
- it "should support OFFSET with LIMIT" do
242
- @query.select.where([:s, :p, :o]).offset(100).limit(10).to_s.should == "SELECT * WHERE { ?s ?p ?o . } OFFSET 100 LIMIT 10"
243
- @query.select.where([:s, :p, :o]).slice(100, 10).to_s.should == "SELECT * WHERE { ?s ?p ?o . } OFFSET 100 LIMIT 10"
244
- end
245
-
246
- # DEPRECATED - USE RDF::Vocabulary instead
247
- =begin
248
- it "should support PREFIX" do
249
- prefixes = ["dc: <http://purl.org/dc/elements/1.1/>", "foaf: <http://xmlns.com/foaf/0.1/>"]
250
- @query.select.prefix(prefixes[0]).prefix(prefixes[1]).where([:s, :p, :o]).to_s.should ==
251
- "PREFIX #{prefixes[0]} PREFIX #{prefixes[1]} SELECT * WHERE { ?s ?p ?o . }"
252
- end
253
-
254
- it "constructs PREFIXes" do
255
- prefixes = RDF::Virtuoso::Prefixes.new dc: RDF::DC, foaf: RDF::FOAF
256
- @query.select.prefixes(prefixes).where([:s, :p, :o]).to_s.should ==
257
- "PREFIX dc: <#{RDF::DC}> PREFIX foaf: <#{RDF::FOAF}> SELECT * WHERE { ?s ?p ?o . }"
258
- end
259
-
260
- it "should support custom PREFIXes in hash array" do
261
- prefixes = RDF::Virtuoso::Prefixes.new foo: "http://foo.com/", bar: "http://bar.net"
262
- @query.select.prefixes(prefixes).where([:s, :p, :o]).to_s.should ==
263
- "PREFIX foo: <http://foo.com/> PREFIX bar: <http://bar.net> SELECT * WHERE { ?s ?p ?o . }"
264
- end
265
-
266
- it "should support accessing custom PREFIXes in SELECT" do
267
- prefixes = RDF::Virtuoso::Prefixes.new foo: "http://foo.com/"
268
- @query.select.where(['foo:bar', :p, :o]).prefixes(prefixes).to_s.should ==
269
- "PREFIX foo: <http://foo.com/bar> SELECT * WHERE { ?s ?p ?o . }"
270
- end
271
- =end
272
-
273
- it "should support using custom RDF::Vocabulary prefixes" do
274
- BIBO = RDF::Vocabulary.new("http://purl.org/ontology/bibo/")
275
- @query.select.where([:s, :p, BIBO.Document]).to_s.should ==
276
- "SELECT * WHERE { ?s ?p <http://purl.org/ontology/bibo/Document> . }"
277
- end
278
-
279
- it "should support OPTIONAL" do
280
- @query.select.where([:s, :p, :o]).optional([:s, RDF.type, :o], [:s, RDF::DC.abstract, :o]).to_s.should ==
281
- "SELECT * WHERE { ?s ?p ?o . OPTIONAL { ?s <#{RDF.type}> ?o . ?s <#{RDF::DC.abstract}> ?o . } }"
282
- end
283
-
284
- it "should support OPTIONAL with GRAPH contexts" do
285
- @graph1 = "http://example1.org/"
286
- @graph2 = "http://example2.org/"
287
- @query.select.where([:s, :p, :o, :context => @graph1]).optional([:s, RDF.type, RDF::DC.Document, :context => @graph2]).to_s.should ==
288
- "SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } OPTIONAL { GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.Document}> . } } }"
289
- end
290
-
291
- it "should support multiple OPTIONALs" do
292
- @query.select.where([:s, :p, :o]).optional([:s, RDF.type, :o]).optional([:s, RDF::DC.abstract, :o]).to_s.should ==
293
- "SELECT * WHERE { ?s ?p ?o . OPTIONAL { ?s <#{RDF.type}> ?o . } OPTIONAL { ?s <#{RDF::DC.abstract}> ?o . } }"
294
- end
295
-
296
- it "should support MINUS, also with an array pattern" do
297
- @query.select.where([:s, :p, :o]).minus([:s, RDF.type, :o], [:s, RDF::DC.abstract, :o]).to_s.should ==
298
- "SELECT * WHERE { ?s ?p ?o . MINUS { ?s <#{RDF.type}> ?o . ?s <#{RDF::DC.abstract}> ?o . } }"
299
- end
300
-
301
- it "should support multiple MINUSes" do
302
- @query.select.where([:s, :p, :o]).minus([:s, RDF.type, :o]).minus([:s, RDF::DC.abstract, :o]).to_s.should ==
303
- "SELECT * WHERE { ?s ?p ?o . MINUS { ?s <#{RDF.type}> ?o . } MINUS { ?s <#{RDF::DC.abstract}> ?o . } }"
304
- end
305
-
306
- it "should support MINUS with a GRAPH context" do
307
- @graph1 = "http://example1.org/"
308
- @query.select.where([:s, :p, :o]).minus([:s, RDF.type, :o, :context => @graph1]).to_s.should ==
309
- "SELECT * WHERE { ?s ?p ?o . MINUS { GRAPH <#{@graph1}> { ?s <#{RDF.type}> ?o . } } }"
310
- end
311
-
312
- it "should support UNION" do
313
- @query.select.where([:s, RDF::DC.abstract, :o]).union([:s, RDF.type, :o]).to_s.should ==
314
- "SELECT * WHERE { { ?s <#{RDF::DC.abstract}> ?o . } UNION { ?s <#{RDF.type}> ?o . } }"
315
- end
316
-
317
- it "should support FILTER" do
318
- @query.select.where([:s, RDF::DC.abstract, :o]).filter('lang(?text) != "nb"').to_s.should ==
319
- "SELECT * WHERE { ?s <#{RDF::DC.abstract}> ?o . FILTER(lang(?text) != \"nb\") }"
320
- end
321
-
322
- it "should support multiple FILTERs" do
323
- filters = ['lang(?text) != "nb"', 'regex(?uri, "^https")']
324
- @query.select.where([:s, RDF::DC.abstract, :o]).filters(filters).to_s.should ==
325
- "SELECT * WHERE { ?s <#{RDF::DC.abstract}> ?o . FILTER(lang(?text) != \"nb\") FILTER(regex(?uri, \"^https\")) }"
326
- end
327
-
328
- it "should support DEFINE headers in queries" do
329
- define = 'sql:select-option "ORDER"'
330
- @query.select.where([:s, RDF::DC.abstract, :o]).define(define).to_s.should ==
331
- "DEFINE #{define} SELECT * WHERE { ?s <#{RDF::DC.abstract}> ?o . }"
332
- end
333
-
334
- it "should support grouping graph patterns within brackets" do
335
- @query.select.where.group([:s, :p, :o],[:s2, :p2, :o2]).
336
- where([:s3, :p3, :o3]).to_s.should ==
337
- "SELECT * WHERE { { ?s ?p ?o . ?s2 ?p2 ?o2 . } ?s3 ?p3 ?o3 . }"
338
- end
339
-
340
- it "should support grouping with several graph statements" do
341
- @query.select.where.graph2(RDF::URI.new("a")).group([:s, :p, :o],[:s2, :p2, :o2]).
342
- where.graph2(RDF::URI.new("b")).group([:s3, :p3, :o3]).to_s.should ==
343
- "SELECT * WHERE { GRAPH <a> { ?s ?p ?o . ?s2 ?p2 ?o2 . } GRAPH <b> { ?s3 ?p3 ?o3 . } }"
344
- end
345
-
346
- end
347
-
348
- context "when building DESCRIBE queries" do
349
- it "should support basic graph patterns" do
350
- @query.describe.where([:s, :p, :o]).to_s.should == "DESCRIBE * WHERE { ?s ?p ?o . }"
351
- end
352
-
353
- it "should support projection" do
354
- @query.describe(:s).where([:s, :p, :o]).to_s.should == "DESCRIBE ?s WHERE { ?s ?p ?o . }"
355
- @query.describe(:s, :p).where([:s, :p, :o]).to_s.should == "DESCRIBE ?s ?p WHERE { ?s ?p ?o . }"
356
- @query.describe(:s, :p, :o).where([:s, :p, :o]).to_s.should == "DESCRIBE ?s ?p ?o WHERE { ?s ?p ?o . }"
357
- end
358
-
359
- it "should support RDF::URI arguments" do
360
- uris = ['http://www.bbc.co.uk/programmes/b007stmh#programme', 'http://www.bbc.co.uk/programmes/b00lg2xb#programme']
361
- @query.describe(RDF::URI.new(uris[0]),RDF::URI.new(uris[1])).to_s.should ==
362
- "DESCRIBE <#{uris[0]}> <#{uris[1]}>"
363
- end
364
- end
365
-
366
- context "when building CONSTRUCT queries" do
367
- it "should support basic graph patterns" do
368
- @query.construct([:s, :p, :o]).where([:s, :p, :o]).to_s.should == "CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
369
- end
370
-
371
- it "should support complex constructs" do
372
- @query.construct([:s, :p, :o], [:s, :q, RDF::Literal.new("new")]).where([:s, :p, :o], [:s, :q, "old"]).to_s.should == "CONSTRUCT { ?s ?p ?o . ?s ?q \"new\" . } WHERE { ?s ?p ?o . ?s ?q \"old\" . }"
373
- end
374
-
375
-
376
- end
377
- end
@@ -1,30 +0,0 @@
1
- require_relative '../lib/rdf/virtuoso/repository'
2
- describe RDF::Virtuoso do
3
-
4
- before(:each) do
5
- @uri = "http://localhost:8890/sparql"
6
- @update_uri = "http://localhost:8890/sparql-auth"
7
- end
8
-
9
- context "when connecting to a Virtuoso server" do
10
- it "should support connecting to a Virtuoso SPARQL endpoint" do
11
- repo = RDF::Virtuoso::Repository.new(@uri)
12
- repo.instance_variable_get("@sparul_endpoint").should == "/sparql"
13
- end
14
-
15
- it "should support accept port in repository endpoint" do
16
- repo = RDF::Virtuoso::Repository.new(@uri)
17
- repo.instance_variable_get("@base_uri").should == "http://localhost:8890"
18
- end
19
-
20
- it "should support connecting to a Virtuoso SPARUL endpoint with BASIC AUTH" do
21
- repo = RDF::Virtuoso::Repository.new(@uri, :update_uri => @update_uri, :username => 'admin', :password => 'secret', :auth_method => 'basic')
22
- repo.instance_variable_get("@auth_method").should == "basic"
23
- end
24
-
25
- it "should support connecting to a Virtuoso SPARUL endpoint with DIGEST AUTH" do
26
- repo = RDF::Virtuoso::Repository.new(@uri, :update_uri => @update_uri, :username => 'admin', :password => 'secret', :auth_method => 'digest')
27
- repo.instance_variable_get("@sparul_endpoint").should == "/sparql-auth"
28
- end
29
- end
30
- end