Skip to content

Commit

Permalink
Finish 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Mar 16, 2022
2 parents b60d7ec + 3bde8ea commit 9b10cef
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -23,7 +23,7 @@ jobs:
ruby:
- 2.6
- 2.7
- 3.0
- "3.0"
- 3.1
- ruby-head
- jruby
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/generate-docs.yml
@@ -0,0 +1,27 @@
name: Build & deploy documentation
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
name: Update gh-pages with docs
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1"
- name: Install required gem dependencies
run: gem install yard --no-document
- name: Build YARD Ruby Documentation
run: yardoc
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc/yard
publish_branch: gh-pages
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -2,7 +2,7 @@

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

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

[![Gem Version](https://badge.fury.io/rb/sparql-client.png)](https://badge.fury.io/rb/sparql-client)
[![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)
Expand Down Expand Up @@ -44,7 +44,7 @@ sparql = SPARQL::Client.new("http://dbpedia.org/sparql", headers: {'User-Agent'

```ruby
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", { graph: "http://dbpedia.org" })
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", graph: "http://dbpedia.org")
```


Expand Down Expand Up @@ -117,10 +117,10 @@ sparql.delete_data(data)

## Documentation

* [SPARQL::Client](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client)
* [SPARQL::Client::Query](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Query)
* [SPARQL::Client::Repository](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Repository)
* [SPARQL::Client::Update](https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Update)
* [SPARQL::Client](https://ruby-rdf.github.io/sparql-client/SPARQL/Client)
* [SPARQL::Client::Query](https://ruby-rdf.github.io/sparql-client/SPARQL/Client/Query)
* [SPARQL::Client::Repository](https://ruby-rdf.github.io/sparql-client/SPARQL/Client/Repository)
* [SPARQL::Client::Update](https://ruby-rdf.github.io/sparql-client/SPARQL/Client/Update)

## Dependencies

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

## Resources

* <https://ruby-rdf.github.com/sparql-client/>
* <https://ruby-rdf.github.io/sparql-client/>
* <https://github.com/ruby-rdf/sparql-client>
* <https://rubygems.org/gems/sparql-client>
* <https://raa.ruby-lang.org/project/sparql-client/>
Expand All @@ -207,7 +207,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
[SPARQL]: https://en.wikipedia.org/wiki/SPARQL
[SPARQL JSON]: https://www.w3.org/TR/rdf-sparql-json-res/
[RDF.rb]: https://rubygems.org/gems/rdf
[RDF::Repository]: https://rubydoc.info/github/ruby-rdf/rdf/RDF/Repository
[RDF::Repository]: https://ruby-rdf.github.io/rdf/RDF/Repository
[DSL]: https://en.wikipedia.org/wiki/Domain-specific_language
"domain-specific language"
[YARD]: https://yardoc.org/
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.2.0
3.2.1
108 changes: 68 additions & 40 deletions lib/sparql/client.rb
Expand Up @@ -116,7 +116,14 @@ def initialize(url, **options, &block)
# Close the http connection when object is deallocated
def self.finalize(klass)
proc do
klass.shutdown if klass.respond_to?(:shutdown)
if klass.respond_to?(:shutdown)
begin
# Attempt asynchronous shutdown
Thread.new {klass.shutdown}
rescue ThreadError
klass.shutdown
end
end
end
end

Expand Down Expand Up @@ -423,7 +430,13 @@ def self.parse_json_bindings(json, nodes = {})
end
RDF::Query::Solution.new(row)
end
RDF::Query::Solutions.new(solutions)
solns = RDF::Query::Solutions.new(solutions)

# Set variable names explicitly
if json.fetch('head', {}).has_key?('vars')
solns.variable_names = json['head']['vars'].map(&:to_sym)
end
solns
end
end

Expand Down Expand Up @@ -484,20 +497,23 @@ def self.parse_tsv_bindings(tsv, nodes = {})
vars = tsv.shift.map {|h| h.sub(/^\?/, '')}
solutions = RDF::Query::Solutions.new
tsv.each do |row|
# Flesh out columns which may be missing
vars.each_with_index do |_, i|
row[i] ||= ""
end
solution = RDF::Query::Solution.new
row.each_with_index do |v, i|
if !v.empty?
term = RDF::NTriples.unserialize(v) || case v
when /^\d+\.\d*[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
when /^\d*\.\d+[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
when /^\d*\.\d+$/ then RDF::Literal::Decimal.new(v)
when /^\d+$/ then RDF::Literal::Integer.new(v)
else
RDF::Literal(v)
end
nodes[term.id] = term if term.is_a? RDF::Node
solution[vars[i].to_sym] = term
term = case v
when "" then RDF::Literal("")
when /^\d+\.\d*[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
when /^\d*\.\d+[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
when /^\d*\.\d+$/ then RDF::Literal::Decimal.new(v)
when /^\d+$/ then RDF::Literal::Integer.new(v)
else
RDF::NTriples.unserialize(v) || RDF::Literal(v)
end
nodes[term.id] = term if term.is_a? RDF::Node
solution[vars[i].to_sym] = term
end
solutions << solution
end
Expand All @@ -506,45 +522,57 @@ def self.parse_tsv_bindings(tsv, nodes = {})

##
# @param [String, IO, Nokogiri::XML::Node, REXML::Element] xml
# @param [Symbol] library (:nokogiri)
# One of :nokogiri or :rexml.
# @return [<RDF::Query::Solutions>]
# @see https://www.w3.org/TR/rdf-sparql-json-res/#results
def self.parse_xml_bindings(xml, nodes = {})
def self.parse_xml_bindings(xml, nodes = {}, library: :nokogiri)
xml.force_encoding(::Encoding::UTF_8) if xml.respond_to?(:force_encoding)

if defined?(::Nokogiri)
if defined?(::Nokogiri) && library == :nokogiri
xml = Nokogiri::XML(xml).root unless xml.is_a?(Nokogiri::XML::Document)
case
when boolean = xml.xpath("//sparql:boolean", XMLNS)[0]
boolean.text == 'true'
when results = xml.xpath("//sparql:results", XMLNS)[0]
solutions = results.elements.map do |result|
row = {}
result.elements.each do |binding|
name = binding.attr('name').to_sym
value = binding.elements.first
row[name] = parse_xml_value(value, nodes)
end
RDF::Query::Solution.new(row)
when boolean = xml.xpath("//sparql:boolean", XMLNS)[0]
boolean.text == 'true'
when results = xml.xpath("//sparql:results", XMLNS)[0]
solutions = results.elements.map do |result|
row = {}
result.elements.each do |binding|
name = binding.attr('name').to_sym
value = binding.elements.first
row[name] = parse_xml_value(value, nodes)
end
RDF::Query::Solutions.new(solutions)
RDF::Query::Solution.new(row)
end
solns = RDF::Query::Solutions.new(solutions)

# Set variable names explicitly
var_names = xml.xpath("//sparql:head/sparql:variable/@name", XMLNS)
solns.variable_names = var_names.map(&:to_s)
solns
end
else
# REXML
xml = REXML::Document.new(xml).root unless xml.is_a?(REXML::Element)
case
when boolean = xml.elements['boolean']
boolean.text == 'true'
when results = xml.elements['results']
solutions = results.elements.map do |result|
row = {}
result.elements.each do |binding|
name = binding.attributes['name'].to_sym
value = binding.select { |node| node.kind_of?(::REXML::Element) }.first
row[name] = parse_xml_value(value, nodes)
end
RDF::Query::Solution.new(row)
when boolean = xml.elements['boolean']
boolean.text == 'true'
when results = xml.elements['results']
solutions = results.elements.map do |result|
row = {}
result.elements.each do |binding|
name = binding.attributes['name'].to_sym
value = binding.select { |node| node.kind_of?(::REXML::Element) }.first
row[name] = parse_xml_value(value, nodes)
end
RDF::Query::Solutions.new(solutions)
RDF::Query::Solution.new(row)
end
solns = RDF::Query::Solutions.new(solutions)

# Set variable names explicitly
var_names = xml.elements['head'].elements.map {|e| e.attributes['name']}
solns.variable_names = var_names.map(&:to_sym)
solns
end
end
end
Expand Down Expand Up @@ -578,7 +606,7 @@ def self.parse_xml_value(value, nodes = {})
# @return [RDF::Enumerable]
def parse_rdf_serialization(response, **options)
options = {content_type: response.content_type} unless options[:content_type]
if reader = RDF::Reader.for(options)
if reader = RDF::Reader.for(**options)
reader.new(response.body)
else
raise RDF::ReaderError, "no RDF reader was found for #{options}."
Expand Down
11 changes: 9 additions & 2 deletions sparql-client.gemspec
Expand Up @@ -6,13 +6,20 @@ Gem::Specification.new do |gem|
gem.date = File.mtime('VERSION').strftime('%Y-%m-%d')

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

gem.authors = ['Arto Bendiken', 'Ben Lavender', 'Gregg Kellogg']
gem.email = 'public-rdf-ruby@w3.org'
Expand All @@ -24,7 +31,7 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = '>= 2.6'
gem.requirements = []
gem.add_runtime_dependency 'rdf', '~> 3.2'
gem.add_runtime_dependency 'rdf', '~> 3.2', '>= 3.2.6'
gem.add_runtime_dependency 'net-http-persistent', '~> 4.0', '>= 4.0.1'
gem.add_development_dependency 'rdf-spec', '~> 3.2'
gem.add_development_dependency 'sparql', '~> 3.2'
Expand Down

0 comments on commit 9b10cef

Please sign in to comment.