sparql-client 2.1.0 → 3.1.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.
@@ -1,4 +1,4 @@
1
- module SPARQL; class Client
1
+ class SPARQL::Client
2
2
  ##
3
3
  # A read-only repository view of a SPARQL endpoint.
4
4
  #
@@ -10,14 +10,13 @@ module SPARQL; class Client
10
10
  ##
11
11
  # @param [URI, #to_s] uri
12
12
  # Endpoint of this repository
13
- # @param [String, #to_s] title (nil)
14
13
  # @param [Hash{Symbol => Object}] options passed to RDF::Repository
15
14
  def initialize(uri: nil, **options, &block)
16
15
  raise ArgumentError, "uri is a required parameter" unless uri
17
16
  @options = options.merge(uri: uri)
18
- @update_client = SPARQL::Client.new(options.delete(:update_endpoint), options) if options[:update_endpoint]
19
- @client = SPARQL::Client.new(uri, options)
20
- super(@options, &block)
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)
21
20
  end
22
21
 
23
22
  ##
@@ -38,6 +37,30 @@ module SPARQL; class Client
38
37
  client.construct([:s, :p, :o]).where([:s, :p, :o]).each_statement(&block)
39
38
  end
40
39
 
40
+ ##
41
+ # Iterates the given block for each RDF statement.
42
+ #
43
+ # If no block was given, returns an enumerator.
44
+ #
45
+ # The order in which statements are yielded is undefined.
46
+ #
47
+ # @overload each_statement
48
+ # @yield [statement]
49
+ # each statement
50
+ # @yieldparam [RDF::Statement] statement
51
+ # @yieldreturn [void] ignored
52
+ # @return [void]
53
+ #
54
+ # @overload each_statement
55
+ # @return [Enumerator<RDF::Statement>]
56
+ def each_statement(&block)
57
+ if block_given?
58
+ # Invoke {#each} in the containing class:
59
+ each(&block)
60
+ end
61
+ enum_statement
62
+ end
63
+
41
64
  ##
42
65
  # @private
43
66
  # @see RDF::Enumerable#supports?
@@ -48,6 +71,7 @@ module SPARQL; class Client
48
71
  when :graph_name then false
49
72
  when :inference then false # forward-chaining inference
50
73
  when :validity then false
74
+ when :literal_equality then true
51
75
  else false
52
76
  end
53
77
  end
@@ -91,7 +115,7 @@ module SPARQL; class Client
91
115
  # @see RDF::Repository#each_subject?
92
116
  def each_subject(&block)
93
117
  if block_given?
94
- client.select(:s, :distinct => true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:s]) }
118
+ client.select(:s, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:s]) }
95
119
  end
96
120
  enum_subject
97
121
  end
@@ -105,7 +129,7 @@ module SPARQL; class Client
105
129
  # @see RDF::Repository#each_predicate?
106
130
  def each_predicate(&block)
107
131
  if block_given?
108
- client.select(:p, :distinct => true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:p]) }
132
+ client.select(:p, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:p]) }
109
133
  end
110
134
  enum_predicate
111
135
  end
@@ -119,7 +143,7 @@ module SPARQL; class Client
119
143
  # @see RDF::Repository#each_object?
120
144
  def each_object(&block)
121
145
  if block_given?
122
- client.select(:o, :distinct => true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:o]) }
146
+ client.select(:o, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:o]) }
123
147
  end
124
148
  enum_object
125
149
  end
@@ -151,13 +175,11 @@ module SPARQL; class Client
151
175
  # @see RDF::Repository#count?
152
176
  def count
153
177
  begin
154
- binding = client.query("SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }").first.to_hash
178
+ binding = client.query("SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }").first.to_h
155
179
  binding[:count].value.to_i rescue 0
156
180
  rescue SPARQL::Client::MalformedQuery => e
157
181
  # SPARQL 1.0 does not include support for aggregate functions:
158
- count = 0
159
- each_statement { count += 1 } # TODO: optimize this
160
- count
182
+ each_statement.count
161
183
  end
162
184
  end
163
185
 
@@ -238,10 +260,12 @@ module SPARQL; class Client
238
260
  # @return [void] ignored
239
261
  # @see RDF::Queryable#query
240
262
  # @see RDF::Query#execute
241
- def query_execute(query, options = {}, &block)
263
+ def query_execute(query, **options, &block)
242
264
  return nil unless block_given?
243
- q = SPARQL::Client::Query.select(query.variables).where(*query.patterns)
244
- client.query(q, options).each do |solution|
265
+ q = SPARQL::Client::Query.
266
+ select(query.variables, **{}).
267
+ where(*query.patterns)
268
+ client.query(q, **options).each do |solution|
245
269
  yield solution
246
270
  end
247
271
  end
@@ -251,7 +275,7 @@ module SPARQL; class Client
251
275
  #
252
276
  # @example
253
277
  # repository.query([nil, RDF::DOAP.developer, nil])
254
- # repository.query(:predicate => RDF::DOAP.developer)
278
+ # repository.query({predicate: RDF::DOAP.developer})
255
279
  #
256
280
  # @todo This should use basic SPARQL query mechanism.
257
281
  #
@@ -260,7 +284,7 @@ module SPARQL; class Client
260
284
  # @yield [statement]
261
285
  # @yieldparam [Statement]
262
286
  # @return [Enumerable<Statement>]
263
- def query_pattern(pattern, options = {}, &block)
287
+ def query_pattern(pattern, **options, &block)
264
288
  pattern = pattern.dup
265
289
  pattern.subject ||= RDF::Query::Variable.new
266
290
  pattern.predicate ||= RDF::Query::Variable.new
@@ -321,4 +345,4 @@ module SPARQL; class Client
321
345
  end
322
346
 
323
347
  end
324
- end; end
348
+ end
@@ -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, :graph => 'http://example.org/')
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, :graph => 'http://example.org/')
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,12 +53,12 @@ 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
  ##
61
- # Load statements into the graph
61
+ # Clear the graph
62
62
  #
63
63
  # @example CLEAR GRAPH <http://example.org/data.rdf>
64
64
  # clear.graph(RDF::URI(http://example.org/data.rdf))
@@ -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 = arguments.last.is_a?(Hash) ? arguments.pop.dup : {}
134
+ def initialize(*arguments, **options)
135
+ @options = options.dup
136
136
  unless arguments.empty?
137
137
  send(arguments.shift, *arguments)
138
138
  end
@@ -155,7 +155,7 @@ class SPARQL::Client
155
155
  end
156
156
 
157
157
  ##
158
- # @see http://www.w3.org/TR/sparql11-update/#insertData
158
+ # @see https://www.w3.org/TR/sparql11-update/#insertData
159
159
  class InsertData < Operation
160
160
  # @return [RDF::Enumerable]
161
161
  attr_reader :data
@@ -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
  ##
@@ -205,7 +205,7 @@ class SPARQL::Client
205
205
  end
206
206
 
207
207
  ##
208
- # @see http://www.w3.org/TR/sparql11-update/#deleteData
208
+ # @see https://www.w3.org/TR/sparql11-update/#deleteData
209
209
  class DeleteData < Operation
210
210
  # @return [RDF::Enumerable]
211
211
  attr_reader :data
@@ -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
  ##
@@ -247,17 +247,17 @@ class SPARQL::Client
247
247
  end
248
248
 
249
249
  ##
250
- # @see http://www.w3.org/TR/sparql11-update/#deleteInsert
250
+ # @see https://www.w3.org/TR/sparql11-update/#deleteInsert
251
251
  class DeleteInsert < Operation
252
252
  attr_reader :insert_graph
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
  ##
@@ -301,7 +301,7 @@ class SPARQL::Client
301
301
  end
302
302
 
303
303
  ##
304
- # @see http://www.w3.org/TR/sparql11-update/#load
304
+ # @see https://www.w3.org/TR/sparql11-update/#load
305
305
  class Load < Operation
306
306
  attr_reader :from
307
307
  attr_reader :into
@@ -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(options.delete(:into)) if options[:into]
331
- super(options)
329
+ @into = RDF::URI(into) if into
330
+ super(**options)
332
331
  end
333
332
 
334
333
  ##
@@ -351,7 +350,7 @@ class SPARQL::Client
351
350
  end
352
351
 
353
352
  ##
354
- # @see http://www.w3.org/TR/sparql11-update/#clear
353
+ # @see https://www.w3.org/TR/sparql11-update/#clear
355
354
  class Clear < Operation
356
355
  attr_reader :uri
357
356
 
@@ -415,14 +414,14 @@ class SPARQL::Client
415
414
  end
416
415
 
417
416
  ##
418
- # @see http://www.w3.org/TR/sparql11-update/#create
417
+ # @see https://www.w3.org/TR/sparql11-update/#create
419
418
  class Create < Operation
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
@@ -434,7 +433,7 @@ class SPARQL::Client
434
433
  end
435
434
 
436
435
  ##
437
- # @see http://www.w3.org/TR/sparql11-update/#drop
436
+ # @see https://www.w3.org/TR/sparql11-update/#drop
438
437
  class Drop < Clear
439
438
  def to_s
440
439
  query_text = 'DROP '
@@ -451,7 +450,7 @@ class SPARQL::Client
451
450
  end
452
451
 
453
452
  ##
454
- # @see http://www.w3.org/TR/sparql11-update/#copy
453
+ # @see https://www.w3.org/TR/sparql11-update/#copy
455
454
  class Copy < Operation
456
455
  def to_s
457
456
  # TODO
@@ -459,7 +458,7 @@ class SPARQL::Client
459
458
  end
460
459
 
461
460
  ##
462
- # @see http://www.w3.org/TR/sparql11-update/#move
461
+ # @see https://www.w3.org/TR/sparql11-update/#move
463
462
  class Move < Operation
464
463
  def to_s
465
464
  # TODO
@@ -467,7 +466,7 @@ class SPARQL::Client
467
466
  end
468
467
 
469
468
  ##
470
- # @see http://www.w3.org/TR/sparql11-update/#add
469
+ # @see https://www.w3.org/TR/sparql11-update/#add
471
470
  class Add < Operation
472
471
  def to_s
473
472
  # TODO
@@ -1,4 +1,4 @@
1
- module SPARQL; class Client
1
+ class SPARQL::Client
2
2
  module VERSION
3
3
  FILE = File.expand_path('../../../../VERSION', __FILE__)
4
4
  MAJOR, MINOR, TINY, EXTRA = File.read(FILE).chomp.split('.')
@@ -16,4 +16,4 @@ module SPARQL; class Client
16
16
  # @return [Array(Integer, Integer, Integer)]
17
17
  def self.to_a() [MAJOR, MINOR, TINY] end
18
18
  end
19
- end; end
19
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparql-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
8
8
  - Ben Lavender
9
9
  - Gregg Kellogg
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-06 00:00:00.000000000 Z
13
+ date: 2020-12-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
@@ -18,112 +18,112 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '2.0'
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: '2.0'
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
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '2.9'
35
+ version: '4.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '2.9'
42
+ version: '4.0'
43
43
  - !ruby/object:Gem::Dependency
44
- name: sparql
44
+ name: rdf-spec
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '2.0'
49
+ version: '3.1'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '2.0'
56
+ version: '3.1'
57
57
  - !ruby/object:Gem::Dependency
58
- name: rdf-spec
58
+ name: sparql
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '2.0'
63
+ version: '3.1'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '2.0'
70
+ version: '3.1'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: '3.4'
77
+ version: '3.10'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: '3.4'
84
+ version: '3.10'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rspec-its
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: '1.2'
91
+ version: '1.3'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: '1.2'
98
+ version: '1.3'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: webmock
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: '1.15'
105
+ version: '3.11'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: '1.15'
112
+ version: '3.11'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: yard
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: '0.8'
119
+ version: '0.9'
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - "~>"
125
125
  - !ruby/object:Gem::Version
126
- version: '0.8'
126
+ version: '0.9'
127
127
  description: |-
128
128
  Executes SPARQL queries and updates against a remote SPARQL 1.0 or 1.1 endpoint,
129
129
  or against a local repository. Generates SPARQL queries using a simple DSL.
@@ -144,11 +144,11 @@ files:
144
144
  - lib/sparql/client/repository.rb
145
145
  - lib/sparql/client/update.rb
146
146
  - lib/sparql/client/version.rb
147
- homepage: http://ruby-rdf.github.com/sparql-client/
147
+ homepage: https://github.com/ruby-rdf/sparql-client/
148
148
  licenses:
149
149
  - Unlicense
150
150
  metadata: {}
151
- post_install_message:
151
+ post_install_message:
152
152
  rdoc_options: []
153
153
  require_paths:
154
154
  - lib
@@ -156,16 +156,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 2.2.2
159
+ version: '2.4'
160
160
  required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - ">="
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubyforge_project: sparql-client
167
- rubygems_version: 2.5.1
168
- signing_key:
166
+ rubygems_version: 3.1.4
167
+ signing_key:
169
168
  specification_version: 4
170
169
  summary: SPARQL client for RDF.rb.
171
170
  test_files: []