sparql-client 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -46
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/lib/sparql/client.rb +27 -27
- data/lib/sparql/client/query.rb +33 -31
- data/lib/sparql/client/repository.rb +4 -4
- data/lib/sparql/client/update.rb +10 -10
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b464200c11f2c711f8fae5cb6d75a2deea216a2d682246b7b74ba8316c515404
|
4
|
+
data.tar.gz: 63822682605b809841d008beee3599c81caa72df9d6d7c1004f9e7e1f136ed34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da4608ed0bc2c17af4bc7eba4c9c82f0be8095174fb18e8ec455441622a7efd3782e375f85eb8200b51617472fa0a6a94d0c7352e21e00e07dc21b1ec2709e23
|
7
|
+
data.tar.gz: 1c78bbf4de5d7c6a30126938813991175598084ef19ebd38b3bd20d941ea8ab1b94cc347f3a7a1a2d7238745c2589ef173974e300edbb581f53e072c9b637724
|
data/README.md
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
|
4
4
|
|
5
|
-
* <
|
5
|
+
* <https://ruby-rdf.github.com/sparql-client/>
|
6
6
|
|
7
|
-
[![Gem Version](https://badge.fury.io/rb/sparql-client.png)](
|
8
|
-
[![Build Status](https://
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/sparql-client.png)](https://badge.fury.io/rb/sparql-client)
|
8
|
+
[![Build Status](https://github.com/ruby-rdf/sparql-client/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/sparql-client/actions?query=workflow%3ACI)
|
9
9
|
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/sparql-client/badge.svg?branch=master&service=github)](https://coveralls.io/github/ruby-rdf/sparql-client?branch=master)
|
10
|
+
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
|
10
11
|
|
11
12
|
## Features
|
12
13
|
|
@@ -18,7 +19,7 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
|
|
18
19
|
* Supports tuple result sets in both XML, JSON, CSV and TSV formats, with JSON being
|
19
20
|
the preferred default for content-negotiation purposes.
|
20
21
|
* Supports graph results in any RDF serialization format understood by RDF.rb.
|
21
|
-
* Returns results using the
|
22
|
+
* Returns results using the RDF.rb object model.
|
22
23
|
* Supports accessing endpoints as read/write [`RDF::Repository`][RDF::Repository]
|
23
24
|
instances {SPARQL::Client::Repository}.
|
24
25
|
|
@@ -123,15 +124,15 @@ sparql.delete_data(data)
|
|
123
124
|
|
124
125
|
## Dependencies
|
125
126
|
|
126
|
-
* [Ruby](
|
127
|
-
* [RDF.rb](
|
128
|
-
* [Net::HTTP::Persistent](
|
129
|
-
* Soft dependency on [SPARQL](
|
130
|
-
* Soft dependency on [Nokogiri](
|
127
|
+
* [Ruby](https://ruby-lang.org/) (>= 2.4)
|
128
|
+
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.1)
|
129
|
+
* [Net::HTTP::Persistent](https://rubygems.org/gems/net-http-persistent) (~> 3.1)
|
130
|
+
* Soft dependency on [SPARQL](https://rubygems.org/gems/sparql) (~> 3.1)
|
131
|
+
* Soft dependency on [Nokogiri](https://rubygems.org/gems/nokogiri) (>= 1.10)
|
131
132
|
|
132
133
|
## Installation
|
133
134
|
|
134
|
-
The recommended installation method is via [RubyGems](
|
135
|
+
The recommended installation method is via [RubyGems](https://rubygems.org/).
|
135
136
|
To install the latest official release of the `SPARQL::Client` gem, do:
|
136
137
|
|
137
138
|
% [sudo] gem install sparql-client
|
@@ -145,31 +146,31 @@ To get a local working copy of the development repository, do:
|
|
145
146
|
Alternatively, download the latest development version as a tarball as
|
146
147
|
follows:
|
147
148
|
|
148
|
-
% wget
|
149
|
+
% wget https://github.com/ruby-rdf/sparql-client/tarball/master
|
149
150
|
|
150
151
|
## Mailing List
|
151
152
|
|
152
|
-
* <
|
153
|
+
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
153
154
|
|
154
155
|
## Authors
|
155
156
|
|
156
|
-
* [Arto Bendiken](
|
157
|
-
* [Ben Lavender](
|
158
|
-
* [Gregg Kellogg](
|
157
|
+
* [Arto Bendiken](https://github.com/artob) - <https://ar.to/>
|
158
|
+
* [Ben Lavender](https://github.com/bhuga) - <https://bhuga.net/>
|
159
|
+
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
|
159
160
|
|
160
161
|
## Contributors
|
161
162
|
|
162
|
-
* [Christoph Badura](
|
163
|
-
* [James Hetherington](
|
164
|
-
* [Gabriel Horner](
|
165
|
-
* [Nicholas Humfrey](
|
166
|
-
* [Fumihiro Kato](
|
167
|
-
* [David Nielsen](
|
168
|
-
* [Thamaraiselvan Poomalai](
|
169
|
-
* [Michael Sokol](
|
170
|
-
* [Yves Raimond](
|
171
|
-
* [Thomas Feron](
|
172
|
-
* [Nick Gottlieb](
|
163
|
+
* [Christoph Badura](https://github.com/bad) - <https://github.com/bad>
|
164
|
+
* [James Hetherington](https://github.com/jamespjh) - <https://twitter.com/jamespjh>
|
165
|
+
* [Gabriel Horner](https://github.com/cldwalker) - <https://tagaholic.me/>
|
166
|
+
* [Nicholas Humfrey](https://github.com/njh) - <https://www.aelius.com/njh/>
|
167
|
+
* [Fumihiro Kato](https://github.com/fumi) - <https://fumi.me/>
|
168
|
+
* [David Nielsen](https://github.com/drankard) - <https://github.com/drankard>
|
169
|
+
* [Thamaraiselvan Poomalai](https://github.com/selvan) - <https://softonaut.blogspot.com/>
|
170
|
+
* [Michael Sokol](https://github.com/mikaa123) - <https://sokolmichael.com/>
|
171
|
+
* [Yves Raimond](https://github.com/moustaki) - <https://moustaki.org/>
|
172
|
+
* [Thomas Feron](https://github.com/thoferon) - <https://github.com/thoferon>
|
173
|
+
* [Nick Gottlieb](https://github.com/ngottlieb) - <https://www.nicholasgottlieb.com>
|
173
174
|
|
174
175
|
## Contributing
|
175
176
|
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
@@ -184,31 +185,32 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
184
185
|
list in the the `README`. Alphabetical order applies.
|
185
186
|
* Do note that in order for us to merge any non-trivial changes (as a rule
|
186
187
|
of thumb, additions larger than about 15 lines of code), we need an
|
187
|
-
explicit [public domain dedication][PDD] on record from you
|
188
|
+
explicit [public domain dedication][PDD] on record from you,
|
189
|
+
which you will be asked to agree to on the first commit to a repo within the organization.
|
190
|
+
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
|
188
191
|
|
189
192
|
## Resources
|
190
193
|
|
191
|
-
* <
|
192
|
-
* <
|
193
|
-
* <
|
194
|
-
* <
|
195
|
-
* <
|
194
|
+
* <https://ruby-rdf.github.com/sparql-client/>
|
195
|
+
* <https://github.com/ruby-rdf/sparql-client>
|
196
|
+
* <https://rubygems.org/gems/sparql-client>
|
197
|
+
* <https://raa.ruby-lang.org/project/sparql-client/>
|
198
|
+
* <https://www.ohloh.net/p/rdf>
|
196
199
|
|
197
200
|
## License
|
198
201
|
|
199
202
|
This is free and unencumbered public domain software. For more information,
|
200
|
-
see <
|
201
|
-
|
202
|
-
[Ruby]:
|
203
|
-
[RDF]:
|
204
|
-
[SPARQL]:
|
205
|
-
[SPARQL JSON]:
|
206
|
-
[RDF.rb]:
|
207
|
-
[RDF
|
208
|
-
[
|
209
|
-
[DSL]: http://en.wikipedia.org/wiki/Domain-specific_language
|
203
|
+
see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
204
|
+
|
205
|
+
[Ruby]: https://ruby-lang.org/
|
206
|
+
[RDF]: https://www.w3.org/RDF/
|
207
|
+
[SPARQL]: https://en.wikipedia.org/wiki/SPARQL
|
208
|
+
[SPARQL JSON]: https://www.w3.org/TR/rdf-sparql-json-res/
|
209
|
+
[RDF.rb]: https://rubygems.org/gems/rdf
|
210
|
+
[RDF::Repository]: https://rubydoc.info/github/ruby-rdf/rdf/RDF/Repository
|
211
|
+
[DSL]: https://en.wikipedia.org/wiki/Domain-specific_language
|
210
212
|
"domain-specific language"
|
211
|
-
[YARD]:
|
212
|
-
[YARD-GS]:
|
213
|
-
[PDD]:
|
214
|
-
[Backports]:
|
213
|
+
[YARD]: https://yardoc.org/
|
214
|
+
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
215
|
+
[PDD]: https://unlicense.org/#unlicensing-contributions
|
216
|
+
[Backports]: https://rubygems.org/gems/backports
|
data/UNLICENSE
CHANGED
@@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
21
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
22
|
OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
|
24
|
-
For more information, please refer to <
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.1
|
data/lib/sparql/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'net/http/persistent' # @see
|
2
|
-
require 'rdf' # @see
|
3
|
-
require 'rdf/ntriples' # @see
|
1
|
+
require 'net/http/persistent' # @see https://rubygems.org/gems/net-http-persistent
|
2
|
+
require 'rdf' # @see https://rubygems.org/gems/rdf
|
3
|
+
require 'rdf/ntriples' # @see https://rubygems.org/gems/rdf
|
4
4
|
begin
|
5
5
|
require 'nokogiri'
|
6
6
|
rescue LoadError
|
@@ -11,10 +11,10 @@ module SPARQL
|
|
11
11
|
##
|
12
12
|
# A SPARQL 1.0/1.1 client for RDF.rb.
|
13
13
|
#
|
14
|
-
# @see
|
15
|
-
# @see
|
16
|
-
# @see
|
17
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/
|
15
|
+
# @see https://www.w3.org/TR/sparql11-protocol/
|
16
|
+
# @see https://www.w3.org/TR/sparql11-results-json/
|
17
|
+
# @see https://www.w3.org/TR/sparql11-results-csv-tsv/
|
18
18
|
class Client
|
19
19
|
autoload :Query, 'sparql/client/query'
|
20
20
|
autoload :Repository, 'sparql/client/repository'
|
@@ -185,7 +185,7 @@ module SPARQL
|
|
185
185
|
# @param [Hash{Symbol => Object}] options
|
186
186
|
# @option options [RDF::URI, String] :graph
|
187
187
|
# @return [void] `self`
|
188
|
-
# @see
|
188
|
+
# @see https://www.w3.org/TR/sparql11-update/#insertData
|
189
189
|
def insert_data(data, **options)
|
190
190
|
self.update(Update::InsertData.new(data, **options))
|
191
191
|
end
|
@@ -206,7 +206,7 @@ module SPARQL
|
|
206
206
|
# @param [Hash{Symbol => Object}] options
|
207
207
|
# @option options [RDF::URI, String] :graph
|
208
208
|
# @return [void] `self`
|
209
|
-
# @see
|
209
|
+
# @see https://www.w3.org/TR/sparql11-update/#deleteData
|
210
210
|
def delete_data(data, **options)
|
211
211
|
self.update(Update::DeleteData.new(data, **options))
|
212
212
|
end
|
@@ -222,7 +222,7 @@ module SPARQL
|
|
222
222
|
# @param [Hash{Symbol => Object}] options
|
223
223
|
# @option options [RDF::URI, String] :graph
|
224
224
|
# @return [void] `self`
|
225
|
-
# @see
|
225
|
+
# @see https://www.w3.org/TR/sparql11-update/#deleteInsert
|
226
226
|
def delete_insert(delete_graph, insert_graph = nil, where_graph = nil, **options)
|
227
227
|
self.update(Update::DeleteInsert.new(delete_graph, insert_graph, where_graph, **options))
|
228
228
|
end
|
@@ -239,7 +239,7 @@ module SPARQL
|
|
239
239
|
# @param [Hash{Symbol => Object}] options
|
240
240
|
# @option options [Boolean] :silent
|
241
241
|
# @return [void] `self`
|
242
|
-
# @see
|
242
|
+
# @see https://www.w3.org/TR/sparql11-update/#clear
|
243
243
|
def clear_graph(graph_uri, **options)
|
244
244
|
self.clear(:graph, graph_uri, **options)
|
245
245
|
end
|
@@ -274,7 +274,7 @@ module SPARQL
|
|
274
274
|
# @option options [Boolean] :silent
|
275
275
|
# @return [void] `self`
|
276
276
|
#
|
277
|
-
# @see
|
277
|
+
# @see https://www.w3.org/TR/sparql11-update/#clear
|
278
278
|
def clear(what, *arguments)
|
279
279
|
self.update(Update::Clear.new(what, *arguments))
|
280
280
|
end
|
@@ -307,7 +307,7 @@ module SPARQL
|
|
307
307
|
# @option options [Hash] :headers
|
308
308
|
# @return [Array<RDF::Query::Solution>]
|
309
309
|
# @raise [IOError] if connection is closed
|
310
|
-
# @see
|
310
|
+
# @see https://www.w3.org/TR/sparql11-protocol/#query-operation
|
311
311
|
def query(query, **options)
|
312
312
|
@op = :query
|
313
313
|
@alt_endpoint = options[:endpoint]
|
@@ -315,7 +315,7 @@ module SPARQL
|
|
315
315
|
when RDF::Queryable
|
316
316
|
require 'sparql' unless defined?(::SPARQL::Grammar)
|
317
317
|
begin
|
318
|
-
SPARQL.execute(query, @url, **options)
|
318
|
+
SPARQL.execute(query, @url, optimize: true, **options)
|
319
319
|
rescue SPARQL::MalformedQuery
|
320
320
|
$stderr.puts "error running #{query}: #{$!}"
|
321
321
|
raise
|
@@ -335,14 +335,14 @@ module SPARQL
|
|
335
335
|
# @option options [Hash] :headers
|
336
336
|
# @return [void] `self`
|
337
337
|
# @raise [IOError] if connection is closed
|
338
|
-
# @see
|
338
|
+
# @see https://www.w3.org/TR/sparql11-protocol/#update-operation
|
339
339
|
def update(query, **options)
|
340
340
|
@op = :update
|
341
341
|
@alt_endpoint = options[:endpoint]
|
342
342
|
case @url
|
343
343
|
when RDF::Queryable
|
344
344
|
require 'sparql' unless defined?(::SPARQL::Grammar)
|
345
|
-
SPARQL.execute(query, @url, update: true, **options)
|
345
|
+
SPARQL.execute(query, @url, update: true, optimize: true, **options)
|
346
346
|
else
|
347
347
|
response(query, **options)
|
348
348
|
end
|
@@ -402,7 +402,7 @@ module SPARQL
|
|
402
402
|
##
|
403
403
|
# @param [String, Hash] json
|
404
404
|
# @return [<RDF::Query::Solutions>]
|
405
|
-
# @see
|
405
|
+
# @see https://www.w3.org/TR/rdf-sparql-json-res/#results
|
406
406
|
def self.parse_json_bindings(json, nodes = {})
|
407
407
|
require 'json' unless defined?(::JSON)
|
408
408
|
json = JSON.parse(json.to_s) unless json.is_a?(Hash)
|
@@ -423,8 +423,8 @@ module SPARQL
|
|
423
423
|
##
|
424
424
|
# @param [Hash{String => String}] value
|
425
425
|
# @return [RDF::Value]
|
426
|
-
# @see
|
427
|
-
# @see
|
426
|
+
# @see https://www.w3.org/TR/sparql11-results-json/#select-encode-terms
|
427
|
+
# @see https://www.w3.org/TR/rdf-sparql-json-res/#variable-binding-results
|
428
428
|
def self.parse_json_value(value, nodes = {})
|
429
429
|
case value['type'].to_sym
|
430
430
|
when :bnode
|
@@ -442,7 +442,7 @@ module SPARQL
|
|
442
442
|
##
|
443
443
|
# @param [String, Array<Array<String>>] csv
|
444
444
|
# @return [<RDF::Query::Solutions>]
|
445
|
-
# @see
|
445
|
+
# @see https://www.w3.org/TR/sparql11-results-csv-tsv/
|
446
446
|
def self.parse_csv_bindings(csv, nodes = {})
|
447
447
|
require 'csv' unless defined?(::CSV)
|
448
448
|
csv = CSV.parse(csv.to_s) unless csv.is_a?(Array)
|
@@ -466,7 +466,7 @@ module SPARQL
|
|
466
466
|
##
|
467
467
|
# @param [String, Array<Array<String>>] tsv
|
468
468
|
# @return [<RDF::Query::Solutions>]
|
469
|
-
# @see
|
469
|
+
# @see https://www.w3.org/TR/sparql11-results-csv-tsv/
|
470
470
|
def self.parse_tsv_bindings(tsv, nodes = {})
|
471
471
|
tsv = tsv.lines.map {|l| l.chomp.split("\t")} unless tsv.is_a?(Array)
|
472
472
|
vars = tsv.shift.map {|h| h.sub(/^\?/, '')}
|
@@ -495,7 +495,7 @@ module SPARQL
|
|
495
495
|
##
|
496
496
|
# @param [String, IO, Nokogiri::XML::Node, REXML::Element] xml
|
497
497
|
# @return [<RDF::Query::Solutions>]
|
498
|
-
# @see
|
498
|
+
# @see https://www.w3.org/TR/rdf-sparql-json-res/#results
|
499
499
|
def self.parse_xml_bindings(xml, nodes = {})
|
500
500
|
xml.force_encoding(::Encoding::UTF_8) if xml.respond_to?(:force_encoding)
|
501
501
|
|
@@ -540,7 +540,7 @@ module SPARQL
|
|
540
540
|
##
|
541
541
|
# @param [Nokogiri::XML::Element, REXML::Element] value
|
542
542
|
# @return [RDF::Value]
|
543
|
-
# @see
|
543
|
+
# @see https://www.w3.org/TR/rdf-sparql-json-res/#variable-binding-results
|
544
544
|
def self.parse_xml_value(value, nodes = {})
|
545
545
|
case value.name.to_sym
|
546
546
|
when :bnode
|
@@ -699,7 +699,7 @@ module SPARQL
|
|
699
699
|
# @yieldparam [Net::HTTPResponse] response
|
700
700
|
# @return [Net::HTTPResponse]
|
701
701
|
# @raise [IOError] if connection is closed
|
702
|
-
# @see
|
702
|
+
# @see https://www.w3.org/TR/sparql11-protocol/#query-operation
|
703
703
|
def request(query, headers = {}, &block)
|
704
704
|
# Make sure an appropriate Accept header is present
|
705
705
|
headers['Accept'] ||= if (query.respond_to?(:expects_statements?) ?
|
@@ -747,7 +747,7 @@ module SPARQL
|
|
747
747
|
# @param [String, #to_s] query
|
748
748
|
# @param [Hash{String => String}] headers
|
749
749
|
# @return [Net::HTTPRequest]
|
750
|
-
# @see
|
750
|
+
# @see https://www.w3.org/TR/sparql11-protocol/#query-via-get
|
751
751
|
def make_get_request(query, headers = {})
|
752
752
|
url = self.url.dup
|
753
753
|
url.query_values = (url.query_values || {}).merge(query: query.to_s)
|
@@ -762,8 +762,8 @@ module SPARQL
|
|
762
762
|
# @param [String, #to_s] query
|
763
763
|
# @param [Hash{String => String}] headers
|
764
764
|
# @return [Net::HTTPRequest]
|
765
|
-
# @see
|
766
|
-
# @see
|
765
|
+
# @see https://www.w3.org/TR/sparql11-protocol/#query-via-post-direct
|
766
|
+
# @see https://www.w3.org/TR/sparql11-protocol/#query-via-post-urlencoded
|
767
767
|
def make_post_request(query, headers = {})
|
768
768
|
if @alt_endpoint.nil?
|
769
769
|
url = self.url.dup
|
data/lib/sparql/client/query.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
class SPARQL::Client
|
2
4
|
##
|
3
5
|
# A SPARQL query builder.
|
@@ -10,7 +12,7 @@ class SPARQL::Client
|
|
10
12
|
# The form of the query.
|
11
13
|
#
|
12
14
|
# @return [:select, :ask, :construct, :describe]
|
13
|
-
# @see
|
15
|
+
# @see https://www.w3.org/TR/sparql11-query/#QueryForms
|
14
16
|
attr_reader :form
|
15
17
|
|
16
18
|
##
|
@@ -25,7 +27,7 @@ class SPARQL::Client
|
|
25
27
|
#
|
26
28
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
27
29
|
# @return [Query]
|
28
|
-
# @see
|
30
|
+
# @see https://www.w3.org/TR/sparql11-query/#ask
|
29
31
|
def self.ask(**options)
|
30
32
|
self.new(:ask, **options)
|
31
33
|
end
|
@@ -33,13 +35,13 @@ class SPARQL::Client
|
|
33
35
|
##
|
34
36
|
# Creates a tuple `SELECT` query.
|
35
37
|
#
|
36
|
-
# @example SELECT * WHERE { ?s ?p ?o . }
|
38
|
+
# @example `SELECT * WHERE { ?s ?p ?o . }`
|
37
39
|
# Query.select.where([:s, :p, :o])
|
38
40
|
#
|
39
|
-
# @example SELECT ?s WHERE {?s ?p ?o .}
|
41
|
+
# @example `SELECT ?s WHERE {?s ?p ?o .}`
|
40
42
|
# Query.select(:s).where([:s, :p, :o])
|
41
43
|
#
|
42
|
-
# @example SELECT COUNT(?uri as ?c) WHERE {?uri a owl:Class}
|
44
|
+
# @example `SELECT COUNT(?uri as ?c) WHERE {?uri a owl:Class}`
|
43
45
|
# Query.select(count: {uri: :c}).where([:uri, RDF.type, RDF::OWL.Class])
|
44
46
|
#
|
45
47
|
# @param [Array<Symbol>] variables
|
@@ -49,7 +51,7 @@ class SPARQL::Client
|
|
49
51
|
# @param [Array<Symbol>] variables
|
50
52
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
51
53
|
# @return [Query]
|
52
|
-
# @see
|
54
|
+
# @see https://www.w3.org/TR/sparql11-query/#select
|
53
55
|
def self.select(*variables, **options)
|
54
56
|
self.new(:select, **options).select(*variables)
|
55
57
|
end
|
@@ -67,7 +69,7 @@ class SPARQL::Client
|
|
67
69
|
# @param [Array<Symbol, RDF::URI>] variables
|
68
70
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
69
71
|
# @return [Query]
|
70
|
-
# @see
|
72
|
+
# @see https://www.w3.org/TR/sparql11-query/#describe
|
71
73
|
def self.describe(*variables, **options)
|
72
74
|
self.new(:describe, **options).describe(*variables)
|
73
75
|
end
|
@@ -85,7 +87,7 @@ class SPARQL::Client
|
|
85
87
|
# @param [Array<RDF::Query::Pattern, Array>] patterns
|
86
88
|
# @param [Hash{Symbol => Object}] options (see {#initialize})
|
87
89
|
# @return [Query]
|
88
|
-
# @see
|
90
|
+
# @see https://www.w3.org/TR/sparql11-query/#construct
|
89
91
|
def self.construct(*patterns, **options)
|
90
92
|
self.new(:construct, **options).construct(*patterns) # FIXME
|
91
93
|
end
|
@@ -112,25 +114,25 @@ class SPARQL::Client
|
|
112
114
|
# query.ask.where([:s, :p, :o])
|
113
115
|
#
|
114
116
|
# @return [Query]
|
115
|
-
# @see
|
117
|
+
# @see https://www.w3.org/TR/sparql11-query/#ask
|
116
118
|
def ask
|
117
119
|
@form = :ask
|
118
120
|
self
|
119
121
|
end
|
120
122
|
|
121
123
|
##
|
122
|
-
# @example SELECT * WHERE { ?s ?p ?o . }
|
124
|
+
# @example `SELECT * WHERE { ?s ?p ?o . }`
|
123
125
|
# query.select.where([:s, :p, :o])
|
124
126
|
#
|
125
|
-
# @example SELECT ?s WHERE {?s ?p ?o .}
|
127
|
+
# @example `SELECT ?s WHERE {?s ?p ?o .}`
|
126
128
|
# query.select(:s).where([:s, :p, :o])
|
127
129
|
#
|
128
|
-
# @example SELECT COUNT(?uri as ?c) WHERE {?uri a owl:Class}
|
130
|
+
# @example `SELECT COUNT(?uri as ?c) WHERE {?uri a owl:Class}`
|
129
131
|
# query.select(count: {uri: :c}).where([:uri, RDF.type, RDF::OWL.Class])
|
130
132
|
#
|
131
133
|
# @param [Array<Symbol>, Hash{Symbol => RDF::Query::Variable}] variables
|
132
134
|
# @return [Query]
|
133
|
-
# @see
|
135
|
+
# @see https://www.w3.org/TR/sparql11-query/#select
|
134
136
|
def select(*variables)
|
135
137
|
@values = if variables.length == 1 && variables.first.is_a?(Hash)
|
136
138
|
variables.to_a
|
@@ -146,7 +148,7 @@ class SPARQL::Client
|
|
146
148
|
#
|
147
149
|
# @param [Array<Symbol>] variables
|
148
150
|
# @return [Query]
|
149
|
-
# @see
|
151
|
+
# @see https://www.w3.org/TR/sparql11-query/#describe
|
150
152
|
def describe(*variables)
|
151
153
|
@values = variables.map { |var|
|
152
154
|
[var, var.is_a?(RDF::URI) ? var : RDF::Query::Variable.new(var)]
|
@@ -160,7 +162,7 @@ class SPARQL::Client
|
|
160
162
|
#
|
161
163
|
# @param [Array<RDF::Query::Pattern, Array>] patterns
|
162
164
|
# @return [Query]
|
163
|
-
# @see
|
165
|
+
# @see https://www.w3.org/TR/sparql11-query/#construct
|
164
166
|
def construct(*patterns)
|
165
167
|
options[:template] = build_patterns(patterns)
|
166
168
|
self
|
@@ -172,7 +174,7 @@ class SPARQL::Client
|
|
172
174
|
#
|
173
175
|
# @param [RDF::URI] uri
|
174
176
|
# @return [Query]
|
175
|
-
# @see
|
177
|
+
# @see https://www.w3.org/TR/sparql11-query/#specifyingDataset
|
176
178
|
def from(uri)
|
177
179
|
options[:from] = uri
|
178
180
|
self
|
@@ -205,7 +207,7 @@ class SPARQL::Client
|
|
205
207
|
# Yield form with or without argument; without an argument, evaluates within the query.
|
206
208
|
# @yieldparam [SPARQL::Client::Query] query Actually a delegator to query. Methods other than `#select` are evaluated against `self`. For `#select`, a new Query is created, and the result added as a subquery.
|
207
209
|
# @return [Query]
|
208
|
-
# @see
|
210
|
+
# @see https://www.w3.org/TR/sparql11-query/#GraphPattern
|
209
211
|
def where(*patterns_queries, &block)
|
210
212
|
subqueries, patterns = patterns_queries.partition {|pq| pq.is_a? SPARQL::Client::Query}
|
211
213
|
@patterns += build_patterns(patterns)
|
@@ -245,7 +247,7 @@ class SPARQL::Client
|
|
245
247
|
#
|
246
248
|
# @param [Array<Symbol, String>] variables
|
247
249
|
# @return [Query]
|
248
|
-
# @see
|
250
|
+
# @see https://www.w3.org/TR/sparql11-query/#modOrderBy
|
249
251
|
def order(*variables)
|
250
252
|
options[:order_by] = variables
|
251
253
|
self
|
@@ -260,7 +262,7 @@ class SPARQL::Client
|
|
260
262
|
#
|
261
263
|
# @param [Array<Symbol, String>] var
|
262
264
|
# @return [Query]
|
263
|
-
# @see
|
265
|
+
# @see https://www.w3.org/TR/sparql11-query/#modOrderBy
|
264
266
|
def asc(var)
|
265
267
|
(options[:order_by] ||= []) << {var => :asc}
|
266
268
|
self
|
@@ -273,7 +275,7 @@ class SPARQL::Client
|
|
273
275
|
#
|
274
276
|
# @param [Array<Symbol, String>] var
|
275
277
|
# @return [Query]
|
276
|
-
# @see
|
278
|
+
# @see https://www.w3.org/TR/sparql11-query/#modOrderBy
|
277
279
|
def desc(var)
|
278
280
|
(options[:order_by] ||= []) << {var => :desc}
|
279
281
|
self
|
@@ -285,7 +287,7 @@ class SPARQL::Client
|
|
285
287
|
#
|
286
288
|
# @param [Array<Symbol, String>] variables
|
287
289
|
# @return [Query]
|
288
|
-
# @see
|
290
|
+
# @see https://www.w3.org/TR/sparql11-query/#groupby
|
289
291
|
def group(*variables)
|
290
292
|
options[:group_by] = variables
|
291
293
|
self
|
@@ -298,7 +300,7 @@ class SPARQL::Client
|
|
298
300
|
# query.select(:s).distinct.where([:s, :p, :o])
|
299
301
|
#
|
300
302
|
# @return [Query]
|
301
|
-
# @see
|
303
|
+
# @see https://www.w3.org/TR/sparql11-query/#modDuplicates
|
302
304
|
def distinct(state = true)
|
303
305
|
options[:distinct] = state
|
304
306
|
self
|
@@ -309,7 +311,7 @@ class SPARQL::Client
|
|
309
311
|
# query.select(:s).reduced.where([:s, :p, :o])
|
310
312
|
#
|
311
313
|
# @return [Query]
|
312
|
-
# @see
|
314
|
+
# @see https://www.w3.org/TR/sparql11-query/#modDuplicates
|
313
315
|
def reduced(state = true)
|
314
316
|
options[:reduced] = state
|
315
317
|
self
|
@@ -320,7 +322,7 @@ class SPARQL::Client
|
|
320
322
|
# query.select.graph(:g).where([:s, :p, :o])
|
321
323
|
# @param [RDF::Value] graph_uri_or_var
|
322
324
|
# @return [Query]
|
323
|
-
# @see
|
325
|
+
# @see https://www.w3.org/TR/sparql11-query/#queryDataset
|
324
326
|
def graph(graph_uri_or_var)
|
325
327
|
options[:graph] = case graph_uri_or_var
|
326
328
|
when Symbol then RDF::Query::Variable.new(graph_uri_or_var)
|
@@ -337,7 +339,7 @@ class SPARQL::Client
|
|
337
339
|
#
|
338
340
|
# @param [Integer, #to_i] start
|
339
341
|
# @return [Query]
|
340
|
-
# @see
|
342
|
+
# @see https://www.w3.org/TR/sparql11-query/#modOffset
|
341
343
|
def offset(start)
|
342
344
|
slice(start, nil)
|
343
345
|
end
|
@@ -348,7 +350,7 @@ class SPARQL::Client
|
|
348
350
|
#
|
349
351
|
# @param [Integer, #to_i] length
|
350
352
|
# @return [Query]
|
351
|
-
# @see
|
353
|
+
# @see https://www.w3.org/TR/sparql11-query/#modResultLimit
|
352
354
|
def limit(length)
|
353
355
|
slice(nil, length)
|
354
356
|
end
|
@@ -387,7 +389,7 @@ class SPARQL::Client
|
|
387
389
|
#
|
388
390
|
# @param [string] string
|
389
391
|
# @return [Query]
|
390
|
-
# @see
|
392
|
+
# @see https://www.w3.org/TR/sparql11-query/#prefNames
|
391
393
|
def prefix(val)
|
392
394
|
options[:prefixes] ||= []
|
393
395
|
if val.kind_of? String
|
@@ -420,7 +422,7 @@ class SPARQL::Client
|
|
420
422
|
# Yield form with or without argument; without an argument, evaluates within the query.
|
421
423
|
# @yieldparam [SPARQL::Client::Query] query used for creating filters on the optional patterns.
|
422
424
|
# @return [Query]
|
423
|
-
# @see
|
425
|
+
# @see https://www.w3.org/TR/sparql11-query/#optionals
|
424
426
|
def optional(*patterns, &block)
|
425
427
|
(options[:optionals] ||= []) << build_patterns(patterns)
|
426
428
|
|
@@ -466,7 +468,7 @@ class SPARQL::Client
|
|
466
468
|
# Yield form with or without argument; without an argument, evaluates within the query.
|
467
469
|
# @yieldparam [SPARQL::Client::Query] query used for adding select clauses.
|
468
470
|
# @return [Query]
|
469
|
-
# @see
|
471
|
+
# @see https://www.w3.org/TR/sparql11-query/#optionals
|
470
472
|
def union(*patterns, &block)
|
471
473
|
options[:unions] ||= []
|
472
474
|
|
@@ -519,7 +521,7 @@ class SPARQL::Client
|
|
519
521
|
# Yield form with or without argument; without an argument, evaluates within the query.
|
520
522
|
# @yieldparam [SPARQL::Client::Query] query used for adding select clauses.
|
521
523
|
# @return [Query]
|
522
|
-
# @see
|
524
|
+
# @see https://www.w3.org/TR/sparql11-query/#optionals
|
523
525
|
def minus(*patterns, &block)
|
524
526
|
options[:minuses] ||= []
|
525
527
|
|
@@ -601,7 +603,7 @@ class SPARQL::Client
|
|
601
603
|
case nil_literal_or_term
|
602
604
|
when nil then nil
|
603
605
|
when String then RDF::Literal(nil_literal_or_term)
|
604
|
-
when RDF::Value then
|
606
|
+
when RDF::Value then nil_literal_or_term
|
605
607
|
else raise ArgumentError
|
606
608
|
end
|
607
609
|
end
|
@@ -179,9 +179,7 @@ class SPARQL::Client
|
|
179
179
|
binding[:count].value.to_i rescue 0
|
180
180
|
rescue SPARQL::Client::MalformedQuery => e
|
181
181
|
# SPARQL 1.0 does not include support for aggregate functions:
|
182
|
-
count
|
183
|
-
each_statement { count += 1 } # TODO: optimize this
|
184
|
-
count
|
182
|
+
each_statement.count
|
185
183
|
end
|
186
184
|
end
|
187
185
|
|
@@ -264,7 +262,9 @@ class SPARQL::Client
|
|
264
262
|
# @see RDF::Query#execute
|
265
263
|
def query_execute(query, **options, &block)
|
266
264
|
return nil unless block_given?
|
267
|
-
q = SPARQL::Client::Query.
|
265
|
+
q = SPARQL::Client::Query.
|
266
|
+
select(query.variables, **{}).
|
267
|
+
where(*query.patterns)
|
268
268
|
client.query(q, **options).each do |solution|
|
269
269
|
yield solution
|
270
270
|
end
|
data/lib/sparql/client/update.rb
CHANGED
@@ -155,7 +155,7 @@ class SPARQL::Client
|
|
155
155
|
end
|
156
156
|
|
157
157
|
##
|
158
|
-
# @see
|
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
|
@@ -205,7 +205,7 @@ class SPARQL::Client
|
|
205
205
|
end
|
206
206
|
|
207
207
|
##
|
208
|
-
# @see
|
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
|
@@ -247,7 +247,7 @@ class SPARQL::Client
|
|
247
247
|
end
|
248
248
|
|
249
249
|
##
|
250
|
-
# @see
|
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
|
@@ -301,7 +301,7 @@ class SPARQL::Client
|
|
301
301
|
end
|
302
302
|
|
303
303
|
##
|
304
|
-
# @see
|
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
|
@@ -350,7 +350,7 @@ class SPARQL::Client
|
|
350
350
|
end
|
351
351
|
|
352
352
|
##
|
353
|
-
# @see
|
353
|
+
# @see https://www.w3.org/TR/sparql11-update/#clear
|
354
354
|
class Clear < Operation
|
355
355
|
attr_reader :uri
|
356
356
|
|
@@ -414,7 +414,7 @@ class SPARQL::Client
|
|
414
414
|
end
|
415
415
|
|
416
416
|
##
|
417
|
-
# @see
|
417
|
+
# @see https://www.w3.org/TR/sparql11-update/#create
|
418
418
|
class Create < Operation
|
419
419
|
attr_reader :uri
|
420
420
|
|
@@ -433,7 +433,7 @@ class SPARQL::Client
|
|
433
433
|
end
|
434
434
|
|
435
435
|
##
|
436
|
-
# @see
|
436
|
+
# @see https://www.w3.org/TR/sparql11-update/#drop
|
437
437
|
class Drop < Clear
|
438
438
|
def to_s
|
439
439
|
query_text = 'DROP '
|
@@ -450,7 +450,7 @@ class SPARQL::Client
|
|
450
450
|
end
|
451
451
|
|
452
452
|
##
|
453
|
-
# @see
|
453
|
+
# @see https://www.w3.org/TR/sparql11-update/#copy
|
454
454
|
class Copy < Operation
|
455
455
|
def to_s
|
456
456
|
# TODO
|
@@ -458,7 +458,7 @@ class SPARQL::Client
|
|
458
458
|
end
|
459
459
|
|
460
460
|
##
|
461
|
-
# @see
|
461
|
+
# @see https://www.w3.org/TR/sparql11-update/#move
|
462
462
|
class Move < Operation
|
463
463
|
def to_s
|
464
464
|
# TODO
|
@@ -466,7 +466,7 @@ class SPARQL::Client
|
|
466
466
|
end
|
467
467
|
|
468
468
|
##
|
469
|
-
# @see
|
469
|
+
# @see https://www.w3.org/TR/sparql11-update/#add
|
470
470
|
class Add < Operation
|
471
471
|
def to_s
|
472
472
|
# TODO
|
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: 3.1.
|
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:
|
13
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rdf
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
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: '
|
42
|
+
version: '4.0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rdf-spec
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,14 +74,14 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '3.
|
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.
|
84
|
+
version: '3.10'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: rspec-its
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,28 +102,28 @@ dependencies:
|
|
102
102
|
requirements:
|
103
103
|
- - "~>"
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: '3.
|
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: '3.
|
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.9
|
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.9
|
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:
|
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
|
@@ -163,8 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
167
|
-
signing_key:
|
166
|
+
rubygems_version: 3.1.4
|
167
|
+
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: SPARQL client for RDF.rb.
|
170
170
|
test_files: []
|