Skip to content

Commit

Permalink
Finish 3.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jan 19, 2021
2 parents 4f9e705 + b62a630 commit d046078
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 50 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: Jrom81OgSyBklzReIFjUpSMdZbsoPwaFU
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
- 2.5
- 2.6
- 2.7
#- ruby-head # net-http-persistent
- 3.0
- ruby-head
- jruby
steps:
- name: Clone repository
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ group :debug do
gem 'pry-byebug', platforms: :mri
gem 'redcarpet', platforms: :ruby
gem 'ruby-prof', platforms: :mri
gem 'awesome_print', github: 'akshaymohite/awesome_print'
end

group :test do
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a [Ruby][] implementation of [SPARQL][] for [RDF.rb][].

[![Gem Version](https://badge.fury.io/rb/sparql.png)](https://badge.fury.io/rb/sparql)
[![Build Status](https://github.com/ruby-rdf/sparql/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/sparql/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/sparql/badge.svg)](https://coveralls.io/r/ruby-rdf/sparql)
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/sparql/badge.svg?branch=develop)](https://coveralls.io/r/ruby-rdf/sparql?branch=develop)
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)

## Features
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.4
3.1.5
4 changes: 1 addition & 3 deletions etc/doap.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
<https://rubygems.org/gems/sparql> a doap:Project;
doap:name "SPARQL";
doap:shortdesc "SPARQL library for Ruby."@en;
doap:description """
Implements SPARQL grammar parsing to SPARQL Algebra, SPARQL Algebra processing
and includes SPARQL Client for accessing remote repositories."""@en;
doap:description "SPARQL Implements SPARQL 1.1 Query, Update and result formats for the Ruby RDF.rb library suite."@en;
doap:implements <https://www.w3.org/TR/sparql11-query/>,
<https://www.w3.org/TR/sparql11-update/>,
<https://www.w3.org/TR/sparql11-results-json/>,
Expand Down
6 changes: 6 additions & 0 deletions examples/rdfstar-issue76.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT *
WHERE {
<< ?s:marriedTo :Beth >> :at :Kelby .
FILTER (?s = :Peter) .
BIND (<< ?s:marriedTo :Beth >> as ?r) .
}
11 changes: 7 additions & 4 deletions lib/sparql/algebra/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def self.parse(sse, **options, &block)
def self.open(filename, **options, &block)
RDF::Util::File.open_file(filename, **options) do |file|
options[:base_uri] ||= filename
Expression.parse(file, options, &block)
Expression.parse(file, **options, &block)
end
end

Expand Down Expand Up @@ -114,8 +114,11 @@ def self.new(sse, **options)

debug(options) {"#{operator.inspect}(#{operands.map(&:inspect).join(',')})"}
options.delete_if {|k, v| [:debug, :logger, :depth, :prefixes, :base_uri, :update, :validate].include?(k) }
operands << options unless options.empty?
operator.new(*operands)
begin
operator.new(*operands, **options)
rescue ArgumentError => e
error(options) {"Operator=#{operator.inspect}: #{e}"}
end
end

##
Expand Down Expand Up @@ -332,7 +335,7 @@ def optimize!(**options)
# @param [Hash{Symbol => Object}] options ({})
# options passed from query
# @return [Expression] `self`
def evaluate(bindings, options = {})
def evaluate(bindings, **options)
self
end

Expand Down
2 changes: 1 addition & 1 deletion lib/sparql/algebra/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ module RDF::Queryable
# @yieldreturn [void] ignored
# @return [Enumerator]
# @see RDF::Queryable#query_pattern
def query(pattern, options = {}, &block)
def query(pattern, **options, &block)
raise TypeError, "#{self} is not queryable" if respond_to?(:queryable?) && !queryable?

if pattern.is_a?(SPARQL::Algebra::Operator) && pattern.respond_to?(:execute)
Expand Down
16 changes: 8 additions & 8 deletions lib/sparql/algebra/operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ def self.arity
# @option options [Boolean] :memoize (false)
# whether to memoize results for particular operands
# @raise [TypeError] if any operand is invalid
def initialize(*operands)
@options = operands.last.is_a?(Hash) ? operands.pop.dup : {}
def initialize(*operands, **options)
@options = options.dup
@operands = operands.map! do |operand|
case operand
when Array
Expand All @@ -358,7 +358,7 @@ def initialize(*operands)
##
# Deep duplicate operands
def deep_dup
self.class.new(*operands.map(&:deep_dup), @options)
self.class.new(*operands.map(&:deep_dup), **@options)
end

##
Expand Down Expand Up @@ -745,7 +745,7 @@ class Nullary < Operator
##
# @param [Hash{Symbol => Object}] options
# any additional options (see {Operator#initialize})
def initialize(options = {})
def initialize(**options)
super
end
end # Nullary
Expand All @@ -764,7 +764,7 @@ class Unary < Operator
# the operand
# @param [Hash{Symbol => Object}] options
# any additional options (see {Operator#initialize})
def initialize(arg, options = {})
def initialize(arg, **options)
super
end
end # Unary
Expand All @@ -785,7 +785,7 @@ class Binary < Operator
# the second operand
# @param [Hash{Symbol => Object}] options
# any additional options (see {Operator#initialize})
def initialize(arg1, arg2, options = {})
def initialize(arg1, arg2, **options)
super
end
end # Binary
Expand All @@ -808,7 +808,7 @@ class Ternary < Operator
# the third operand
# @param [Hash{Symbol => Object}] options
# any additional options (see {Operator#initialize})
def initialize(arg1, arg2, arg3, options = {})
def initialize(arg1, arg2, arg3, **options)
super
end
end # Ternary
Expand All @@ -833,7 +833,7 @@ class Quaternary < Operator
# the forth operand
# @param [Hash{Symbol => Object}] options
# any additional options (see {Operator#initialize})
def initialize(arg1, arg2, arg3, arg4, options = {})
def initialize(arg1, arg2, arg3, arg4, **options)
super
end
end # Ternary
Expand Down
7 changes: 7 additions & 0 deletions lib/sparql/algebra/operator/avg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Avg < Operator

NAME = :avg

def initialize(*operands, **options)
raise ArgumentError,
"avg operator accepts at most one argument with an optional :distinct" if
(operands - %i{distinct}).length != 1
super
end

##
# The Avg set function calculates the average value for an expression over a group. It is defined in terms of Sum and Count.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/sparql/algebra/operator/bgp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BGP < Operator
# @yieldparam [RDF::Query::Solution] solution
# @yieldreturn [void] ignored
# @return [RDF::Query]
def self.new(*patterns, &block)
def self.new(*patterns, **options, &block)
RDF::Query.new(*patterns, graph_name: false, &block)
end
end # BGP
Expand Down
2 changes: 1 addition & 1 deletion lib/sparql/algebra/operator/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Graph < Operator::Binary
# @param [Array<RDF::Query::Pattern>] patterns
# Quads
# @return [RDF::Query]
def self.new(name, patterns, options = {}, &block)
def self.new(name, patterns, **options, &block)
case patterns
when RDF::Query
# Record that the argument as a (bgp) for re-serialization back to SSE
Expand Down
4 changes: 4 additions & 0 deletions lib/sparql/algebra/operator/left_join.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class LeftJoin < Operator
def execute(queryable, **options, &block)
filter = operand(2)

raise ArgumentError,
"leftjoin operator accepts at most two arguments with an optional filter" if
operands.length < 2 || operands.length > 3

debug(options) {"LeftJoin"}
left = queryable.query(operand(0), depth: options[:depth].to_i + 1, **options)
debug(options) {"=>(leftjoin left) #{left.inspect}"}
Expand Down
7 changes: 7 additions & 0 deletions lib/sparql/algebra/operator/max.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Max < Operator

NAME = :max

def initialize(*operands, **options)
raise ArgumentError,
"max operator accepts at most one argument with an optional :distinct" if
(operands - %i{distinct}).length != 1
super
end

##
# Max is a SPARQL set function that return the maximum value from a group respectively.
#
Expand Down
7 changes: 7 additions & 0 deletions lib/sparql/algebra/operator/min.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Min < Operator

NAME = :min

def initialize(*operands, **options)
raise ArgumentError,
"min operator accepts at most one argument with an optional :distinct" if
(operands - %i{distinct}).length != 1
super
end

##
# Min is a SPARQL set function that return the minimum value from a group respectively.
#
Expand Down
9 changes: 8 additions & 1 deletion lib/sparql/algebra/operator/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ class Operator
# (bgp (triple ?s :dec ?o)))))))
#
# @see https://www.w3.org/TR/sparql11-query/#defn_aggSample
class Sample < Operator::Unary
class Sample < Operator
include Aggregate

NAME = :sample

def initialize(*operands, **options)
raise ArgumentError,
"sample operator accepts at most one argument with an optional :distinct" if
(operands - %i{distinct}).length != 1
super
end

##
# Sample is a set function which returns an arbitrary value from the multiset passed to it.
#
Expand Down
18 changes: 6 additions & 12 deletions lib/sparql/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ module RDF::Queryable
#
# Used to implement the SPARQL `DESCRIBE` operator.
#
# @overload concise_bounded_description(*terms, &block)
# @param [Array<RDF::Term>] terms
# List of terms to include in the results.
#
# @overload concise_bounded_description(*terms, options, &block)
# @overload concise_bounded_description(*terms, **options, &block)
# @param [Array<RDF::Term>] terms
# List of terms to include in the results.
# @param [Hash{Symbol => Object}] options
Expand All @@ -44,16 +40,14 @@ module RDF::Queryable
# @return [RDF::Graph]
#
# @see https://www.w3.org/Submission/CBD/
def concise_bounded_description(*terms, &block)
options = terms.last.is_a?(Hash) ? terms.pop.dup : {}

def concise_bounded_description(*terms, **options, &block)
graph = options[:graph] || RDF::Graph.new

if options[:non_subjects]
query_terms = terms.dup

# Find terms not in self as a subject and recurse with their subjects
terms.reject {|term| self.first(subject: term)}.each do |term|
terms.reject {|term| self.first({subject: term})}.each do |term|
self.query({predicate: term}) do |statement|
query_terms << statement.subject
end
Expand All @@ -67,7 +61,7 @@ def concise_bounded_description(*terms, &block)
end

# Don't consider term if already in graph
terms.reject {|term| graph.first(subject: term)}.each do |term|
terms.reject {|term| graph.first({subject: term})}.each do |term|
# Find statements from queryiable with term as a subject
self.query({subject: term}) do |statement|
yield(statement) if block_given?
Expand All @@ -84,13 +78,13 @@ def concise_bounded_description(*terms, &block)
}, **{}).execute(self).each do |solution|
# Recurse to include this subject
recurse_opts = options.merge(non_subjects: false, graph: graph)
self.concise_bounded_description(solution[:s], recurse_opts, &block)
self.concise_bounded_description(solution[:s], **recurse_opts, &block)
end

# Recurse if object is a BNode and it is not already in subjects
if statement.object.node?
recurse_opts = options.merge(non_subjects: false, graph: graph)
self.concise_bounded_description(statement.object, recurse_opts, &block)
self.concise_bounded_description(statement.object, **recurse_opts, &block)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sparql/grammar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def self.parse(query, **options, &block)
# @raise [RDF::FormatError] if no reader found for the specified format
def self.open(filename, **options, &block)
RDF::Util::File.open_file(filename, **options) do |file|
self.parse(file, options, &block)
self.parse(file, **options, &block)
end
end

Expand Down Expand Up @@ -326,7 +326,7 @@ def self.valid?(query, **options)
# @return [Lexer]
# @raise [Lexer::Error] on invalid input
def self.tokenize(query, **options, &block)
Lexer.tokenize(query, options, &block)
Lexer.tokenize(query, **options, &block)
end
end # Grammar
end # SPARQL
2 changes: 1 addition & 1 deletion lib/sparql/grammar/parser11.rb
Original file line number Diff line number Diff line change
Expand Up @@ -878,10 +878,10 @@ class Parser
# [80] Object ::= GraphNode | EmbTP
production(:Object) do |input, data, callback|
object = data[:GraphNode] || data[:EmbTP]
add_prod_datum(:pattern, data[:pattern])
if object
if prod_data[:Verb]
add_pattern(:Object, subject: prod_data[:Subject], predicate: prod_data[:Verb], object: object)
add_prod_datum(:pattern, data[:pattern])
elsif prod_data[:VerbPath]
add_prod_datum(:path,
SPARQL::Algebra::Expression(:path,
Expand Down
6 changes: 2 additions & 4 deletions sparql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ Gem::Specification.new do |gem|
gem.bindir = %q(bin)
gem.executables = %w(sparql)
gem.require_paths = %w(lib)
gem.description = %(
Implements SPARQL grammar parsing to SPARQL Algebra, SPARQL Algebra processing
and includes SPARQL Client for accessing remote repositories.)
gem.description = %(SPARQL Implements SPARQL 1.1 Query, Update and result formats for the Ruby RDF.rb library suite.)

gem.required_ruby_version = '>= 2.4'
gem.requirements = []
Expand All @@ -29,7 +27,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'ebnf', '~> 2.1'
gem.add_runtime_dependency 'builder', '~> 3.2'
gem.add_runtime_dependency 'sxp', '~> 1.1'
gem.add_runtime_dependency 'sparql-client', '~> 3.1'
gem.add_runtime_dependency 'sparql-client', '~> 3.1', '>= 3.1.2'
gem.add_runtime_dependency 'rdf-xsd', '~> 3.1'

gem.add_development_dependency 'sinatra', '~> 2.0'
Expand Down
2 changes: 1 addition & 1 deletion spec/grammar/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ def self.variable(id, distinguished = true)
def parser(production = nil, **options)
@logger = options.fetch(:logger, false)
Proc.new do |query|
parser = described_class.new(query, {logger: @logger, resolve_iris: true}.merge(options))
parser = described_class.new(query, logger: @logger, resolve_iris: true, **options)
production ? parser.parse(production) : parser
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/suite_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def self.sparql1_1_tests
end

def self.sparql_star_tests
%w(syntax query update).map do |partial|
"https://w3c.github.io/rdf-star/tests/sparql/manifest-#{partial}.jsonld"
["syntax/manifest", "manifest-query", "manifest-update"].map do |man|
"https://w3c.github.io/rdf-star/tests/sparql/#{man}.jsonld"
end
end
end
2 changes: 1 addition & 1 deletion spec/support/matchers/generate.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rspec/matchers'
require 'awesome_print'
require 'amazing_print'

RSpec::Matchers.define :generate do |expected, options|
def parser(**options)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/matchers/have_result_set.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rspec/matchers'
require 'awesome_print'
require 'amazing_print'

::RSpec::Matchers.define :have_result_set do |expected|
def normalize(soln)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/matchers/solutions.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rspec/matchers'
require 'rdf/isomorphic'
require 'rdf/trig'
require 'awesome_print'
require 'amazing_print'

# For examining unordered solution sets
RSpec::Matchers.define :describe_solutions do |expected_solutions, info|
Expand Down

0 comments on commit d046078

Please sign in to comment.