sparql-client 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24eb08925822a40dafa2fd3ddb20b5812bb0541f
4
- data.tar.gz: ecd254327832d34c3f6fea043d28fc7e17dab96d
3
+ metadata.gz: 38ac883367777a453e1af010eb241ee4c14ee3dc
4
+ data.tar.gz: 2b251fa756f8adb385e95394bb1497d917021340
5
5
  SHA512:
6
- metadata.gz: a8bc568e26de651c7d2402ecec14505328099fe72bd340e5b375df1b2db75cd194f230a0915a617b9255310ac07a87e60ba3ee10ca46197f8ec03687ae1995b4
7
- data.tar.gz: 4610e805ad5058e162ba2b58f4c60b9af78fd61e1474d4a32d74fe45373435dbc78493a81ce558be83cfdc76dcb05d3112478d5217e70f58e739058698fbd1f4
6
+ metadata.gz: 7a3044448b1e7e7bb252de265834bf76bedae8deafa28a1861a49d1b08e6ec9fd62d54e3c19b70a39cd76cd595e8e8d8524287aeb6ad751eff080e1ddeac5ec6
7
+ data.tar.gz: f4839f05b1441be9bde48f8e411d85ecd86c433b670da202c8a0ca0a3f62f6c931470438ca7f213cf6aacc144581806058f03380db418d875934208df7956693
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.4
1
+ 1.1.5
@@ -293,7 +293,12 @@ module SPARQL
293
293
  case @url
294
294
  when RDF::Queryable
295
295
  require 'sparql' unless defined?(::SPARQL::Grammar)
296
- SPARQL.execute(query, @url, options)
296
+ begin
297
+ SPARQL.execute(query, @url, options)
298
+ rescue SPARQL::MalformedQuery
299
+ $stderr.puts "error running #{query}: #{$!}"
300
+ raise
301
+ end
297
302
  else
298
303
  parse_response(response(query, options), options)
299
304
  end
@@ -315,7 +320,7 @@ module SPARQL
315
320
  case @url
316
321
  when RDF::Queryable
317
322
  require 'sparql' unless defined?(::SPARQL::Grammar)
318
- SPARQL.execute(query, @url, options)
323
+ SPARQL.execute(query, @url, options.merge(update: true))
319
324
  else
320
325
  parse_response(response(query, options), options)
321
326
  end
@@ -25,31 +25,6 @@ module SPARQL; class Client
25
25
  @update_client || @client
26
26
  end
27
27
 
28
- ##
29
- # Queries `self` using the given basic graph pattern (BGP) query,
30
- # yielding each matched solution to the given block.
31
- #
32
- # Overrides Queryable::query_execute to use SPARQL::Client::query
33
- #
34
- # @param [RDF::Query] query
35
- # the query to execute
36
- # @param [Hash{Symbol => Object}] options ({})
37
- # Any other options passed to `query.execute`
38
- # @yield [solution]
39
- # @yieldparam [RDF::Query::Solution] solution
40
- # @yieldreturn [void] ignored
41
- # @return [void] ignored
42
- # @see RDF::Queryable#query
43
- # @see RDF::Query#execute
44
- def query_execute(query, options = {}, &block)
45
- return nil unless block_given?
46
- q = SPARQL::Client::Query.select(query.variables).where(*query.patterns)
47
- client.query(q, options).each do |solution|
48
- yield solution
49
- end
50
- end
51
-
52
- ##
53
28
  # Enumerates each RDF statement in this repository.
54
29
  #
55
30
  # @yield [statement]
@@ -171,8 +146,8 @@ module SPARQL; class Client
171
146
  # @see RDF::Repository#count?
172
147
  def count
173
148
  begin
174
- binding = client.query("SELECT COUNT(*) WHERE { ?s ?p ?o }").first.to_hash
175
- binding[binding.keys.first].value.to_i
149
+ binding = client.query("SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }").first.to_hash
150
+ binding[:count].value.to_i rescue 0
176
151
  rescue SPARQL::Client::MalformedQuery => e
177
152
  # SPARQL 1.0 does not include support for aggregate functions:
178
153
  count = 0
@@ -193,35 +168,6 @@ module SPARQL; class Client
193
168
  client.ask.whether([:s, :p, :o]).false?
194
169
  end
195
170
 
196
- ##
197
- # Queries `self` for RDF statements matching the given `pattern`.
198
- #
199
- # @example
200
- # repository.query([nil, RDF::DOAP.developer, nil])
201
- # repository.query(:predicate => RDF::DOAP.developer)
202
- #
203
- # @fixme This should use basic SPARQL query mechanism.
204
- #
205
- # @param [Pattern] pattern
206
- # @see RDF::Queryable#query_pattern
207
- # @yield [statement]
208
- # @yieldparam [Statement]
209
- # @return [Enumerable<Statement>]
210
- def query_pattern(pattern, &block)
211
- pattern = pattern.dup
212
- pattern.subject ||= RDF::Query::Variable.new
213
- pattern.predicate ||= RDF::Query::Variable.new
214
- pattern.object ||= RDF::Query::Variable.new
215
- pattern.initialize!
216
- query = client.construct(pattern).where(pattern)
217
-
218
- if block_given?
219
- query.each_statement(&block)
220
- else
221
- query.solutions.to_a.extend(RDF::Enumerable, RDF::Queryable)
222
- end
223
- end
224
-
225
171
  ##
226
172
  # Returns `false` to indicate that this is a read-only repository.
227
173
  #
@@ -254,6 +200,59 @@ module SPARQL; class Client
254
200
 
255
201
  protected
256
202
 
203
+ ##
204
+ # Queries `self` using the given basic graph pattern (BGP) query,
205
+ # yielding each matched solution to the given block.
206
+ #
207
+ # Overrides Queryable::query_execute to use SPARQL::Client::query
208
+ #
209
+ # @param [RDF::Query] query
210
+ # the query to execute
211
+ # @param [Hash{Symbol => Object}] options ({})
212
+ # Any other options passed to `query.execute`
213
+ # @yield [solution]
214
+ # @yieldparam [RDF::Query::Solution] solution
215
+ # @yieldreturn [void] ignored
216
+ # @return [void] ignored
217
+ # @see RDF::Queryable#query
218
+ # @see RDF::Query#execute
219
+ def query_execute(query, options = {}, &block)
220
+ return nil unless block_given?
221
+ q = SPARQL::Client::Query.select(query.variables).where(*query.patterns)
222
+ client.query(q, options).each do |solution|
223
+ yield solution
224
+ end
225
+ end
226
+
227
+ ##
228
+ # Queries `self` for RDF statements matching the given `pattern`.
229
+ #
230
+ # @example
231
+ # repository.query([nil, RDF::DOAP.developer, nil])
232
+ # repository.query(:predicate => RDF::DOAP.developer)
233
+ #
234
+ # @fixme This should use basic SPARQL query mechanism.
235
+ #
236
+ # @param [Pattern] pattern
237
+ # @see RDF::Queryable#query_pattern
238
+ # @yield [statement]
239
+ # @yieldparam [Statement]
240
+ # @return [Enumerable<Statement>]
241
+ def query_pattern(pattern, &block)
242
+ pattern = pattern.dup
243
+ pattern.subject ||= RDF::Query::Variable.new
244
+ pattern.predicate ||= RDF::Query::Variable.new
245
+ pattern.object ||= RDF::Query::Variable.new
246
+ pattern.initialize!
247
+ query = client.construct(pattern).where(pattern)
248
+
249
+ if block_given?
250
+ query.each_statement(&block)
251
+ else
252
+ query.solutions.to_a.extend(RDF::Enumerable, RDF::Queryable)
253
+ end
254
+ end
255
+
257
256
  ##
258
257
  # Deletes the given RDF statements from the underlying storage.
259
258
  #
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: 1.1.4
4
+ version: 1.1.5
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: 2015-03-04 00:00:00.000000000 Z
13
+ date: 2015-05-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
@@ -47,6 +47,9 @@ dependencies:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.6
50
53
  type: :development
51
54
  prerelease: false
52
55
  version_requirements: !ruby/object:Gem::Requirement
@@ -54,6 +57,9 @@ dependencies:
54
57
  - - "~>"
55
58
  - !ruby/object:Gem::Version
56
59
  version: '1.1'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.1.6
57
63
  - !ruby/object:Gem::Dependency
58
64
  name: rdf-spec
59
65
  requirement: !ruby/object:Gem::Requirement