sparql-client 3.0.1 → 3.1.0
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.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/VERSION +1 -1
- data/lib/sparql/client.rb +69 -44
- data/lib/sparql/client/query.rb +22 -21
- data/lib/sparql/client/repository.rb +11 -11
- data/lib/sparql/client/update.rb +27 -28
- metadata +22 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25fd44467b4b7014096fea7c336164c863b3da501ee747466ed486bdfab2f93d
|
4
|
+
data.tar.gz: f44d3e424e8c3fb13b0a323403212134c34e8fa7fb7ebaba562ded69a9d02fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 404e7f204b5bda734f531b29133705dcdf236a4bc7f348f32f6034595e43cd7e78814cb2d8cf66c696a9fd548496fd50b245b5bf2e705a551ef6e5012321c7d6
|
7
|
+
data.tar.gz: 4764b49167f0bd23e16455d9e1cf9ede6193db3dcd96eb17fd9ed4245557906dd5195424dbe88f098c8381e580ffc433f577e558b5472cb4f8f2a1756de3f911
|
data/README.md
CHANGED
@@ -30,11 +30,20 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
|
|
30
30
|
require 'sparql/client'
|
31
31
|
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
|
32
32
|
```
|
33
|
+
|
34
|
+
### Querying a remote SPARQL endpoint with a custom User-Agent
|
35
|
+
By default, SPARQL::Client adds a `User-Agent` field to requests, but applications may choose to provide their own, using the `headers` option:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'sparql/client'
|
39
|
+
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", headers: {'User-Agent' => 'MyBotName'})
|
40
|
+
```
|
41
|
+
|
33
42
|
### Querying a remote SPARQL endpoint with a specified default graph
|
34
43
|
|
35
44
|
```ruby
|
36
45
|
require 'sparql/client'
|
37
|
-
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", { :
|
46
|
+
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", { graph: "http://dbpedia.org" })
|
38
47
|
```
|
39
48
|
|
40
49
|
|
@@ -114,11 +123,11 @@ sparql.delete_data(data)
|
|
114
123
|
|
115
124
|
## Dependencies
|
116
125
|
|
117
|
-
* [Ruby](http://ruby-lang.org/) (>= 2.
|
118
|
-
* [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.
|
119
|
-
* [Net::HTTP::Persistent](http://rubygems.org/gems/net-http-persistent) (
|
120
|
-
* Soft dependency on [SPARQL](http://rubygems.org/gems/sparql) (~> 3.
|
121
|
-
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.
|
126
|
+
* [Ruby](http://ruby-lang.org/) (>= 2.4)
|
127
|
+
* [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.1)
|
128
|
+
* [Net::HTTP::Persistent](http://rubygems.org/gems/net-http-persistent) (~> 3.1)
|
129
|
+
* Soft dependency on [SPARQL](http://rubygems.org/gems/sparql) (~> 3.1)
|
130
|
+
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.10)
|
122
131
|
|
123
132
|
## Installation
|
124
133
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0
|
1
|
+
3.1.0
|
data/lib/sparql/client.rb
CHANGED
@@ -86,8 +86,13 @@ module SPARQL
|
|
86
86
|
# @option options [Symbol] :method (DEFAULT_METHOD)
|
87
87
|
# @option options [Number] :protocol (DEFAULT_PROTOCOL)
|
88
88
|
# @option options [Hash] :headers
|
89
|
+
# HTTP Request headers
|
90
|
+
#
|
91
|
+
# Defaults `Accept` header based on available reader content types if triples are expected and to SPARQL result types otherwise, to allow for content negotiation based on available readers.
|
92
|
+
#
|
93
|
+
# Defaults `User-Agent` header, unless one is specified.
|
89
94
|
# @option options [Hash] :read_timeout
|
90
|
-
def initialize(url, options
|
95
|
+
def initialize(url, **options, &block)
|
91
96
|
case url
|
92
97
|
when RDF::Queryable
|
93
98
|
@url, @options = url, options.dup
|
@@ -95,6 +100,9 @@ module SPARQL
|
|
95
100
|
@url, @options = RDF::URI.new(url.to_s), options.dup
|
96
101
|
@headers = @options.delete(:headers) || {}
|
97
102
|
@http = http_klass(@url.scheme)
|
103
|
+
|
104
|
+
# Close the http connection when object is deallocated
|
105
|
+
ObjectSpace.define_finalizer(self, proc {@http.shutdown if @http.respond_to?(:shutdown)})
|
98
106
|
end
|
99
107
|
|
100
108
|
if block_given?
|
@@ -105,13 +113,23 @@ module SPARQL
|
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
116
|
+
##
|
117
|
+
# Closes a client instance by finishing the connection.
|
118
|
+
# The client is unavailable for any further data operations; an IOError is raised if such an attempt is made. I/O streams are automatically closed when they are claimed by the garbage collector.
|
119
|
+
# @return [void] `self`
|
120
|
+
def close
|
121
|
+
@http.shutdown if @http
|
122
|
+
@http = nil
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
108
126
|
##
|
109
127
|
# Executes a boolean `ASK` query.
|
110
128
|
#
|
111
129
|
# @param (see Query.ask)
|
112
130
|
# @return [Query]
|
113
|
-
def ask(*args)
|
114
|
-
call_query_method(:ask, *args)
|
131
|
+
def ask(*args, **options)
|
132
|
+
call_query_method(:ask, *args, **options)
|
115
133
|
end
|
116
134
|
|
117
135
|
##
|
@@ -119,8 +137,8 @@ module SPARQL
|
|
119
137
|
#
|
120
138
|
# @param (see Query.select)
|
121
139
|
# @return [Query]
|
122
|
-
def select(*args)
|
123
|
-
call_query_method(:select, *args)
|
140
|
+
def select(*args, **options)
|
141
|
+
call_query_method(:select, *args, **options)
|
124
142
|
end
|
125
143
|
|
126
144
|
##
|
@@ -128,8 +146,8 @@ module SPARQL
|
|
128
146
|
#
|
129
147
|
# @param (see Query.describe)
|
130
148
|
# @return [Query]
|
131
|
-
def describe(*args)
|
132
|
-
call_query_method(:describe, *args)
|
149
|
+
def describe(*args, **options)
|
150
|
+
call_query_method(:describe, *args, **options)
|
133
151
|
end
|
134
152
|
|
135
153
|
##
|
@@ -137,8 +155,8 @@ module SPARQL
|
|
137
155
|
#
|
138
156
|
# @param (see Query.construct)
|
139
157
|
# @return [Query]
|
140
|
-
def construct(*args)
|
141
|
-
call_query_method(:construct, *args)
|
158
|
+
def construct(*args, **options)
|
159
|
+
call_query_method(:construct, *args, **options)
|
142
160
|
end
|
143
161
|
|
144
162
|
##
|
@@ -161,15 +179,15 @@ module SPARQL
|
|
161
179
|
# client.insert_data(data)
|
162
180
|
#
|
163
181
|
# @example Inserting data into a named graph
|
164
|
-
# client.insert_data(data, :
|
182
|
+
# client.insert_data(data, graph: "http://example.org/")
|
165
183
|
#
|
166
184
|
# @param [RDF::Enumerable] data
|
167
185
|
# @param [Hash{Symbol => Object}] options
|
168
186
|
# @option options [RDF::URI, String] :graph
|
169
187
|
# @return [void] `self`
|
170
188
|
# @see http://www.w3.org/TR/sparql11-update/#insertData
|
171
|
-
def insert_data(data, options
|
172
|
-
self.update(Update::InsertData.new(data, options))
|
189
|
+
def insert_data(data, **options)
|
190
|
+
self.update(Update::InsertData.new(data, **options))
|
173
191
|
end
|
174
192
|
|
175
193
|
##
|
@@ -182,15 +200,15 @@ module SPARQL
|
|
182
200
|
# client.delete_data(data)
|
183
201
|
#
|
184
202
|
# @example Deleting data from a named graph
|
185
|
-
# client.delete_data(data, :
|
203
|
+
# client.delete_data(data, graph: "http://example.org/")
|
186
204
|
#
|
187
205
|
# @param [RDF::Enumerable] data
|
188
206
|
# @param [Hash{Symbol => Object}] options
|
189
207
|
# @option options [RDF::URI, String] :graph
|
190
208
|
# @return [void] `self`
|
191
209
|
# @see http://www.w3.org/TR/sparql11-update/#deleteData
|
192
|
-
def delete_data(data, options
|
193
|
-
self.update(Update::DeleteData.new(data, options))
|
210
|
+
def delete_data(data, **options)
|
211
|
+
self.update(Update::DeleteData.new(data, **options))
|
194
212
|
end
|
195
213
|
|
196
214
|
##
|
@@ -205,8 +223,8 @@ module SPARQL
|
|
205
223
|
# @option options [RDF::URI, String] :graph
|
206
224
|
# @return [void] `self`
|
207
225
|
# @see http://www.w3.org/TR/sparql11-update/#deleteInsert
|
208
|
-
def delete_insert(delete_graph, insert_graph = nil, where_graph = nil, options
|
209
|
-
self.update(Update::DeleteInsert.new(delete_graph, insert_graph, where_graph, options))
|
226
|
+
def delete_insert(delete_graph, insert_graph = nil, where_graph = nil, **options)
|
227
|
+
self.update(Update::DeleteInsert.new(delete_graph, insert_graph, where_graph, **options))
|
210
228
|
end
|
211
229
|
|
212
230
|
##
|
@@ -222,8 +240,8 @@ module SPARQL
|
|
222
240
|
# @option options [Boolean] :silent
|
223
241
|
# @return [void] `self`
|
224
242
|
# @see http://www.w3.org/TR/sparql11-update/#clear
|
225
|
-
def clear_graph(graph_uri, options
|
226
|
-
self.clear(:graph, graph_uri, options)
|
243
|
+
def clear_graph(graph_uri, **options)
|
244
|
+
self.clear(:graph, graph_uri, **options)
|
227
245
|
end
|
228
246
|
|
229
247
|
##
|
@@ -249,7 +267,7 @@ module SPARQL
|
|
249
267
|
# @option options [Boolean] :silent
|
250
268
|
# @return [void] `self`
|
251
269
|
#
|
252
|
-
# @overload clear(what, *arguments, options
|
270
|
+
# @overload clear(what, *arguments, **options)
|
253
271
|
# @param [Symbol, #to_sym] what
|
254
272
|
# @param [Array] arguments splat of other arguments to {Update::Clear}.
|
255
273
|
# @param [Hash{Symbol => Object}] options
|
@@ -263,9 +281,9 @@ module SPARQL
|
|
263
281
|
|
264
282
|
##
|
265
283
|
# @private
|
266
|
-
def call_query_method(meth, *args)
|
284
|
+
def call_query_method(meth, *args, **options)
|
267
285
|
client = self
|
268
|
-
result = Query.send(meth, *args)
|
286
|
+
result = Query.send(meth, *args, **options)
|
269
287
|
(class << result; self; end).send(:define_method, :execute) do
|
270
288
|
client.query(self)
|
271
289
|
end
|
@@ -288,21 +306,22 @@ module SPARQL
|
|
288
306
|
# @option options [String] :content_type
|
289
307
|
# @option options [Hash] :headers
|
290
308
|
# @return [Array<RDF::Query::Solution>]
|
309
|
+
# @raise [IOError] if connection is closed
|
291
310
|
# @see http://www.w3.org/TR/sparql11-protocol/#query-operation
|
292
|
-
def query(query, options
|
311
|
+
def query(query, **options)
|
293
312
|
@op = :query
|
294
313
|
@alt_endpoint = options[:endpoint]
|
295
314
|
case @url
|
296
315
|
when RDF::Queryable
|
297
316
|
require 'sparql' unless defined?(::SPARQL::Grammar)
|
298
317
|
begin
|
299
|
-
SPARQL.execute(query, @url, options)
|
318
|
+
SPARQL.execute(query, @url, **options)
|
300
319
|
rescue SPARQL::MalformedQuery
|
301
320
|
$stderr.puts "error running #{query}: #{$!}"
|
302
321
|
raise
|
303
322
|
end
|
304
323
|
else
|
305
|
-
parse_response(response(query, options), options)
|
324
|
+
parse_response(response(query, **options), **options)
|
306
325
|
end
|
307
326
|
end
|
308
327
|
|
@@ -315,16 +334,17 @@ module SPARQL
|
|
315
334
|
# @option options [String] :content_type
|
316
335
|
# @option options [Hash] :headers
|
317
336
|
# @return [void] `self`
|
337
|
+
# @raise [IOError] if connection is closed
|
318
338
|
# @see http://www.w3.org/TR/sparql11-protocol/#update-operation
|
319
|
-
def update(query, options
|
339
|
+
def update(query, **options)
|
320
340
|
@op = :update
|
321
341
|
@alt_endpoint = options[:endpoint]
|
322
342
|
case @url
|
323
343
|
when RDF::Queryable
|
324
344
|
require 'sparql' unless defined?(::SPARQL::Grammar)
|
325
|
-
SPARQL.execute(query, @url,
|
345
|
+
SPARQL.execute(query, @url, update: true, **options)
|
326
346
|
else
|
327
|
-
response(query, options)
|
347
|
+
response(query, **options)
|
328
348
|
end
|
329
349
|
self
|
330
350
|
end
|
@@ -338,8 +358,9 @@ module SPARQL
|
|
338
358
|
# @option options [String] :content_type
|
339
359
|
# @option options [Hash] :headers
|
340
360
|
# @return [String]
|
341
|
-
|
342
|
-
|
361
|
+
# @raise [IOError] if connection is closed
|
362
|
+
def response(query, **options)
|
363
|
+
headers = options[:headers] || @headers
|
343
364
|
headers['Accept'] = options[:content_type] if options[:content_type]
|
344
365
|
request(query, headers) do |response|
|
345
366
|
case response
|
@@ -359,7 +380,7 @@ module SPARQL
|
|
359
380
|
# @param [Net::HTTPSuccess] response
|
360
381
|
# @param [Hash{Symbol => Object}] options
|
361
382
|
# @return [Object]
|
362
|
-
def parse_response(response, options
|
383
|
+
def parse_response(response, **options)
|
363
384
|
case options[:content_type] || response.content_type
|
364
385
|
when NilClass
|
365
386
|
response.body
|
@@ -374,7 +395,7 @@ module SPARQL
|
|
374
395
|
when RESULT_TSV
|
375
396
|
self.class.parse_tsv_bindings(response.body, nodes)
|
376
397
|
else
|
377
|
-
parse_rdf_serialization(response, options)
|
398
|
+
parse_rdf_serialization(response, **options)
|
378
399
|
end
|
379
400
|
end
|
380
401
|
|
@@ -411,9 +432,9 @@ module SPARQL
|
|
411
432
|
when :uri
|
412
433
|
RDF::URI.new(value['value'])
|
413
434
|
when :literal
|
414
|
-
RDF::Literal.new(value['value'], :
|
435
|
+
RDF::Literal.new(value['value'], datatype: value['datatype'], language: value['xml:lang'])
|
415
436
|
when :'typed-literal'
|
416
|
-
RDF::Literal.new(value['value'], :
|
437
|
+
RDF::Literal.new(value['value'], datatype: value['datatype'])
|
417
438
|
else nil
|
418
439
|
end
|
419
440
|
end
|
@@ -529,7 +550,7 @@ module SPARQL
|
|
529
550
|
when :literal
|
530
551
|
lang = value.respond_to?(:attr) ? value.attr('xml:lang') : value.attributes['xml:lang']
|
531
552
|
datatype = value.respond_to?(:attr) ? value.attr('datatype') : value.attributes['datatype']
|
532
|
-
RDF::Literal.new(value.text, :
|
553
|
+
RDF::Literal.new(value.text, language: lang, datatype: datatype)
|
533
554
|
else nil
|
534
555
|
end
|
535
556
|
end
|
@@ -538,8 +559,8 @@ module SPARQL
|
|
538
559
|
# @param [Net::HTTPSuccess] response
|
539
560
|
# @param [Hash{Symbol => Object}] options
|
540
561
|
# @return [RDF::Enumerable]
|
541
|
-
def parse_rdf_serialization(response, options
|
542
|
-
options = {:
|
562
|
+
def parse_rdf_serialization(response, **options)
|
563
|
+
options = {content_type: response.content_type} unless options[:content_type]
|
543
564
|
if reader = RDF::Reader.for(options)
|
544
565
|
reader.new(response.body)
|
545
566
|
else
|
@@ -615,7 +636,7 @@ module SPARQL
|
|
615
636
|
RDF::Statement.from(pattern).to_triple.each_with_index.map do |v, i|
|
616
637
|
if i == 1
|
617
638
|
SPARQL::Client.serialize_predicate(v)
|
618
|
-
|
639
|
+
else
|
619
640
|
SPARQL::Client.serialize_value(v, use_vars)
|
620
641
|
end
|
621
642
|
end
|
@@ -658,11 +679,7 @@ module SPARQL
|
|
658
679
|
value = ENV['https_proxy']
|
659
680
|
proxy_url = URI.parse(value) unless value.nil? || value.empty?
|
660
681
|
end
|
661
|
-
klass =
|
662
|
-
Net::HTTP::Persistent.new(name: self.class.to_s, proxy: proxy_url)
|
663
|
-
else
|
664
|
-
Net::HTTP::Persistent.new(self.class.to_s, proxy_url)
|
665
|
-
end
|
682
|
+
klass = Net::HTTP::Persistent.new(name: self.class.to_s, proxy: proxy_url)
|
666
683
|
klass.keep_alive = @options[:keep_alive] || 120
|
667
684
|
klass.read_timeout = @options[:read_timeout] || 60
|
668
685
|
klass
|
@@ -673,9 +690,15 @@ module SPARQL
|
|
673
690
|
#
|
674
691
|
# @param [String, #to_s] query
|
675
692
|
# @param [Hash{String => String}] headers
|
693
|
+
# HTTP Request headers
|
694
|
+
#
|
695
|
+
# Defaults `Accept` header based on available reader content types if triples are expected and to SPARQL result types otherwise, to allow for content negotiation based on available readers.
|
696
|
+
#
|
697
|
+
# Defaults `User-Agent` header, unless one is specified.
|
676
698
|
# @yield [response]
|
677
699
|
# @yieldparam [Net::HTTPResponse] response
|
678
700
|
# @return [Net::HTTPResponse]
|
701
|
+
# @raise [IOError] if connection is closed
|
679
702
|
# @see http://www.w3.org/TR/sparql11-protocol/#query-operation
|
680
703
|
def request(query, headers = {}, &block)
|
681
704
|
# Make sure an appropriate Accept header is present
|
@@ -686,6 +709,7 @@ module SPARQL
|
|
686
709
|
else
|
687
710
|
RESULT_ALL
|
688
711
|
end
|
712
|
+
headers['User-Agent'] ||= "Ruby SPARQL::Client/#{SPARQL::Client::VERSION}"
|
689
713
|
|
690
714
|
request = send("make_#{request_method(query)}_request", query, headers)
|
691
715
|
|
@@ -693,6 +717,7 @@ module SPARQL
|
|
693
717
|
|
694
718
|
pre_http_hook(request) if respond_to?(:pre_http_hook)
|
695
719
|
|
720
|
+
raise IOError, "Client has been closed" unless @http
|
696
721
|
response = @http.request(::URI.parse(url.to_s), request)
|
697
722
|
|
698
723
|
post_http_hook(response) if respond_to?(:post_http_hook)
|
@@ -725,7 +750,7 @@ module SPARQL
|
|
725
750
|
# @see http://www.w3.org/TR/sparql11-protocol/#query-via-get
|
726
751
|
def make_get_request(query, headers = {})
|
727
752
|
url = self.url.dup
|
728
|
-
url.query_values = (url.query_values || {}).merge(:
|
753
|
+
url.query_values = (url.query_values || {}).merge(query: query.to_s)
|
729
754
|
set_url_default_graph url unless @options[:graph].nil?
|
730
755
|
request = Net::HTTP::Get.new(url.request_uri, self.headers.merge(headers))
|
731
756
|
request
|
data/lib/sparql/client/query.rb
CHANGED
@@ -26,8 +26,8 @@ class SPARQL::Client
|
|
26
26
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
27
27
|
# @return [Query]
|
28
28
|
# @see http://www.w3.org/TR/sparql11-query/#ask
|
29
|
-
def self.ask(options
|
30
|
-
self.new(:ask, options)
|
29
|
+
def self.ask(**options)
|
30
|
+
self.new(:ask, **options)
|
31
31
|
end
|
32
32
|
|
33
33
|
##
|
@@ -45,14 +45,13 @@ class SPARQL::Client
|
|
45
45
|
# @param [Array<Symbol>] variables
|
46
46
|
# @return [Query]
|
47
47
|
#
|
48
|
-
# @overload self.select(*variables, options)
|
48
|
+
# @overload self.select(*variables, **options)
|
49
49
|
# @param [Array<Symbol>] variables
|
50
50
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
51
51
|
# @return [Query]
|
52
52
|
# @see http://www.w3.org/TR/sparql11-query/#select
|
53
|
-
def self.select(*variables)
|
54
|
-
options
|
55
|
-
self.new(:select, options).select(*variables)
|
53
|
+
def self.select(*variables, **options)
|
54
|
+
self.new(:select, **options).select(*variables)
|
56
55
|
end
|
57
56
|
|
58
57
|
##
|
@@ -64,14 +63,13 @@ class SPARQL::Client
|
|
64
63
|
# @param [Array<Symbol, RDF::URI>] variables
|
65
64
|
# @return [Query]
|
66
65
|
#
|
67
|
-
# @overload self.describe(*variables, options)
|
66
|
+
# @overload self.describe(*variables, **options)
|
68
67
|
# @param [Array<Symbol, RDF::URI>] variables
|
69
68
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
70
69
|
# @return [Query]
|
71
70
|
# @see http://www.w3.org/TR/sparql11-query/#describe
|
72
|
-
def self.describe(*variables)
|
73
|
-
options
|
74
|
-
self.new(:describe, options).describe(*variables)
|
71
|
+
def self.describe(*variables, **options)
|
72
|
+
self.new(:describe, **options).describe(*variables)
|
75
73
|
end
|
76
74
|
|
77
75
|
##
|
@@ -83,19 +81,18 @@ class SPARQL::Client
|
|
83
81
|
# @param [Array<RDF::Query::Pattern, Array>] patterns
|
84
82
|
# @return [Query]
|
85
83
|
#
|
86
|
-
# @overload self.construct(*variables, options)
|
84
|
+
# @overload self.construct(*variables, **options)
|
87
85
|
# @param [Array<RDF::Query::Pattern, Array>] patterns
|
88
86
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
89
87
|
# @return [Query]
|
90
88
|
# @see http://www.w3.org/TR/sparql11-query/#construct
|
91
|
-
def self.construct(*patterns)
|
92
|
-
options
|
93
|
-
self.new(:construct, options).construct(*patterns) # FIXME
|
89
|
+
def self.construct(*patterns, **options)
|
90
|
+
self.new(:construct, **options).construct(*patterns) # FIXME
|
94
91
|
end
|
95
92
|
|
96
93
|
##
|
97
94
|
# @param [Symbol, #to_s] form
|
98
|
-
# @overload self.construct(*variables, options)
|
95
|
+
# @overload self.construct(*variables, **options)
|
99
96
|
# @param [Symbol, #to_s] form
|
100
97
|
# @param [Hash{Symbol => Object}] options (see {Client#initialize})
|
101
98
|
# @option options [Hash{Symbol => Symbol}] :count
|
@@ -104,10 +101,10 @@ class SPARQL::Client
|
|
104
101
|
#
|
105
102
|
# @yield [query]
|
106
103
|
# @yieldparam [Query]
|
107
|
-
def initialize(form = :ask, options
|
104
|
+
def initialize(form = :ask, **options, &block)
|
108
105
|
@subqueries = []
|
109
106
|
@form = form.respond_to?(:to_sym) ? form.to_sym : form.to_s.to_sym
|
110
|
-
super([], options, &block)
|
107
|
+
super([], **options, &block)
|
111
108
|
end
|
112
109
|
|
113
110
|
##
|
@@ -131,11 +128,15 @@ class SPARQL::Client
|
|
131
128
|
# @example SELECT COUNT(?uri as ?c) WHERE {?uri a owl:Class}
|
132
129
|
# query.select(count: {uri: :c}).where([:uri, RDF.type, RDF::OWL.Class])
|
133
130
|
#
|
134
|
-
# @param [Array<Symbol
|
131
|
+
# @param [Array<Symbol>, Hash{Symbol => RDF::Query::Variable}] variables
|
135
132
|
# @return [Query]
|
136
133
|
# @see http://www.w3.org/TR/sparql11-query/#select
|
137
134
|
def select(*variables)
|
138
|
-
@values = variables.
|
135
|
+
@values = if variables.length == 1 && variables.first.is_a?(Hash)
|
136
|
+
variables.to_a
|
137
|
+
else
|
138
|
+
variables.map { |var| [var, RDF::Query::Variable.new(var)] }
|
139
|
+
end
|
139
140
|
self
|
140
141
|
end
|
141
142
|
|
@@ -240,7 +241,7 @@ class SPARQL::Client
|
|
240
241
|
# query.select.where([:s, :p, :o]).order_by(:o, :p)
|
241
242
|
#
|
242
243
|
# @example SELECT * WHERE { ?s ?p ?o . } ORDER BY ASC(?o) DESC(?p)
|
243
|
-
# query.select.where([:s, :p, :o]).order_by(:
|
244
|
+
# query.select.where([:s, :p, :o]).order_by(o: :asc, p: :desc)
|
244
245
|
#
|
245
246
|
# @param [Array<Symbol, String>] variables
|
246
247
|
# @return [Query]
|
@@ -727,7 +728,7 @@ class SPARQL::Client
|
|
727
728
|
buffer << 'ORDER BY'
|
728
729
|
options[:order_by].map { |elem|
|
729
730
|
case elem
|
730
|
-
# .order_by({ :
|
731
|
+
# .order_by({ var1: :asc, var2: :desc})
|
731
732
|
when Hash
|
732
733
|
elem.each { |key, val|
|
733
734
|
# check provided values
|
@@ -14,9 +14,9 @@ class SPARQL::Client
|
|
14
14
|
def initialize(uri: nil, **options, &block)
|
15
15
|
raise ArgumentError, "uri is a required parameter" unless uri
|
16
16
|
@options = options.merge(uri: uri)
|
17
|
-
@update_client = SPARQL::Client.new(options.delete(:update_endpoint), options) if options[:update_endpoint]
|
18
|
-
@client = SPARQL::Client.new(uri, options)
|
19
|
-
super(
|
17
|
+
@update_client = SPARQL::Client.new(options.delete(:update_endpoint), **options) if options[:update_endpoint]
|
18
|
+
@client = SPARQL::Client.new(uri, **options)
|
19
|
+
super(**@options, &block)
|
20
20
|
end
|
21
21
|
|
22
22
|
##
|
@@ -115,7 +115,7 @@ class SPARQL::Client
|
|
115
115
|
# @see RDF::Repository#each_subject?
|
116
116
|
def each_subject(&block)
|
117
117
|
if block_given?
|
118
|
-
client.select(:s, :
|
118
|
+
client.select(:s, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:s]) }
|
119
119
|
end
|
120
120
|
enum_subject
|
121
121
|
end
|
@@ -129,7 +129,7 @@ class SPARQL::Client
|
|
129
129
|
# @see RDF::Repository#each_predicate?
|
130
130
|
def each_predicate(&block)
|
131
131
|
if block_given?
|
132
|
-
client.select(:p, :
|
132
|
+
client.select(:p, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:p]) }
|
133
133
|
end
|
134
134
|
enum_predicate
|
135
135
|
end
|
@@ -143,7 +143,7 @@ class SPARQL::Client
|
|
143
143
|
# @see RDF::Repository#each_object?
|
144
144
|
def each_object(&block)
|
145
145
|
if block_given?
|
146
|
-
client.select(:o, :
|
146
|
+
client.select(:o, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:o]) }
|
147
147
|
end
|
148
148
|
enum_object
|
149
149
|
end
|
@@ -262,10 +262,10 @@ class SPARQL::Client
|
|
262
262
|
# @return [void] ignored
|
263
263
|
# @see RDF::Queryable#query
|
264
264
|
# @see RDF::Query#execute
|
265
|
-
def query_execute(query, options
|
265
|
+
def query_execute(query, **options, &block)
|
266
266
|
return nil unless block_given?
|
267
|
-
q = SPARQL::Client::Query.select(query.variables).where(*query.patterns)
|
268
|
-
client.query(q, options).each do |solution|
|
267
|
+
q = SPARQL::Client::Query.select(query.variables, **{}).where(*query.patterns)
|
268
|
+
client.query(q, **options).each do |solution|
|
269
269
|
yield solution
|
270
270
|
end
|
271
271
|
end
|
@@ -275,7 +275,7 @@ class SPARQL::Client
|
|
275
275
|
#
|
276
276
|
# @example
|
277
277
|
# repository.query([nil, RDF::DOAP.developer, nil])
|
278
|
-
# repository.query(:
|
278
|
+
# repository.query({predicate: RDF::DOAP.developer})
|
279
279
|
#
|
280
280
|
# @todo This should use basic SPARQL query mechanism.
|
281
281
|
#
|
@@ -284,7 +284,7 @@ class SPARQL::Client
|
|
284
284
|
# @yield [statement]
|
285
285
|
# @yieldparam [Statement]
|
286
286
|
# @return [Enumerable<Statement>]
|
287
|
-
def query_pattern(pattern, options
|
287
|
+
def query_pattern(pattern, **options, &block)
|
288
288
|
pattern = pattern.dup
|
289
289
|
pattern.subject ||= RDF::Query::Variable.new
|
290
290
|
pattern.predicate ||= RDF::Query::Variable.new
|
data/lib/sparql/client/update.rb
CHANGED
@@ -12,12 +12,12 @@ class SPARQL::Client
|
|
12
12
|
# insert_data(data)
|
13
13
|
#
|
14
14
|
# @example INSERT DATA \{ GRAPH <http://example.org/> \{\}\}
|
15
|
-
# insert_data(RDF::Graph.new, :
|
15
|
+
# insert_data(RDF::Graph.new, graph: 'http://example.org/')
|
16
16
|
# insert_data(RDF::Graph.new).graph('http://example.org/')
|
17
17
|
#
|
18
18
|
# @param (see InsertData#initialize)
|
19
|
-
def self.insert_data(*arguments)
|
20
|
-
InsertData.new(*arguments)
|
19
|
+
def self.insert_data(*arguments, **options)
|
20
|
+
InsertData.new(*arguments, **options)
|
21
21
|
end
|
22
22
|
|
23
23
|
##
|
@@ -30,12 +30,12 @@ class SPARQL::Client
|
|
30
30
|
# delete_data(data)
|
31
31
|
#
|
32
32
|
# @example DELETE DATA \{ GRAPH <http://example.org/> \{\}\}
|
33
|
-
# delete_data(RDF::Graph.new, :
|
33
|
+
# delete_data(RDF::Graph.new, graph: 'http://example.org/')
|
34
34
|
# delete_data(RDF::Graph.new).graph('http://example.org/')
|
35
35
|
#
|
36
36
|
# @param (see DeleteData#initialize)
|
37
|
-
def self.delete_data(*arguments)
|
38
|
-
DeleteData.new(*arguments)
|
37
|
+
def self.delete_data(*arguments, **options)
|
38
|
+
DeleteData.new(*arguments, **options)
|
39
39
|
end
|
40
40
|
|
41
41
|
##
|
@@ -53,8 +53,8 @@ class SPARQL::Client
|
|
53
53
|
# load(RDF::URI(http://example.org/data.rdf), into: RDF::URI(http://example.org/data.rdf))
|
54
54
|
#
|
55
55
|
# @param (see Load#initialize)
|
56
|
-
def self.load(*arguments)
|
57
|
-
Load.new(*arguments)
|
56
|
+
def self.load(*arguments, **options)
|
57
|
+
Load.new(*arguments, **options)
|
58
58
|
end
|
59
59
|
|
60
60
|
##
|
@@ -81,8 +81,8 @@ class SPARQL::Client
|
|
81
81
|
# clear(:all, silent: true)
|
82
82
|
#
|
83
83
|
# @param (see Clear#initialize)
|
84
|
-
def self.clear(*arguments)
|
85
|
-
Clear.new(*arguments)
|
84
|
+
def self.clear(*arguments, **options)
|
85
|
+
Clear.new(*arguments, **options)
|
86
86
|
end
|
87
87
|
|
88
88
|
##
|
@@ -96,8 +96,8 @@ class SPARQL::Client
|
|
96
96
|
# create(RDF::URI(http://example.org/data.rdf), silent: true)
|
97
97
|
#
|
98
98
|
# @param (see Create#initialize)
|
99
|
-
def self.create(*arguments)
|
100
|
-
Create.new(*arguments)
|
99
|
+
def self.create(*arguments, **options)
|
100
|
+
Create.new(*arguments, **options)
|
101
101
|
end
|
102
102
|
|
103
103
|
##
|
@@ -124,15 +124,15 @@ class SPARQL::Client
|
|
124
124
|
# drop(:all, silent: true)
|
125
125
|
#
|
126
126
|
# @param (see Drop#initialize)
|
127
|
-
def self.drop(*arguments)
|
128
|
-
Drop.new(*arguments)
|
127
|
+
def self.drop(*arguments, **options)
|
128
|
+
Drop.new(*arguments, **options)
|
129
129
|
end
|
130
130
|
|
131
131
|
class Operation
|
132
132
|
attr_reader :options
|
133
133
|
|
134
|
-
def initialize(*arguments)
|
135
|
-
@options =
|
134
|
+
def initialize(*arguments, **options)
|
135
|
+
@options = options.dup
|
136
136
|
unless arguments.empty?
|
137
137
|
send(arguments.shift, *arguments)
|
138
138
|
end
|
@@ -171,9 +171,9 @@ class SPARQL::Client
|
|
171
171
|
#
|
172
172
|
# @param [Array<RDF::Statement>, RDF::Enumerable] data
|
173
173
|
# @param [Hash{Symbol => Object}] options
|
174
|
-
def initialize(data, options
|
174
|
+
def initialize(data, **options)
|
175
175
|
@data = data
|
176
|
-
super(options)
|
176
|
+
super(**options)
|
177
177
|
end
|
178
178
|
|
179
179
|
##
|
@@ -221,9 +221,9 @@ class SPARQL::Client
|
|
221
221
|
#
|
222
222
|
# @param [Array<RDF::Statement>, RDF::Enumerable] data
|
223
223
|
# @param [Hash{Symbol => Object}] options
|
224
|
-
def initialize(data, options
|
224
|
+
def initialize(data, **options)
|
225
225
|
@data = data
|
226
|
-
super(options)
|
226
|
+
super(**options)
|
227
227
|
end
|
228
228
|
|
229
229
|
##
|
@@ -253,11 +253,11 @@ class SPARQL::Client
|
|
253
253
|
attr_reader :delete_graph
|
254
254
|
attr_reader :where_graph
|
255
255
|
|
256
|
-
def initialize(_delete_graph, _insert_graph = nil, _where_graph = nil, options
|
256
|
+
def initialize(_delete_graph, _insert_graph = nil, _where_graph = nil, **options)
|
257
257
|
@delete_graph = _delete_graph
|
258
258
|
@insert_graph = _insert_graph
|
259
259
|
@where_graph = _where_graph
|
260
|
-
super(options)
|
260
|
+
super(**options)
|
261
261
|
end
|
262
262
|
|
263
263
|
##
|
@@ -324,11 +324,10 @@ class SPARQL::Client
|
|
324
324
|
# @param [Hash{Symbol => Object}] options
|
325
325
|
# @option [RDF::URI] :into
|
326
326
|
# @option [Boolean] :silent
|
327
|
-
def initialize(from, options
|
328
|
-
options = options.dup
|
327
|
+
def initialize(from, into: nil,**options)
|
329
328
|
@from = RDF::URI(from)
|
330
|
-
@into = RDF::URI(
|
331
|
-
super(options)
|
329
|
+
@into = RDF::URI(into) if into
|
330
|
+
super(**options)
|
332
331
|
end
|
333
332
|
|
334
333
|
##
|
@@ -420,9 +419,9 @@ class SPARQL::Client
|
|
420
419
|
attr_reader :uri
|
421
420
|
|
422
421
|
# @param [Hash{Symbol => Object}] options
|
423
|
-
def initialize(uri, options
|
422
|
+
def initialize(uri, **options)
|
424
423
|
@uri = RDF::URI(uri)
|
425
|
-
super(options)
|
424
|
+
super(**options)
|
426
425
|
end
|
427
426
|
|
428
427
|
def to_s
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparql-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-12-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rdf
|
@@ -18,118 +18,112 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3.
|
21
|
+
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '3.
|
28
|
+
version: '3.1'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: net-http-persistent
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - "
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '2.9'
|
36
|
-
- - "<"
|
33
|
+
- - "~>"
|
37
34
|
- !ruby/object:Gem::Version
|
38
|
-
version: '
|
35
|
+
version: '3.1'
|
39
36
|
type: :runtime
|
40
37
|
prerelease: false
|
41
38
|
version_requirements: !ruby/object:Gem::Requirement
|
42
39
|
requirements:
|
43
|
-
- - "
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '2.9'
|
46
|
-
- - "<"
|
40
|
+
- - "~>"
|
47
41
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
42
|
+
version: '3.1'
|
49
43
|
- !ruby/object:Gem::Dependency
|
50
44
|
name: rdf-spec
|
51
45
|
requirement: !ruby/object:Gem::Requirement
|
52
46
|
requirements:
|
53
47
|
- - "~>"
|
54
48
|
- !ruby/object:Gem::Version
|
55
|
-
version: '3.
|
49
|
+
version: '3.1'
|
56
50
|
type: :development
|
57
51
|
prerelease: false
|
58
52
|
version_requirements: !ruby/object:Gem::Requirement
|
59
53
|
requirements:
|
60
54
|
- - "~>"
|
61
55
|
- !ruby/object:Gem::Version
|
62
|
-
version: '3.
|
56
|
+
version: '3.1'
|
63
57
|
- !ruby/object:Gem::Dependency
|
64
58
|
name: sparql
|
65
59
|
requirement: !ruby/object:Gem::Requirement
|
66
60
|
requirements:
|
67
61
|
- - "~>"
|
68
62
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
63
|
+
version: '3.1'
|
70
64
|
type: :development
|
71
65
|
prerelease: false
|
72
66
|
version_requirements: !ruby/object:Gem::Requirement
|
73
67
|
requirements:
|
74
68
|
- - "~>"
|
75
69
|
- !ruby/object:Gem::Version
|
76
|
-
version: '3.
|
70
|
+
version: '3.1'
|
77
71
|
- !ruby/object:Gem::Dependency
|
78
72
|
name: rspec
|
79
73
|
requirement: !ruby/object:Gem::Requirement
|
80
74
|
requirements:
|
81
75
|
- - "~>"
|
82
76
|
- !ruby/object:Gem::Version
|
83
|
-
version: '3.
|
77
|
+
version: '3.9'
|
84
78
|
type: :development
|
85
79
|
prerelease: false
|
86
80
|
version_requirements: !ruby/object:Gem::Requirement
|
87
81
|
requirements:
|
88
82
|
- - "~>"
|
89
83
|
- !ruby/object:Gem::Version
|
90
|
-
version: '3.
|
84
|
+
version: '3.9'
|
91
85
|
- !ruby/object:Gem::Dependency
|
92
86
|
name: rspec-its
|
93
87
|
requirement: !ruby/object:Gem::Requirement
|
94
88
|
requirements:
|
95
89
|
- - "~>"
|
96
90
|
- !ruby/object:Gem::Version
|
97
|
-
version: '1.
|
91
|
+
version: '1.3'
|
98
92
|
type: :development
|
99
93
|
prerelease: false
|
100
94
|
version_requirements: !ruby/object:Gem::Requirement
|
101
95
|
requirements:
|
102
96
|
- - "~>"
|
103
97
|
- !ruby/object:Gem::Version
|
104
|
-
version: '1.
|
98
|
+
version: '1.3'
|
105
99
|
- !ruby/object:Gem::Dependency
|
106
100
|
name: webmock
|
107
101
|
requirement: !ruby/object:Gem::Requirement
|
108
102
|
requirements:
|
109
103
|
- - "~>"
|
110
104
|
- !ruby/object:Gem::Version
|
111
|
-
version: '3.
|
105
|
+
version: '3.7'
|
112
106
|
type: :development
|
113
107
|
prerelease: false
|
114
108
|
version_requirements: !ruby/object:Gem::Requirement
|
115
109
|
requirements:
|
116
110
|
- - "~>"
|
117
111
|
- !ruby/object:Gem::Version
|
118
|
-
version: '3.
|
112
|
+
version: '3.7'
|
119
113
|
- !ruby/object:Gem::Dependency
|
120
114
|
name: yard
|
121
115
|
requirement: !ruby/object:Gem::Requirement
|
122
116
|
requirements:
|
123
117
|
- - "~>"
|
124
118
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0.9.
|
119
|
+
version: 0.9.20
|
126
120
|
type: :development
|
127
121
|
prerelease: false
|
128
122
|
version_requirements: !ruby/object:Gem::Requirement
|
129
123
|
requirements:
|
130
124
|
- - "~>"
|
131
125
|
- !ruby/object:Gem::Version
|
132
|
-
version: 0.9.
|
126
|
+
version: 0.9.20
|
133
127
|
description: |-
|
134
128
|
Executes SPARQL queries and updates against a remote SPARQL 1.0 or 1.1 endpoint,
|
135
129
|
or against a local repository. Generates SPARQL queries using a simple DSL.
|
@@ -162,15 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
156
|
requirements:
|
163
157
|
- - ">="
|
164
158
|
- !ruby/object:Gem::Version
|
165
|
-
version: 2.
|
159
|
+
version: '2.4'
|
166
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
161
|
requirements:
|
168
162
|
- - ">="
|
169
163
|
- !ruby/object:Gem::Version
|
170
164
|
version: '0'
|
171
165
|
requirements: []
|
172
|
-
|
173
|
-
rubygems_version: 2.7.6
|
166
|
+
rubygems_version: 3.0.6
|
174
167
|
signing_key:
|
175
168
|
specification_version: 4
|
176
169
|
summary: SPARQL client for RDF.rb.
|