sparql-client 1.0.3 → 1.0.4

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDg1MzljNzgxZjQ1N2NhZDYyMzdmN2FkMDZlNTIzNmNjMTE4YTE5ZA==
5
- data.tar.gz: !binary |-
6
- MTRlMmZhYmVlMmI3MzdiMzlmNzUwMjYyYjcwYzE5ZTU0MWVhMGZmOA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MGYxMDJjM2EwYTRiZjhmNTEzNjVjZTNhODNlZDM2N2QwYThmYjRhZmFkNTUy
10
- YjJjZjQ2MjQ0NGQyYjM4MjgxYmM0NTI2ZmZlZGRlYWRjYTRiYzNkYjU1YmY4
11
- NmQ3YTAxN2YxNDZlZmRjMTgwMDY0NmRmYjVjMjRlMjY4YTVlYzU=
12
- data.tar.gz: !binary |-
13
- YTY4MjMyY2Q1MDQ1YzFlMDE5ZjJlOTViYjZjYmQ2N2FmMjM1ZDgzMjM0NmY5
14
- MWVlZGE2OTZjZDE0ZWQ0NmU5ZWY4ZDA2MDc4YmViOGI4ZDA3YmIwNzA0YTYz
15
- YTVjYTljMzRjYzA4ZTBjYzBlZmRjNmM1MTQ4NGIwMWM1ZGQwM2E=
2
+ SHA1:
3
+ metadata.gz: 2d31d814fef5e463320af4f8bd59b3975142abf0
4
+ data.tar.gz: 201eb51ea4db458cc6efe7ed1387f6c2ab17e1dc
5
+ SHA512:
6
+ metadata.gz: e01c39d5d56685eda053d1440a20b5286fa524276fd28993d5982b9ee1c93a4f756042d7d7e1ede8549a529b6d5f455df198d9caa99ffd31393f78ae7808cc5f
7
+ data.tar.gz: 066041570ba8b15393f9d036cf042feaaa8146e31105a63abc8b5e9e7a302ff468b4429d248ceea209e6697d1f581f1a2daadd5422cfa1cb2dc25b9c71863195
data/README CHANGED
@@ -9,7 +9,8 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
9
9
 
10
10
  ##Features
11
11
 
12
- * Executes queries against any SPARQL 1.0-compatible endpoint over HTTP.
12
+ * Executes queries against any SPARQL 1.0/1.1-compatible endpoint over HTTP,
13
+ or against an `RDF::Queryable` instance, using the `SPARQL` gem.
13
14
  * Provides a query builder [DSL][] for `ASK`, `SELECT`, `DESCRIBE` and
14
15
  `CONSTRUCT` queries.
15
16
  * Includes preliminary support for some SPARQL 1.1 Update operations.
@@ -22,10 +23,18 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
22
23
 
23
24
  ##Examples
24
25
 
26
+ ### Querying a remote SPARQL endpoint
25
27
  require 'sparql/client'
26
28
 
27
29
  sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
28
30
 
31
+ ### Querying a `RDF::Repository` instance
32
+
33
+ require 'rdf/trig'
34
+ repository = RDF::Repository.load("http://example/dataset.trig")
35
+
36
+ sparql = SPARQL::Client.new(repository)
37
+
29
38
  ### Executing a boolean query and outputting the result
30
39
 
31
40
  # ASK WHERE { ?s ?p ?o }
@@ -69,6 +78,7 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
69
78
  * [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.0)
70
79
  * [Net::HTTP::Persistent](http://rubygems.org/gems/net-http-persistent) (>= 1.4)
71
80
  * [JSON](http://rubygems.org/gems/json_pure) (>= 1.4)
81
+ * Soft dependency on [SPARQL](http://rubygems.org/gems/sparql) (>= 1.0)
72
82
 
73
83
  ##Installation
74
84
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
data/lib/sparql/client.rb CHANGED
@@ -9,6 +9,7 @@ module SPARQL
9
9
  # @see http://www.w3.org/TR/sparql11-query/
10
10
  # @see http://www.w3.org/TR/sparql11-protocol/
11
11
  # @see http://www.w3.org/TR/sparql11-results-json/
12
+ # @see http://www.w3.org/TR/sparql11-results-csv-tsv/
12
13
  class Client
13
14
  autoload :Query, 'sparql/client/query'
14
15
  autoload :Repository, 'sparql/client/repository'
@@ -21,19 +22,23 @@ module SPARQL
21
22
 
22
23
  RESULT_JSON = 'application/sparql-results+json'.freeze
23
24
  RESULT_XML = 'application/sparql-results+xml'.freeze
25
+ RESULT_CSV = 'text/csv'.freeze
26
+ RESULT_TSV = 'text/tab-separated-values'.freeze
24
27
  RESULT_BOOL = 'text/boolean'.freeze # Sesame-specific
25
28
  RESULT_BRTR = 'application/x-binary-rdf-results-table'.freeze # Sesame-specific
26
29
  ACCEPT_JSON = {'Accept' => RESULT_JSON}.freeze
27
30
  ACCEPT_XML = {'Accept' => RESULT_XML}.freeze
31
+ ACCEPT_CSV = {'Accept' => RESULT_CSV}.freeze
32
+ ACCEPT_TSV = {'Accept' => RESULT_TSV}.freeze
28
33
  ACCEPT_BRTR = {'Accept' => RESULT_BRTR}.freeze
29
34
 
30
35
  DEFAULT_PROTOCOL = 1.0
31
36
  DEFAULT_METHOD = :post
32
37
 
33
38
  ##
34
- # The SPARQL endpoint URL.
39
+ # The SPARQL endpoint URL, or an RDF::Queryable instance, to use the native SPARQL engine.
35
40
  #
36
- # @return [RDF::URI]
41
+ # @return [RDF::URI, RDF::Queryable]
37
42
  attr_reader :url
38
43
 
39
44
  ##
@@ -49,17 +54,27 @@ module SPARQL
49
54
  attr_reader :options
50
55
 
51
56
  ##
52
- # @param [String, #to_s] url
57
+ # Initialize a new sparql client, either using the URL of
58
+ # a SPARQL endpoint or an `RDF::Queryable` instance to use
59
+ # the native SPARQL gem.
60
+ #
61
+ # @param [String, RDF::Queryable, #to_s] url
62
+ # URL of endpoint, or queryable object.
53
63
  # @param [Hash{Symbol => Object}] options
54
64
  # @option options [Symbol] :method (DEFAULT_METHOD)
55
65
  # @option options [Number] :protocol (DEFAULT_PROTOCOL)
56
66
  # @option options [Hash] :headers
57
67
  def initialize(url, options = {}, &block)
58
- @url, @options = RDF::URI.new(url.to_s), options.dup
59
- @headers = {
60
- 'Accept' => [RESULT_JSON, RESULT_XML, RDF::Format.content_types.keys.map(&:to_s)].join(', ')
61
- }.merge(@options.delete(:headers) || {})
62
- @http = http_klass(@url.scheme)
68
+ case url
69
+ when RDF::Queryable
70
+ @url, @options = url, options.dup
71
+ else
72
+ @url, @options = RDF::URI.new(url.to_s), options.dup
73
+ @headers = {
74
+ 'Accept' => [RESULT_JSON, RESULT_XML, "#{RESULT_TSV};p=0.8", "#{RESULT_CSV};p=0.2", RDF::Format.content_types.keys.map(&:to_s)].join(', ')
75
+ }.merge(@options.delete(:headers) || {})
76
+ @http = http_klass(@url.scheme)
77
+ end
63
78
 
64
79
  if block_given?
65
80
  case block.arity
@@ -190,10 +205,19 @@ module SPARQL
190
205
  # @example `CLEAR ALL`
191
206
  # client.clear(:all)
192
207
  #
193
- # @param [Symbol, #to_sym] what
194
- # @param [Hash{Symbol => Object}] options
195
- # @option options [Boolean] :silent
196
- # @return [void] `self`
208
+ # @overload clear(what, *arguments)
209
+ # @param [Symbol, #to_sym] what
210
+ # @param [Array] arguments splat of other arguments to {Update::Clear}.
211
+ # @option options [Boolean] :silent
212
+ # @return [void] `self`
213
+ #
214
+ # @overload clear(what, *arguments, options = {})
215
+ # @param [Symbol, #to_sym] what
216
+ # @param [Array] arguments splat of other arguments to {Update::Clear}.
217
+ # @param [Hash{Symbol => Object}] options
218
+ # @option options [Boolean] :silent
219
+ # @return [void] `self`
220
+ #
197
221
  # @see http://www.w3.org/TR/sparql11-update/#clear
198
222
  def clear(what, *arguments)
199
223
  self.update(Update::Clear.new(what, *arguments))
@@ -229,7 +253,13 @@ module SPARQL
229
253
  # @see http://www.w3.org/TR/sparql11-protocol/#query-operation
230
254
  def query(query, options = {})
231
255
  @op = :query
232
- parse_response(response(query, options), options)
256
+ case @url
257
+ when RDF::Queryable
258
+ require 'sparql' unless defined?(:SPARQL)
259
+ SPARQL.execute(query, @url, options)
260
+ else
261
+ parse_response(response(query, options), options)
262
+ end
233
263
  end
234
264
 
235
265
  ##
@@ -243,7 +273,13 @@ module SPARQL
243
273
  # @see http://www.w3.org/TR/sparql11-protocol/#update-operation
244
274
  def update(query, options = {})
245
275
  @op = :update
246
- parse_response(response(query, options), options)
276
+ case @url
277
+ when RDF::Queryable
278
+ require 'sparql' unless defined?(:SPARQL)
279
+ SPARQL.execute(query, @url, options)
280
+ else
281
+ parse_response(response(query, options), options)
282
+ end
247
283
  self
248
284
  end
249
285
 
@@ -285,6 +321,10 @@ module SPARQL
285
321
  self.class.parse_json_bindings(response.body, nodes)
286
322
  when RESULT_XML
287
323
  self.class.parse_xml_bindings(response.body, nodes)
324
+ when RESULT_CSV
325
+ self.class.parse_csv_bindings(response.body, nodes)
326
+ when RESULT_TSV
327
+ self.class.parse_tsv_bindings(response.body, nodes)
288
328
  else
289
329
  parse_rdf_serialization(response, options)
290
330
  end
@@ -134,7 +134,8 @@ module SPARQL; class Client
134
134
  end
135
135
 
136
136
  ##
137
- # @param [Array<RDF::Query::Pattern, Array>] patterns
137
+ # @param [Array<RDF::Query::Pattern, Array>] patterns_queries
138
+ # splat of zero or more patterns followed by zero or more queries.
138
139
  # @return [Query]
139
140
  # @see http://www.w3.org/TR/sparql11-query/#GraphPattern
140
141
  def where(*patterns_queries)
@@ -263,6 +264,7 @@ module SPARQL; class Client
263
264
  def true?
264
265
  case result
265
266
  when TrueClass, FalseClass then result
267
+ when RDF::Literal::Boolean then result.true?
266
268
  when Enumerable then !result.empty?
267
269
  else false
268
270
  end
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.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,93 +10,95 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-18 00:00:00.000000000 Z
13
+ date: 2013-06-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ! '>='
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.0'
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
28
  version: '1.0'
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
35
  version: '1.4'
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
42
  version: '1.4'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: json_pure
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ! '>='
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '1.4'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ! '>='
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '1.4'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rdf-spec
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ! '>='
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '1.0'
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
70
  version: '1.0'
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
77
  version: '2.12'
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
84
  version: '2.12'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: yard
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ! '>='
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0.8'
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
98
  version: '0.8'
99
- description: SPARQL client for RDF.rb.
99
+ description: |-
100
+ Executes SPARQL queries and updates against a remote SPARQL 1.0 or 1.1 endpoint,
101
+ or against a local repository. Generates SPARQL queries using a simple DSL.
100
102
  email: public-rdf-ruby@w3.org
101
103
  executables: []
102
104
  extensions: []
@@ -122,16 +124,16 @@ require_paths:
122
124
  - lib
123
125
  required_ruby_version: !ruby/object:Gem::Requirement
124
126
  requirements:
125
- - - ! '>='
127
+ - - '>='
126
128
  - !ruby/object:Gem::Version
127
129
  version: 1.8.1
128
130
  required_rubygems_version: !ruby/object:Gem::Requirement
129
131
  requirements:
130
- - - ! '>='
132
+ - - '>='
131
133
  - !ruby/object:Gem::Version
132
134
  version: '0'
133
135
  requirements: []
134
- rubyforge_project: sparql
136
+ rubyforge_project: sparql-client
135
137
  rubygems_version: 2.0.3
136
138
  signing_key:
137
139
  specification_version: 4