sparql-client 3.2.0 → 3.2.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 +8 -8
- data/VERSION +1 -1
- data/lib/sparql/client.rb +68 -40
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfca146902f11c4799f6b955e97deecf31873afc3c05309234cab948f34afd0c
|
4
|
+
data.tar.gz: 63cbaafab09deeddf3cbbcb23fe013c27ff82b759fa681a32219eebf24a771ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aa86e2182d70ab4ca0472c2ae4f5a6c645a95a848dbb6f74f38c4406c298e15a8e704d321d42b3d5a8186f607dcf5ad1304755a575e75e295ce81fa26eecdd8
|
7
|
+
data.tar.gz: 495bd5bcfed2a73e47c0a890ccce100551befd249216328209f0bf20a920a6d8db1efb6e4691172adbae7aeff58496bf5434f875987f61f7d2c0068116b762b5
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
|
4
4
|
|
5
|
-
* <https://ruby-rdf.github.
|
5
|
+
* <https://ruby-rdf.github.io/sparql-client/>
|
6
6
|
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/sparql-client.png)](https://badge.fury.io/rb/sparql-client)
|
8
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)
|
@@ -44,7 +44,7 @@ sparql = SPARQL::Client.new("http://dbpedia.org/sparql", headers: {'User-Agent'
|
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
require 'sparql/client'
|
47
|
-
sparql = SPARQL::Client.new("http://dbpedia.org/sparql",
|
47
|
+
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", graph: "http://dbpedia.org")
|
48
48
|
```
|
49
49
|
|
50
50
|
|
@@ -117,10 +117,10 @@ sparql.delete_data(data)
|
|
117
117
|
|
118
118
|
## Documentation
|
119
119
|
|
120
|
-
* [SPARQL::Client](https://
|
121
|
-
* [SPARQL::Client::Query](https://
|
122
|
-
* [SPARQL::Client::Repository](https://
|
123
|
-
* [SPARQL::Client::Update](https://
|
120
|
+
* [SPARQL::Client](https://ruby-rdf.github.io/sparql-client/SPARQL/Client)
|
121
|
+
* [SPARQL::Client::Query](https://ruby-rdf.github.io/sparql-client/SPARQL/Client/Query)
|
122
|
+
* [SPARQL::Client::Repository](https://ruby-rdf.github.io/sparql-client/SPARQL/Client/Repository)
|
123
|
+
* [SPARQL::Client::Update](https://ruby-rdf.github.io/sparql-client/SPARQL/Client/Update)
|
124
124
|
|
125
125
|
## Dependencies
|
126
126
|
|
@@ -191,7 +191,7 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
191
191
|
|
192
192
|
## Resources
|
193
193
|
|
194
|
-
* <https://ruby-rdf.github.
|
194
|
+
* <https://ruby-rdf.github.io/sparql-client/>
|
195
195
|
* <https://github.com/ruby-rdf/sparql-client>
|
196
196
|
* <https://rubygems.org/gems/sparql-client>
|
197
197
|
* <https://raa.ruby-lang.org/project/sparql-client/>
|
@@ -207,7 +207,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
207
207
|
[SPARQL]: https://en.wikipedia.org/wiki/SPARQL
|
208
208
|
[SPARQL JSON]: https://www.w3.org/TR/rdf-sparql-json-res/
|
209
209
|
[RDF.rb]: https://rubygems.org/gems/rdf
|
210
|
-
[RDF::Repository]: https://
|
210
|
+
[RDF::Repository]: https://ruby-rdf.github.io/rdf/RDF/Repository
|
211
211
|
[DSL]: https://en.wikipedia.org/wiki/Domain-specific_language
|
212
212
|
"domain-specific language"
|
213
213
|
[YARD]: https://yardoc.org/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.2.
|
1
|
+
3.2.1
|
data/lib/sparql/client.rb
CHANGED
@@ -116,7 +116,14 @@ module SPARQL
|
|
116
116
|
# Close the http connection when object is deallocated
|
117
117
|
def self.finalize(klass)
|
118
118
|
proc do
|
119
|
-
|
119
|
+
if klass.respond_to?(:shutdown)
|
120
|
+
begin
|
121
|
+
# Attempt asynchronous shutdown
|
122
|
+
Thread.new {klass.shutdown}
|
123
|
+
rescue ThreadError
|
124
|
+
klass.shutdown
|
125
|
+
end
|
126
|
+
end
|
120
127
|
end
|
121
128
|
end
|
122
129
|
|
@@ -423,7 +430,13 @@ module SPARQL
|
|
423
430
|
end
|
424
431
|
RDF::Query::Solution.new(row)
|
425
432
|
end
|
426
|
-
RDF::Query::Solutions.new(solutions)
|
433
|
+
solns = RDF::Query::Solutions.new(solutions)
|
434
|
+
|
435
|
+
# Set variable names explicitly
|
436
|
+
if json.fetch('head', {}).has_key?('vars')
|
437
|
+
solns.variable_names = json['head']['vars'].map(&:to_sym)
|
438
|
+
end
|
439
|
+
solns
|
427
440
|
end
|
428
441
|
end
|
429
442
|
|
@@ -484,20 +497,23 @@ module SPARQL
|
|
484
497
|
vars = tsv.shift.map {|h| h.sub(/^\?/, '')}
|
485
498
|
solutions = RDF::Query::Solutions.new
|
486
499
|
tsv.each do |row|
|
500
|
+
# Flesh out columns which may be missing
|
501
|
+
vars.each_with_index do |_, i|
|
502
|
+
row[i] ||= ""
|
503
|
+
end
|
487
504
|
solution = RDF::Query::Solution.new
|
488
505
|
row.each_with_index do |v, i|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
end
|
498
|
-
nodes[term.id] = term if term.is_a? RDF::Node
|
499
|
-
solution[vars[i].to_sym] = term
|
506
|
+
term = case v
|
507
|
+
when "" then RDF::Literal("")
|
508
|
+
when /^\d+\.\d*[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
|
509
|
+
when /^\d*\.\d+[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
|
510
|
+
when /^\d*\.\d+$/ then RDF::Literal::Decimal.new(v)
|
511
|
+
when /^\d+$/ then RDF::Literal::Integer.new(v)
|
512
|
+
else
|
513
|
+
RDF::NTriples.unserialize(v) || RDF::Literal(v)
|
500
514
|
end
|
515
|
+
nodes[term.id] = term if term.is_a? RDF::Node
|
516
|
+
solution[vars[i].to_sym] = term
|
501
517
|
end
|
502
518
|
solutions << solution
|
503
519
|
end
|
@@ -506,45 +522,57 @@ module SPARQL
|
|
506
522
|
|
507
523
|
##
|
508
524
|
# @param [String, IO, Nokogiri::XML::Node, REXML::Element] xml
|
525
|
+
# @param [Symbol] library (:nokogiri)
|
526
|
+
# One of :nokogiri or :rexml.
|
509
527
|
# @return [<RDF::Query::Solutions>]
|
510
528
|
# @see https://www.w3.org/TR/rdf-sparql-json-res/#results
|
511
|
-
def self.parse_xml_bindings(xml, nodes = {})
|
529
|
+
def self.parse_xml_bindings(xml, nodes = {}, library: :nokogiri)
|
512
530
|
xml.force_encoding(::Encoding::UTF_8) if xml.respond_to?(:force_encoding)
|
513
531
|
|
514
|
-
if defined?(::Nokogiri)
|
532
|
+
if defined?(::Nokogiri) && library == :nokogiri
|
515
533
|
xml = Nokogiri::XML(xml).root unless xml.is_a?(Nokogiri::XML::Document)
|
516
534
|
case
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
end
|
527
|
-
RDF::Query::Solution.new(row)
|
535
|
+
when boolean = xml.xpath("//sparql:boolean", XMLNS)[0]
|
536
|
+
boolean.text == 'true'
|
537
|
+
when results = xml.xpath("//sparql:results", XMLNS)[0]
|
538
|
+
solutions = results.elements.map do |result|
|
539
|
+
row = {}
|
540
|
+
result.elements.each do |binding|
|
541
|
+
name = binding.attr('name').to_sym
|
542
|
+
value = binding.elements.first
|
543
|
+
row[name] = parse_xml_value(value, nodes)
|
528
544
|
end
|
529
|
-
RDF::Query::
|
545
|
+
RDF::Query::Solution.new(row)
|
546
|
+
end
|
547
|
+
solns = RDF::Query::Solutions.new(solutions)
|
548
|
+
|
549
|
+
# Set variable names explicitly
|
550
|
+
var_names = xml.xpath("//sparql:head/sparql:variable/@name", XMLNS)
|
551
|
+
solns.variable_names = var_names.map(&:to_s)
|
552
|
+
solns
|
530
553
|
end
|
531
554
|
else
|
532
555
|
# REXML
|
533
556
|
xml = REXML::Document.new(xml).root unless xml.is_a?(REXML::Element)
|
534
557
|
case
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
end
|
545
|
-
RDF::Query::Solution.new(row)
|
558
|
+
when boolean = xml.elements['boolean']
|
559
|
+
boolean.text == 'true'
|
560
|
+
when results = xml.elements['results']
|
561
|
+
solutions = results.elements.map do |result|
|
562
|
+
row = {}
|
563
|
+
result.elements.each do |binding|
|
564
|
+
name = binding.attributes['name'].to_sym
|
565
|
+
value = binding.select { |node| node.kind_of?(::REXML::Element) }.first
|
566
|
+
row[name] = parse_xml_value(value, nodes)
|
546
567
|
end
|
547
|
-
RDF::Query::
|
568
|
+
RDF::Query::Solution.new(row)
|
569
|
+
end
|
570
|
+
solns = RDF::Query::Solutions.new(solutions)
|
571
|
+
|
572
|
+
# Set variable names explicitly
|
573
|
+
var_names = xml.elements['head'].elements.map {|e| e.attributes['name']}
|
574
|
+
solns.variable_names = var_names.map(&:to_sym)
|
575
|
+
solns
|
548
576
|
end
|
549
577
|
end
|
550
578
|
end
|
@@ -578,7 +606,7 @@ module SPARQL
|
|
578
606
|
# @return [RDF::Enumerable]
|
579
607
|
def parse_rdf_serialization(response, **options)
|
580
608
|
options = {content_type: response.content_type} unless options[:content_type]
|
581
|
-
if reader = RDF::Reader.for(options)
|
609
|
+
if reader = RDF::Reader.for(**options)
|
582
610
|
reader.new(response.body)
|
583
611
|
else
|
584
612
|
raise RDF::ReaderError, "no RDF reader was found for #{options}."
|
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.2.
|
4
|
+
version: 3.2.1
|
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: 2022-03-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rdf
|
@@ -19,6 +19,9 @@ dependencies:
|
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.2'
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.2.6
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,6 +29,9 @@ dependencies:
|
|
26
29
|
- - "~>"
|
27
30
|
- !ruby/object:Gem::Version
|
28
31
|
version: '3.2'
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.2.6
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
36
|
name: net-http-persistent
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,10 +156,15 @@ files:
|
|
150
156
|
- lib/sparql/client/repository.rb
|
151
157
|
- lib/sparql/client/update.rb
|
152
158
|
- lib/sparql/client/version.rb
|
153
|
-
homepage: https://github.com/ruby-rdf/sparql-client
|
159
|
+
homepage: https://github.com/ruby-rdf/sparql-client
|
154
160
|
licenses:
|
155
161
|
- Unlicense
|
156
|
-
metadata:
|
162
|
+
metadata:
|
163
|
+
documentation_uri: https://ruby-rdf.github.io/sparql-client
|
164
|
+
bug_tracker_uri: https://github.com/ruby-rdf/sparql-client/issues
|
165
|
+
homepage_uri: https://github.com/ruby-rdf/sparql-client
|
166
|
+
mailing_list_uri: https://lists.w3.org/Archives/Public/public-rdf-ruby/
|
167
|
+
source_code_uri: https://github.com/ruby-rdf/sparql-client
|
157
168
|
post_install_message:
|
158
169
|
rdoc_options: []
|
159
170
|
require_paths:
|