Skip to content

Commit 9b10cef

Browse files
committed
Finish 3.2.1
2 parents b60d7ec + 3bde8ea commit 9b10cef

File tree

12 files changed

+231
-91
lines changed

12 files changed

+231
-91
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
ruby:
2424
- 2.6
2525
- 2.7
26-
- 3.0
26+
- "3.0"
2727
- 3.1
2828
- ruby-head
2929
- jruby

.github/workflows/generate-docs.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build & deploy documentation
2+
on:
3+
push:
4+
branches:
5+
- master
6+
workflow_dispatch:
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
name: Update gh-pages with docs
11+
steps:
12+
- name: Clone repository
13+
uses: actions/checkout@v2
14+
- name: Set up Ruby
15+
uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: "3.1"
18+
- name: Install required gem dependencies
19+
run: gem install yard --no-document
20+
- name: Build YARD Ruby Documentation
21+
run: yardoc
22+
- name: Deploy
23+
uses: peaceiris/actions-gh-pages@v3
24+
with:
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
26+
publish_dir: ./doc/yard
27+
publish_branch: gh-pages

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
44

5-
* <https://ruby-rdf.github.com/sparql-client/>
5+
* <https://ruby-rdf.github.io/sparql-client/>
66

77
[![Gem Version](https://badge.fury.io/rb/sparql-client.png)](https://badge.fury.io/rb/sparql-client)
88
[![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'
4444

4545
```ruby
4646
require 'sparql/client'
47-
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", { graph: "http://dbpedia.org" })
47+
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", graph: "http://dbpedia.org")
4848
```
4949

5050

@@ -117,10 +117,10 @@ sparql.delete_data(data)
117117

118118
## Documentation
119119

120-
* [SPARQL::Client](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client)
121-
* [SPARQL::Client::Query](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Query)
122-
* [SPARQL::Client::Repository](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Repository)
123-
* [SPARQL::Client::Update](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Update)
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)
124124

125125
## Dependencies
126126

@@ -191,7 +191,7 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
191191

192192
## Resources
193193

194-
* <https://ruby-rdf.github.com/sparql-client/>
194+
* <https://ruby-rdf.github.io/sparql-client/>
195195
* <https://github.com/ruby-rdf/sparql-client>
196196
* <https://rubygems.org/gems/sparql-client>
197197
* <https://raa.ruby-lang.org/project/sparql-client/>
@@ -207,7 +207,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
207207
[SPARQL]: https://en.wikipedia.org/wiki/SPARQL
208208
[SPARQL JSON]: https://www.w3.org/TR/rdf-sparql-json-res/
209209
[RDF.rb]: https://rubygems.org/gems/rdf
210-
[RDF::Repository]: https://rubydoc.info/github/ruby-rdf/rdf/RDF/Repository
210+
[RDF::Repository]: https://ruby-rdf.github.io/rdf/RDF/Repository
211211
[DSL]: https://en.wikipedia.org/wiki/Domain-specific_language
212212
"domain-specific language"
213213
[YARD]: https://yardoc.org/

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.0
1+
3.2.1

lib/sparql/client.rb

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ def initialize(url, **options, &block)
116116
# Close the http connection when object is deallocated
117117
def self.finalize(klass)
118118
proc do
119-
klass.shutdown if klass.respond_to?(:shutdown)
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
120127
end
121128
end
122129

@@ -423,7 +430,13 @@ def self.parse_json_bindings(json, nodes = {})
423430
end
424431
RDF::Query::Solution.new(row)
425432
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
427440
end
428441
end
429442

@@ -484,20 +497,23 @@ def self.parse_tsv_bindings(tsv, nodes = {})
484497
vars = tsv.shift.map {|h| h.sub(/^\?/, '')}
485498
solutions = RDF::Query::Solutions.new
486499
tsv.each do |row|
500+
# Flesh out columns which may be missing
501+
vars.each_with_index do |_, i|
502+
row[i] ||= ""
503+
end
487504
solution = RDF::Query::Solution.new
488505
row.each_with_index do |v, i|
489-
if !v.empty?
490-
term = RDF::NTriples.unserialize(v) || case v
491-
when /^\d+\.\d*[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
492-
when /^\d*\.\d+[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
493-
when /^\d*\.\d+$/ then RDF::Literal::Decimal.new(v)
494-
when /^\d+$/ then RDF::Literal::Integer.new(v)
495-
else
496-
RDF::Literal(v)
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)
500514
end
515+
nodes[term.id] = term if term.is_a? RDF::Node
516+
solution[vars[i].to_sym] = term
501517
end
502518
solutions << solution
503519
end
@@ -506,45 +522,57 @@ def self.parse_tsv_bindings(tsv, nodes = {})
506522

507523
##
508524
# @param [String, IO, Nokogiri::XML::Node, REXML::Element] xml
525+
# @param [Symbol] library (:nokogiri)
526+
# One of :nokogiri or :rexml.
509527
# @return [<RDF::Query::Solutions>]
510528
# @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)
512530
xml.force_encoding(::Encoding::UTF_8) if xml.respond_to?(:force_encoding)
513531

514-
if defined?(::Nokogiri)
532+
if defined?(::Nokogiri) && library == :nokogiri
515533
xml = Nokogiri::XML(xml).root unless xml.is_a?(Nokogiri::XML::Document)
516534
case
517-
when boolean = xml.xpath("//sparql:boolean", XMLNS)[0]
518-
boolean.text == 'true'
519-
when results = xml.xpath("//sparql:results", XMLNS)[0]
520-
solutions = results.elements.map do |result|
521-
row = {}
522-
result.elements.each do |binding|
523-
name = binding.attr('name').to_sym
524-
value = binding.elements.first
525-
row[name] = parse_xml_value(value, nodes)
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)
528544
end
529-
RDF::Query::Solutions.new(solutions)
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
530553
end
531554
else
532555
# REXML
533556
xml = REXML::Document.new(xml).root unless xml.is_a?(REXML::Element)
534557
case
535-
when boolean = xml.elements['boolean']
536-
boolean.text == 'true'
537-
when results = xml.elements['results']
538-
solutions = results.elements.map do |result|
539-
row = {}
540-
result.elements.each do |binding|
541-
name = binding.attributes['name'].to_sym
542-
value = binding.select { |node| node.kind_of?(::REXML::Element) }.first
543-
row[name] = parse_xml_value(value, nodes)
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)
546567
end
547-
RDF::Query::Solutions.new(solutions)
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
548576
end
549577
end
550578
end
@@ -578,7 +606,7 @@ def self.parse_xml_value(value, nodes = {})
578606
# @return [RDF::Enumerable]
579607
def parse_rdf_serialization(response, **options)
580608
options = {content_type: response.content_type} unless options[:content_type]
581-
if reader = RDF::Reader.for(options)
609+
if reader = RDF::Reader.for(**options)
582610
reader.new(response.body)
583611
else
584612
raise RDF::ReaderError, "no RDF reader was found for #{options}."

sparql-client.gemspec

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ Gem::Specification.new do |gem|
66
gem.date = File.mtime('VERSION').strftime('%Y-%m-%d')
77

88
gem.name = 'sparql-client'
9-
gem.homepage = 'https://github.com/ruby-rdf/sparql-client/'
9+
gem.homepage = 'https://github.com/ruby-rdf/sparql-client'
1010
gem.license = 'Unlicense'
1111
gem.summary = 'SPARQL client for RDF.rb.'
1212
gem.description = %(Executes SPARQL queries and updates against a remote SPARQL 1.0 or 1.1 endpoint,
1313
or against a local repository. Generates SPARQL queries using a simple DSL.
1414
Includes SPARQL::Client::Repository, which allows any endpoint supporting
1515
SPARQL Update to be used as an RDF.rb repository.)
16+
gem.metadata = {
17+
"documentation_uri" => "https://ruby-rdf.github.io/sparql-client",
18+
"bug_tracker_uri" => "https://github.com/ruby-rdf/sparql-client/issues",
19+
"homepage_uri" => "https://github.com/ruby-rdf/sparql-client",
20+
"mailing_list_uri" => "https://lists.w3.org/Archives/Public/public-rdf-ruby/",
21+
"source_code_uri" => "https://github.com/ruby-rdf/sparql-client",
22+
}
1623

1724
gem.authors = ['Arto Bendiken', 'Ben Lavender', 'Gregg Kellogg']
1825
gem.email = '[email protected]'
@@ -24,7 +31,7 @@ Gem::Specification.new do |gem|
2431

2532
gem.required_ruby_version = '>= 2.6'
2633
gem.requirements = []
27-
gem.add_runtime_dependency 'rdf', '~> 3.2'
34+
gem.add_runtime_dependency 'rdf', '~> 3.2', '>= 3.2.6'
2835
gem.add_runtime_dependency 'net-http-persistent', '~> 4.0', '>= 4.0.1'
2936
gem.add_development_dependency 'rdf-spec', '~> 3.2'
3037
gem.add_development_dependency 'sparql', '~> 3.2'

0 commit comments

Comments
 (0)