sparql 3.2.4 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/VERSION +1 -1
  4. data/lib/sparql/algebra/aggregate.rb +1 -1
  5. data/lib/sparql/algebra/evaluatable.rb +1 -1
  6. data/lib/sparql/algebra/expression.rb +2 -2
  7. data/lib/sparql/algebra/operator/alt.rb +1 -1
  8. data/lib/sparql/algebra/operator/and.rb +2 -2
  9. data/lib/sparql/algebra/operator/asc.rb +1 -1
  10. data/lib/sparql/algebra/operator/ask.rb +1 -1
  11. data/lib/sparql/algebra/operator/base.rb +1 -1
  12. data/lib/sparql/algebra/operator/bnode.rb +1 -1
  13. data/lib/sparql/algebra/operator/coalesce.rb +1 -1
  14. data/lib/sparql/algebra/operator/concat.rb +1 -1
  15. data/lib/sparql/algebra/operator/construct.rb +1 -1
  16. data/lib/sparql/algebra/operator/dataset.rb +2 -2
  17. data/lib/sparql/algebra/operator/delete_where.rb +1 -1
  18. data/lib/sparql/algebra/operator/distinct.rb +1 -1
  19. data/lib/sparql/algebra/operator/exprlist.rb +1 -1
  20. data/lib/sparql/algebra/operator/extend.rb +2 -3
  21. data/lib/sparql/algebra/operator/filter.rb +1 -1
  22. data/lib/sparql/algebra/operator/group.rb +4 -4
  23. data/lib/sparql/algebra/operator/group_concat.rb +1 -1
  24. data/lib/sparql/algebra/operator/if.rb +3 -3
  25. data/lib/sparql/algebra/operator/in.rb +1 -1
  26. data/lib/sparql/algebra/operator/join.rb +2 -2
  27. data/lib/sparql/algebra/operator/left_join.rb +26 -2
  28. data/lib/sparql/algebra/operator/minus.rb +2 -2
  29. data/lib/sparql/algebra/operator/modify.rb +2 -2
  30. data/lib/sparql/algebra/operator/notin.rb +2 -2
  31. data/lib/sparql/algebra/operator/notoneof.rb +1 -1
  32. data/lib/sparql/algebra/operator/or.rb +2 -2
  33. data/lib/sparql/algebra/operator/order.rb +3 -3
  34. data/lib/sparql/algebra/operator/path.rb +1 -2
  35. data/lib/sparql/algebra/operator/path_plus.rb +1 -1
  36. data/lib/sparql/algebra/operator/path_star.rb +1 -1
  37. data/lib/sparql/algebra/operator/prefix.rb +1 -1
  38. data/lib/sparql/algebra/operator/project.rb +1 -1
  39. data/lib/sparql/algebra/operator/reduced.rb +1 -1
  40. data/lib/sparql/algebra/operator/sequence.rb +2 -2
  41. data/lib/sparql/algebra/operator/slice.rb +1 -1
  42. data/lib/sparql/algebra/operator/union.rb +1 -1
  43. data/lib/sparql/algebra/operator/update.rb +1 -1
  44. data/lib/sparql/algebra/operator/using.rb +1 -1
  45. data/lib/sparql/algebra/operator/with.rb +2 -2
  46. data/lib/sparql/grammar/parser11.rb +2 -2
  47. data/lib/sparql/grammar/terminals11.rb +2 -2
  48. data/lib/sparql/results.rb +2 -1
  49. metadata +45 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 932897287930ea7265a07628e73c13a06b02b9e0d1572b578356166d3c8fe70a
4
- data.tar.gz: 9d17310bc07080475780c8acccbe57acb4bbeb40e3f66ab7b74a09b15ccf0863
3
+ metadata.gz: 10f53a717082f7b94d3e9d207a3cddbd944c15ab7715c551c9a39af6699c77f0
4
+ data.tar.gz: 447bd2c05cb834d81d8e17e8e50eee8b5c972dc116422420b6b742c84a08fe56
5
5
  SHA512:
6
- metadata.gz: e701784500aece828b2cfd41eb0af78a809bda575eed047158e962ff38678d524b179c0c3faef21fc5b5724894ada3066637b608778a1809fdc7b9bda2ffe2a2
7
- data.tar.gz: 77c2520a5f4923a1fe27d589ea6a09b6f5a36fa9c17b564184f206971204fec6988b0941c350e10d812ccfd9b0934e6ae629b82207abfaabf8d7bcc3a380ab33
6
+ metadata.gz: 18c39a3cb233107b4e0c888039e3888ac53eb2982ba2379c126fd777a1ac0834f1c8d50f49fb5a8b081e60781e2f711a6a1f232b5fc394f82b159dd3db5a183b
7
+ data.tar.gz: f206bd6d67b100c2cab74a1e5185cdd393c3fe1eb7529a71e14ffd8d4255064b5d0f97563487f00dbb45126dc87d7eba5953816347d30f89860a62d0c6d538d2
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  An implementation of [SPARQL][] for [RDF.rb][].
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/sparql.png)](https://badge.fury.io/rb/sparql)
5
+ [![Gem Version](https://badge.fury.io/rb/sparql.svg)](https://badge.fury.io/rb/sparql)
6
6
  [![Build Status](https://github.com/ruby-rdf/sparql/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/sparql/actions?query=workflow%3ACI)
7
7
  [![Coverage Status](https://coveralls.io/repos/ruby-rdf/sparql/badge.svg?branch=develop)](https://coveralls.io/r/ruby-rdf/sparql?branch=develop)
8
8
  [![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.4
1
+ 3.2.6
@@ -29,7 +29,7 @@ module SPARQL; module Algebra
29
29
  args_enum = solutions.map do |solution|
30
30
  operands.map do |operand|
31
31
  begin
32
- operand.evaluate(solution, depth: options[:depth].to_i + 1, **options)
32
+ operand.evaluate(solution, **options.merge(depth: options[:depth].to_i + 1))
33
33
  rescue TypeError
34
34
  # Ignore errors
35
35
  nil
@@ -14,7 +14,7 @@ module SPARQL; module Algebra
14
14
  # @return [RDF::Term]
15
15
  # @abstract
16
16
  def evaluate(bindings, **options)
17
- args = operands.map { |operand| operand.evaluate(bindings, depth: options[:depth].to_i + 1, **options) }
17
+ args = operands.map { |operand| operand.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1)) }
18
18
  options[:memoize] ? memoize(*args, **options) : apply(*args, **options)
19
19
  end
20
20
 
@@ -112,7 +112,7 @@ module SPARQL; module Algebra
112
112
  return case sse.first
113
113
  when Array
114
114
  debug(options) {"Map array elements #{sse}"}
115
- sse.map {|s| self.new(s, parent_operator: parent_operator, depth: options[:depth].to_i + 1, **options)}
115
+ sse.map {|s| self.new(s, parent_operator: parent_operator, **options.merge(depth: options[:depth].to_i + 1))}
116
116
  else
117
117
  debug(options) {"No operator found for #{sse.first}"}
118
118
  sse.map do |s|
@@ -127,7 +127,7 @@ module SPARQL; module Algebra
127
127
  debug(options) {"Operator=#{operator.inspect}, Operand=#{operand.inspect}"}
128
128
  case operand
129
129
  when Array
130
- self.new(operand, parent_operator: operator, depth: options[:depth].to_i + 1, **options)
130
+ self.new(operand, parent_operator: operator, **options.merge(depth: options[:depth].to_i + 1))
131
131
  when Operator, Variable, RDF::Term, RDF::Query, Symbol
132
132
  operand
133
133
  when TrueClass, FalseClass, Numeric, String, DateTime, Date, Time
@@ -70,7 +70,7 @@ module SPARQL; module Algebra
70
70
  end
71
71
 
72
72
  query = Union.new(qa, qb)
73
- queryable.query(query, depth: options[:depth].to_i + 1, **options, &block)
73
+ queryable.query(query, **options.merge(depth: options[:depth].to_i + 1), &block)
74
74
  end
75
75
 
76
76
  ##
@@ -52,13 +52,13 @@ module SPARQL; module Algebra
52
52
  # @raise [TypeError] if the operands could not be coerced to boolean literals
53
53
  def evaluate(bindings, **options)
54
54
  begin
55
- left = boolean(operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
55
+ left = boolean(operand(0).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))).true?
56
56
  rescue TypeError
57
57
  left = nil
58
58
  end
59
59
 
60
60
  begin
61
- right = boolean(operand(1).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
61
+ right = boolean(operand(1).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))).true?
62
62
  rescue TypeError
63
63
  right = nil
64
64
  end
@@ -33,7 +33,7 @@ module SPARQL; module Algebra
33
33
  # options passed from query
34
34
  # @return [RDF::Term]
35
35
  def evaluate(bindings, **options)
36
- operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options)
36
+ operand(0).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))
37
37
  end
38
38
 
39
39
  ##
@@ -37,7 +37,7 @@ module SPARQL; module Algebra
37
37
  # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
38
38
  def execute(queryable, **options)
39
39
  debug(options) {"Ask #{operands.first}"}
40
- res = boolean(!queryable.query(operands.last, depth: options[:depth].to_i + 1, **options).empty?)
40
+ res = boolean(!queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1)).empty?)
41
41
  yield res if block_given?
42
42
  res
43
43
  end
@@ -38,7 +38,7 @@ module SPARQL; module Algebra
38
38
  def execute(queryable, **options, &block)
39
39
  debug(options) {"Base #{operands.first}"}
40
40
  Operator.base_uri = operands.first
41
- queryable.query(operands.last, depth: options[:depth].to_i + 1, **options, &block)
41
+ queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1), &block)
42
42
  end
43
43
 
44
44
  ##
@@ -57,7 +57,7 @@ module SPARQL; module Algebra
57
57
  # options passed from query
58
58
  # @return [RDF::Term]
59
59
  def evaluate(bindings, **options)
60
- args = operands.map { |operand| operand.evaluate(bindings, depth: options[:depth].to_i + 1, **options) }
60
+ args = operands.map { |operand| operand.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1)) }
61
61
  apply(args.first, bindings)
62
62
  end
63
63
 
@@ -57,7 +57,7 @@ module SPARQL; module Algebra
57
57
  def evaluate(bindings, **options)
58
58
  operands.each do |op|
59
59
  begin
60
- return op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
60
+ return op.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))
61
61
  rescue
62
62
  end
63
63
  end
@@ -48,7 +48,7 @@ module SPARQL; module Algebra
48
48
  # @return [RDF::Term]
49
49
  # @raise [TypeError] if any operand is not a literal
50
50
  def evaluate(bindings, **options)
51
- ops = operands.map {|op| op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)}
51
+ ops = operands.map {|op| op.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))}
52
52
 
53
53
  raise TypeError, "expected all plain literal operands" unless ops.all? {|op| op.literal? && op.plain?}
54
54
 
@@ -51,7 +51,7 @@ module SPARQL; module Algebra
51
51
  patterns = operands.first
52
52
  query = operands.last
53
53
 
54
- queryable.query(query, depth: options[:depth].to_i + 1, **options).each do |solution|
54
+ queryable.query(query, **options.merge(depth: options[:depth].to_i + 1)).each do |solution|
55
55
  debug(options) {"(construct apply) #{solution.inspect} to BGP"}
56
56
 
57
57
  # Create a mapping from BNodes within the pattern list to newly constructed BNodes
@@ -149,7 +149,7 @@ module SPARQL; module Algebra
149
149
  debug(options) {"Dataset"}
150
150
  if %i(default-graph-uri named-graph-uri).any? {|k| options.key?(k)}
151
151
  debug("=> Skip constructing merge repo due to options", options)
152
- return queryable.query(operands.last, depth: options[:depth].to_i + 1, **options, &base)
152
+ return queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1), &base)
153
153
  end
154
154
 
155
155
  default_datasets = []
@@ -180,7 +180,7 @@ module SPARQL; module Algebra
180
180
  aggregate = RDF::AggregateRepo.new(queryable)
181
181
  named_datasets.each {|name| aggregate.named(name) if queryable.has_graph?(name)}
182
182
  aggregate.default(*default_datasets.select {|name| queryable.has_graph?(name)})
183
- aggregate.query(operands.last, depth: options[:depth].to_i + 1, **options, &base)
183
+ aggregate.query(operands.last, **options.merge(depth: options[:depth].to_i + 1), &base)
184
184
  end
185
185
 
186
186
  ##
@@ -53,7 +53,7 @@ module SPARQL; module Algebra
53
53
  end
54
54
  query = RDF::Query.new(*patterns, **{}) # FIXME: added hash argument needed until Statement#to_hash removed.
55
55
  debug(options) {"DeleteWhere query #{query.to_sse}"}
56
- query.execute(queryable, depth: options[:depth].to_i + 1, **options) do |solution|
56
+ query.execute(queryable, **options.merge(depth: options[:depth].to_i + 1)) do |solution|
57
57
  debug(options) {"DeleteWhere solution #{solution.to_sse}"}
58
58
  query.each_statement do |pattern|
59
59
  pattern = pattern.dup.bind(solution)
@@ -40,7 +40,7 @@ module SPARQL; module Algebra
40
40
  # the resulting solution sequence
41
41
  # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
42
42
  def execute(queryable, **options, &block)
43
- @solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options).distinct
43
+ @solutions = queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1)).distinct
44
44
  @solutions.each(&block) if block_given?
45
45
  @solutions
46
46
  end
@@ -50,7 +50,7 @@ module SPARQL; module Algebra
50
50
  # @return [RDF::Literal::Boolean] `true` or `false`
51
51
  # @raise [TypeError] if the operands could not be coerced to a boolean literal
52
52
  def evaluate(bindings, **options)
53
- res = operands.all? {|op| boolean(op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true? }
53
+ res = operands.all? {|op| boolean(op.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))).true? }
54
54
  RDF::Literal(res) # FIXME: error handling
55
55
  end
56
56
  end # Exprlist
@@ -82,7 +82,7 @@ module SPARQL; module Algebra
82
82
  # @see https://www.w3.org/TR/sparql11-query/#evaluation
83
83
  def execute(queryable, **options, &block)
84
84
  debug(options) {"Extend"}
85
- @solutions = operand(1).execute(queryable, depth: options[:depth].to_i + 1, **options)
85
+ @solutions = operand(1).execute(queryable, **options.merge(depth: options[:depth].to_i + 1))
86
86
  @solutions.each do |solution|
87
87
  # Re-bind to bindings, if defined, as they might not be found in solution
88
88
  options[:bindings].each_binding do |name, value|
@@ -93,8 +93,7 @@ module SPARQL; module Algebra
93
93
  operand(0).each do |(var, expr)|
94
94
  begin
95
95
  val = expr.evaluate(solution, queryable: queryable,
96
- depth: options[:depth].to_i + 1,
97
- **options)
96
+ **options.merge(depth: options[:depth].to_i + 1))
98
97
  debug(options) {"===> + #{var} => #{val.inspect}"}
99
98
  val = val.dup.bind(solution) if val.is_a?(RDF::Query::Pattern)
100
99
  solution.bindings[var.to_sym] = val
@@ -48,7 +48,7 @@ module SPARQL; module Algebra
48
48
  debug(options) {"Filter #{operands.first.to_sxp}"}
49
49
  opts = options.merge(queryable: queryable, depth: options[:depth].to_i + 1)
50
50
  @solutions = RDF::Query::Solutions()
51
- queryable.query(operands.last, depth: options[:depth].to_i + 1, **options) do |solution|
51
+ queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1)) do |solution|
52
52
  # Re-bind to bindings, if defined, as they might not be found in solution
53
53
  options[:bindings].each_binding do |name, value|
54
54
  solution[name] ||= value if operands.first.variables.include?(name)
@@ -35,10 +35,10 @@ module SPARQL; module Algebra
35
35
  # @example SSE (HAVING aggregate)
36
36
  # (prefix ((: <http://www.example.org/>))
37
37
  # (project (?s ?avg)
38
- # (filter (<= ??.0 2.0)
38
+ # (filter (<= ??.1 2.0)
39
39
  # (extend ((?avg ??.0))
40
- # (group (?s) ((??.0 (avg ?o)))
41
- # (bgp (triple ?s ?p ?o)))))) )
40
+ # (group (?s) ((??.0 (avg ?o)) (??.1 (avg ?o)))
41
+ # (bgp (triple ?s ?p ?o)))))))
42
42
  #
43
43
  # @example SPARQL Grammar (non-trivial filters)
44
44
  # PREFIX : <http://example.com/data/#>
@@ -82,7 +82,7 @@ module SPARQL; module Algebra
82
82
  exprlist = operands.first
83
83
  query = operands.last
84
84
  aggregates = operands.length == 3 ? operand(1) : []
85
- solutions = queryable.query(query, depth: options[:depth].to_i + 1, **options)
85
+ solutions = queryable.query(query, **options.merge(depth: options[:depth].to_i + 1))
86
86
 
87
87
  groups = solutions.group_by do |solution|
88
88
  # Evaluate each exprlist operand to get groups where each key is a new solution
@@ -55,7 +55,7 @@ module SPARQL; module Algebra
55
55
  sep = operands.length == 2 ? operand(0).last : RDF::Literal(' ')
56
56
  args_enum = solutions.map do |solution|
57
57
  begin
58
- operands.last.evaluate(solution, depth: options[:depth].to_i + 1, **options)
58
+ operands.last.evaluate(solution, **options.merge(depth: options[:depth].to_i + 1))
59
59
  rescue TypeError
60
60
  # Ignore errors
61
61
  nil
@@ -42,9 +42,9 @@ module SPARQL; module Algebra
42
42
  # @return [RDF::Term]
43
43
  # @raise [TypeError]
44
44
  def evaluate(bindings, **options)
45
- operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options) == RDF::Literal::TRUE ?
46
- operand(1).evaluate(bindings, depth: options[:depth].to_i + 1, **options) :
47
- operand(2).evaluate(bindings, depth: options[:depth].to_i + 1, **options)
45
+ operand(0).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1)) == RDF::Literal::TRUE ?
46
+ operand(1).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1)) :
47
+ operand(2).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))
48
48
  rescue
49
49
  raise TypeError
50
50
  end
@@ -48,7 +48,7 @@ module SPARQL; module Algebra
48
48
  error_found = false
49
49
  found = operands[1..-1].any? do |op|
50
50
  begin
51
- lhs == op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
51
+ lhs == op.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))
52
52
  rescue TypeError
53
53
  error_found = true
54
54
  end
@@ -66,10 +66,10 @@ module SPARQL; module Algebra
66
66
  # Generate solutions independently, merge based on solution compatibility
67
67
  debug(options) {"Join #{operands.to_sse}"}
68
68
 
69
- left = queryable.query(operand(0), depth: options[:depth].to_i + 1, **options)
69
+ left = queryable.query(operand(0), **options.merge(depth: options[:depth].to_i + 1))
70
70
  debug(options) {"(join)=>(left) #{left.map(&:to_h).to_sse}"}
71
71
 
72
- right = queryable.query(operand(1), depth: options[:depth].to_i + 1, **options)
72
+ right = queryable.query(operand(1), **options.merge(depth: options[:depth].to_i + 1))
73
73
  debug(options) {"(join)=>(right) #{right.map(&:to_h).to_sse}"}
74
74
 
75
75
  @solutions = RDF::Query::Solutions(left.map do |s1|
@@ -54,10 +54,10 @@ module SPARQL; module Algebra
54
54
  operands.length < 2 || operands.length > 3
55
55
 
56
56
  debug(options) {"LeftJoin"}
57
- left = queryable.query(operand(0), depth: options[:depth].to_i + 1, **options)
57
+ left = queryable.query(operand(0), **options.merge(depth: options[:depth].to_i + 1))
58
58
  debug(options) {"=>(leftjoin left) #{left.inspect}"}
59
59
 
60
- right = queryable.query(operand(1), depth: options[:depth].to_i + 1, **options)
60
+ right = queryable.query(operand(1), **options.merge(depth: options[:depth].to_i + 1))
61
61
  debug(options) {"=>(leftjoin right) #{right.inspect}"}
62
62
 
63
63
  # LeftJoin(Ω1, Ω2, expr) =
@@ -71,6 +71,30 @@ module SPARQL; module Algebra
71
71
  s[name] = value if filter.variables.include?(name)
72
72
  end if options[:bindings] && filter.respond_to?(:variables)
73
73
 
74
+ # See https://github.com/w3c/rdf-tests/pull/83#issuecomment-1324220844 for @afs's discussion of the simplified/not-simplified issue.
75
+ #
76
+ # The difference is when simplification is applied. It matters for OPTIONAL because OPTIONAL { ... FILTER(...) } puts the filter into the LeftJoin expressions. In LeftJoin, the FILTER can see the left-hand-side variables. (SQL: LEFT JOIN ... ON ...)
77
+ #
78
+ # For OPTIONAL { { ... FILTER(...) } }, the inner part is Join({}, {.... FILTER }).
79
+ #
80
+ # if simplify happens while coming back up the tree generating algebra operations, it removes the join i.e. the inner of {{ }}, and passes "... FILTER()" to the OPTIONAL. The effect of the extra nesting in {{ }} is lost and it exposes the filter to the OPTIONAL rule.
81
+ #
82
+ # if simplification happens as a step after the whole algebra is converted, this does not happen. Compiling the OPTIONAL see a join and the filter is not at the top level of the OPTIONAl block and so not handled in the LeftJoin.
83
+ #
84
+ # Use case:
85
+ #
86
+ # # Include name if person over 18
87
+ # SELECT *
88
+ # { ?person :age ?age
89
+ # OPTIONAL { ?person :name ?name. FILTER(?age > 18) }
90
+ # }
91
+ # Hindsight: a better syntax would be call out if the filter needed access to the LHS.
92
+ #
93
+ # OPTIONAL FILTER(....) { }
94
+ #
95
+ # But we are where we are.
96
+ #
97
+ # (a "no conditions on LeftJoin" approach would mean users having to duplicate parts of their query - possibly quite large parts.)
74
98
  expr = filter ? boolean(filter.evaluate(s)).true? : true rescue false
75
99
  debug(options) {"===>(evaluate) #{s.inspect}"} if filter
76
100
 
@@ -71,9 +71,9 @@ module SPARQL; module Algebra
71
71
  #
72
72
  # card[Minus(Ω1, Ω2)](μ) = card[Ω1](μ)
73
73
  debug(options) {"Minus"}
74
- left = queryable.query(operand(0), depth: options[:depth].to_i + 1, **options)
74
+ left = queryable.query(operand(0), **options.merge(depth: options[:depth].to_i + 1))
75
75
  debug(options) {"(minus left) #{left.inspect}"}
76
- right = queryable.query(operand(1), depth: options[:depth].to_i + 1, **options)
76
+ right = queryable.query(operand(1), **options.merge(depth: options[:depth].to_i + 1))
77
77
  debug(options) {"(minus right) #{right.inspect}"}
78
78
  @solutions = left.minus(right)
79
79
  @solutions.each(&block) if block_given?
@@ -71,12 +71,12 @@ module SPARQL; module Algebra
71
71
  query = Operator::Using.new((defaults + named), query, **options)
72
72
  end
73
73
 
74
- queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
74
+ queryable.query(query, **options.merge(depth: options[:depth].to_i + 1)) do |solution|
75
75
  debug(options) {"(solution)=>#{solution.inspect}"}
76
76
 
77
77
  # Execute each operand with queryable and solution
78
78
  operands.each do |op|
79
- op.execute(queryable, solutions: solution, depth: options[:depth].to_i + 1, **options)
79
+ op.execute(queryable, solutions: solution, **options.merge(depth: options[:depth].to_i + 1))
80
80
  end
81
81
  end
82
82
  queryable
@@ -48,11 +48,11 @@ module SPARQL; module Algebra
48
48
  # @return [RDF::Literal::Boolean] `true` or `false`
49
49
  # @raise [TypeError] if term is not found and any operand raises an error
50
50
  def evaluate(bindings, **options)
51
- lhs = operands.first.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
51
+ lhs = operands.first.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))
52
52
  error_found = false
53
53
  found = operands[1..-1].any? do |op|
54
54
  begin
55
- lhs == op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
55
+ lhs == op.evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))
56
56
  rescue TypeError
57
57
  error_found = true
58
58
  end
@@ -50,7 +50,7 @@ module SPARQL; module Algebra
50
50
  q.pattern [subject, v, object]
51
51
  end
52
52
  query = Filter.new(NotIn.new(v, *operands), bgp)
53
- queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
53
+ queryable.query(query, **options.merge(depth: options[:depth].to_i + 1)) do |solution|
54
54
  solution.bindings.delete(v.to_sym)
55
55
  debug(options) {"(solution)-> #{solution.to_h.to_sse}"}
56
56
  block.call(solution)
@@ -56,13 +56,13 @@ module SPARQL; module Algebra
56
56
  # @raise [TypeError] if the operands could not be coerced to a boolean literal
57
57
  def evaluate(bindings, **options)
58
58
  begin
59
- left = boolean(operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
59
+ left = boolean(operand(0).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))).true?
60
60
  rescue TypeError
61
61
  left = nil
62
62
  end
63
63
 
64
64
  begin
65
- right = boolean(operand(1).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
65
+ right = boolean(operand(1).evaluate(bindings, **options.merge(depth: options[:depth].to_i + 1))).true?
66
66
  rescue TypeError
67
67
  right = nil
68
68
  end
@@ -86,12 +86,12 @@ module SPARQL; module Algebra
86
86
  def execute(queryable, **options, &block)
87
87
 
88
88
  debug(options) {"Order"}
89
- @solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options).order do |a, b|
89
+ @solutions = queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1)).order do |a, b|
90
90
  operand(0).inject(0) do |memo, op|
91
91
  debug(options) {"(order) #{op.inspect}"}
92
92
  memo = begin
93
- a_eval = op.evaluate(a, queryable: queryable, depth: options[:depth].to_i + 1, **options) rescue nil
94
- b_eval = op.evaluate(b, queryable: queryable, depth: options[:depth].to_i + 1, **options) rescue nil
93
+ a_eval = op.evaluate(a, queryable: queryable, **options.merge(depth: options[:depth].to_i + 1)) rescue nil
94
+ b_eval = op.evaluate(b, queryable: queryable, **options.merge(depth: options[:depth].to_i + 1)) rescue nil
95
95
  comp = begin
96
96
  Operator::Compare.evaluate(a_eval, b_eval, order_by: true).to_s.to_i
97
97
  rescue TypeError
@@ -50,8 +50,7 @@ module SPARQL; module Algebra
50
50
  subject: subject,
51
51
  object: object,
52
52
  graph_name: options.fetch(:graph_name, false),
53
- depth: options[:depth].to_i + 1,
54
- **options
53
+ **options.merge(depth: options[:depth].to_i + 1)
55
54
  ) do |solution|
56
55
  @solutions << solution
57
56
  end
@@ -73,7 +73,7 @@ module SPARQL; module Algebra
73
73
  # Keep track of solutions
74
74
  # Recurse into query
75
75
  immediate_solutions =
76
- query.execute(queryable, depth: options[:depth].to_i + 1, **options)
76
+ query.execute(queryable, **options.merge(depth: options[:depth].to_i + 1))
77
77
 
78
78
  # For all solutions, if they are not in the accumulator, add them and recurse, otherwise skip
79
79
  recursive_solutions = RDF::Query::Solutions.new
@@ -48,7 +48,7 @@ module SPARQL; module Algebra
48
48
 
49
49
  # (:x :p* :y) => (:x (:p+)? :y)
50
50
  query = PathOpt.new(PathPlus.new(*operands))
51
- query.execute(queryable, depth: options[:depth].to_i + 1, **options, &block)
51
+ query.execute(queryable, **options.merge(depth: options[:depth].to_i + 1), &block)
52
52
  end
53
53
  ##
54
54
  #
@@ -37,7 +37,7 @@ module SPARQL; module Algebra
37
37
  # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
38
38
  def execute(queryable, **options, &block)
39
39
  debug(options) {"Prefix"}
40
- @solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options, &block)
40
+ @solutions = queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1), &block)
41
41
  end
42
42
 
43
43
  ##
@@ -101,7 +101,7 @@ module SPARQL; module Algebra
101
101
  # the resulting solution sequence
102
102
  # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
103
103
  def execute(queryable, **options, &block)
104
- @solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options)
104
+ @solutions = queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1))
105
105
  @solutions.variable_names = self.variables.keys
106
106
  @solutions = @solutions.project(*(operands.first)) unless operands.first.empty?
107
107
  @solutions.each(&block) if block_given?
@@ -41,7 +41,7 @@ module SPARQL; module Algebra
41
41
  # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
42
42
  def execute(queryable, **options, &block)
43
43
  @solutions = operands.last.
44
- execute(queryable, depth: options[:depth].to_i + 1, **options).reduced
44
+ execute(queryable, **options.merge(depth: options[:depth].to_i + 1)).reduced
45
45
  @solutions.each(&block) if block_given?
46
46
  @solutions
47
47
  end
@@ -31,11 +31,11 @@ module SPARQL; module Algebra
31
31
  def execute(queryable, **options)
32
32
  debug(options) {"Sequence #{operands.to_sse}"}
33
33
 
34
- last = queryable.query(operands.shift, depth: options[:depth].to_i + 1, **options)
34
+ last = queryable.query(operands.shift, **options.merge(depth: options[:depth].to_i + 1))
35
35
  debug(options) {"(sequence)=>(last) #{last.map(&:to_h).to_sse}"}
36
36
 
37
37
  operands.each do |op|
38
- this = queryable.query(op, depth: options[:depth].to_i + 1, **options)
38
+ this = queryable.query(op, **options.merge(depth: options[:depth].to_i + 1))
39
39
  debug(options) {"(sequence)=>(this) #{this.map(&:to_h).to_sse}"}
40
40
 
41
41
  last = last.map do |s1|
@@ -57,7 +57,7 @@ module SPARQL; module Algebra
57
57
  def execute(queryable, **options, &block)
58
58
  offset = operands[0] == :_ ? 0 : operands[0].to_i
59
59
  limit = operands[1] == :_ ? -1 : operands[1].to_i
60
- @solutions = operands.last. execute(queryable, depth: options[:depth].to_i + 1, **options)
60
+ @solutions = operands.last. execute(queryable, **options.merge(depth: options[:depth].to_i + 1))
61
61
  @solutions.offset(operands[0]) unless operands[0] == :_
62
62
  @solutions.limit(operands[1]) unless operands[1] == :_
63
63
  @solutions.each(&block) if block_given?
@@ -41,7 +41,7 @@ module SPARQL; module Algebra
41
41
  def execute(queryable, **options, &block)
42
42
  debug(options) {"Union"}
43
43
  @solutions = RDF::Query::Solutions(operands.inject([]) do |memo, op|
44
- solns = op.execute(queryable, depth: options[:depth].to_i + 1, **options)
44
+ solns = op.execute(queryable, **options.merge(depth: options[:depth].to_i + 1))
45
45
  debug(options) {"=> (op) #{solns.inspect}"}
46
46
  memo + solns
47
47
  end)
@@ -68,7 +68,7 @@ module SPARQL; module Algebra
68
68
  debug(options) {"Update"}
69
69
  raise IOError, "queryable is not mutable" unless queryable.mutable?
70
70
  operands.each do |op|
71
- op.execute(queryable, depth: options[:depth].to_i + 1, **options)
71
+ op.execute(queryable, **options.merge(depth: options[:depth].to_i + 1))
72
72
  end
73
73
  queryable
74
74
  end
@@ -67,7 +67,7 @@ module SPARQL; module Algebra
67
67
  # @see https://www.w3.org/TR/sparql11-update/
68
68
  def execute(queryable, **options, &block)
69
69
  debug(options) {"Using"}
70
- Dataset.new(*operands).execute(queryable, depth: options[:depth].to_i + 1, **options, &block)
70
+ Dataset.new(*operands).execute(queryable, **options.merge(depth: options[:depth].to_i + 1), &block)
71
71
  end
72
72
 
73
73
  ##
@@ -69,12 +69,12 @@ module SPARQL; module Algebra
69
69
  query = operands.shift
70
70
 
71
71
  # Restrict query portion to this graph
72
- queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
72
+ queryable.query(query, **options.merge(depth: options[:depth].to_i + 1)) do |solution|
73
73
  debug(options) {"(solution)=>#{solution.inspect}"}
74
74
 
75
75
  # Execute each operand with queryable and solution
76
76
  operands.each do |op|
77
- op.execute(queryable, solutions: solution, depth: options[:depth].to_i + 1, **options)
77
+ op.execute(queryable, solutions: solution, **options.merge(depth: options[:depth].to_i + 1))
78
78
  end
79
79
  end
80
80
  end
@@ -1610,7 +1610,7 @@ module SPARQL::Grammar
1610
1610
  if data[:_Compare_Numeric]
1611
1611
  add_prod_datum(:Expression, SPARQL::Algebra::Expression.for(data[:_Compare_Numeric].insert(1, *data[:Expression])))
1612
1612
  elsif data[:in]
1613
- expr = (data[:Expression] + data[:in]).reject {|v| v.equal?(RDF.nil)}
1613
+ expr = (data[:Expression] + data[:in]).reject {|v| v.eql?(RDF.nil)}
1614
1614
  add_prod_datum(:Expression, SPARQL::Algebra::Expression.for(expr.unshift(:in)))
1615
1615
  elsif data[:notin]
1616
1616
  expr = (data[:Expression] + data[:notin]).reject {|v| v.equal?(RDF.nil)}
@@ -2452,7 +2452,7 @@ module SPARQL::Grammar
2452
2452
 
2453
2453
  # Replace aggregates in expr as above
2454
2454
  expr.replace_aggregate! do |function|
2455
- if avf = aggregates.detect {|(_, f)| f == function}
2455
+ if avf = aggregates.detect {|(_, f)| f.equal?(function)}
2456
2456
  avf.first
2457
2457
  else
2458
2458
  # Allocate a temporary variable for this function, and retain the mapping for outside the group
@@ -94,10 +94,10 @@ module SPARQL::Grammar
94
94
  STR_EXPR = %r(ABS|ADD|ADJUST|ALL|ASC|ASK|AS|AVG|BASE|BINDINGS|BIND
95
95
  |BNODE|BOUND|BY|CEIL|CLEAR|COALESCE|CONCAT
96
96
  |CONSTRUCT|CONTAINS|COPY|COUNT|CREATE|DATATYPE|DAY
97
- |DEFAULT|DELETE#{WS}DATA|DELETE#{WS}WHERE|DELETE
97
+ |DEFAULT|DELETE\s+DATA|DELETE\s+WHERE|DELETE
98
98
  |DESCRIBE|DESC|DISTINCT|DROP|ENCODE_FOR_URI|EXISTS
99
99
  |FILTER|FLOOR|FROM|GRAPH|GROUP_CONCAT|GROUP|HAVING
100
- |HOURS|IF|INSERT#{WS}DATA|INSERT|INTO|IN|IRI
100
+ |HOURS|IF|INSERT\s+DATA|INSERT|INTO|IN|IRI
101
101
  |LANGMATCHES|LANGTAG|LANG|LCASE|LIMIT|LOAD
102
102
  |MAX|MD5|MINUS|MINUTES|MIN|MONTH|MOVE
103
103
  |NAMED|NOT|NOW|OFFSET|OPTIONAL
@@ -280,7 +280,8 @@ module SPARQL
280
280
  end
281
281
 
282
282
  content_type ||= SPARQL::Results::MIME_TYPES[format] if format
283
-
283
+
284
+ serialization = serialization.dup if serialization.frozen?
284
285
  serialization.instance_eval do
285
286
  define_singleton_method(:content_type) { content_type }
286
287
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparql
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-07 00:00:00.000000000 Z
12
+ date: 2023-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '3.2'
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 3.2.8
23
+ version: 3.2.11
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '3.2'
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.2.8
33
+ version: 3.2.11
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdf-aggregate-repo
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,9 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.2'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.2.1
41
44
  type: :runtime
42
45
  prerelease: false
43
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -45,26 +48,29 @@ dependencies:
45
48
  - - "~>"
46
49
  - !ruby/object:Gem::Version
47
50
  version: '3.2'
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.1
48
54
  - !ruby/object:Gem::Dependency
49
55
  name: ebnf
50
56
  requirement: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '2.2'
60
+ version: '2.3'
55
61
  - - ">="
56
62
  - !ruby/object:Gem::Version
57
- version: 2.3.1
63
+ version: 2.3.5
58
64
  type: :runtime
59
65
  prerelease: false
60
66
  version_requirements: !ruby/object:Gem::Requirement
61
67
  requirements:
62
68
  - - "~>"
63
69
  - !ruby/object:Gem::Version
64
- version: '2.2'
70
+ version: '2.3'
65
71
  - - ">="
66
72
  - !ruby/object:Gem::Version
67
- version: 2.3.1
73
+ version: 2.3.5
68
74
  - !ruby/object:Gem::Dependency
69
75
  name: builder
70
76
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +78,9 @@ dependencies:
72
78
  - - "~>"
73
79
  - !ruby/object:Gem::Version
74
80
  version: '3.2'
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 3.2.4
75
84
  type: :runtime
76
85
  prerelease: false
77
86
  version_requirements: !ruby/object:Gem::Requirement
@@ -79,6 +88,9 @@ dependencies:
79
88
  - - "~>"
80
89
  - !ruby/object:Gem::Version
81
90
  version: '3.2'
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 3.2.4
82
94
  - !ruby/object:Gem::Dependency
83
95
  name: logger
84
96
  requirement: !ruby/object:Gem::Requirement
@@ -102,7 +114,7 @@ dependencies:
102
114
  version: '1.2'
103
115
  - - ">="
104
116
  - !ruby/object:Gem::Version
105
- version: 1.2.2
117
+ version: 1.2.4
106
118
  type: :runtime
107
119
  prerelease: false
108
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -112,7 +124,7 @@ dependencies:
112
124
  version: '1.2'
113
125
  - - ">="
114
126
  - !ruby/object:Gem::Version
115
- version: 1.2.2
127
+ version: 1.2.4
116
128
  - !ruby/object:Gem::Dependency
117
129
  name: sparql-client
118
130
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +134,7 @@ dependencies:
122
134
  version: '3.2'
123
135
  - - ">="
124
136
  - !ruby/object:Gem::Version
125
- version: 3.2.1
137
+ version: 3.2.2
126
138
  type: :runtime
127
139
  prerelease: false
128
140
  version_requirements: !ruby/object:Gem::Requirement
@@ -132,7 +144,7 @@ dependencies:
132
144
  version: '3.2'
133
145
  - - ">="
134
146
  - !ruby/object:Gem::Version
135
- version: 3.2.1
147
+ version: 3.2.2
136
148
  - !ruby/object:Gem::Dependency
137
149
  name: rdf-xsd
138
150
  requirement: !ruby/object:Gem::Requirement
@@ -153,42 +165,54 @@ dependencies:
153
165
  requirements:
154
166
  - - "~>"
155
167
  - !ruby/object:Gem::Version
156
- version: '2.2'
168
+ version: '3.0'
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: 3.0.5
157
172
  type: :development
158
173
  prerelease: false
159
174
  version_requirements: !ruby/object:Gem::Requirement
160
175
  requirements:
161
176
  - - "~>"
162
177
  - !ruby/object:Gem::Version
163
- version: '2.2'
178
+ version: '3.0'
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: 3.0.5
164
182
  - !ruby/object:Gem::Dependency
165
183
  name: rack
166
184
  requirement: !ruby/object:Gem::Requirement
167
185
  requirements:
168
- - - "~>"
186
+ - - ">="
169
187
  - !ruby/object:Gem::Version
170
188
  version: '2.2'
189
+ - - "<"
190
+ - !ruby/object:Gem::Version
191
+ version: '4'
171
192
  type: :development
172
193
  prerelease: false
173
194
  version_requirements: !ruby/object:Gem::Requirement
174
195
  requirements:
175
- - - "~>"
196
+ - - ">="
176
197
  - !ruby/object:Gem::Version
177
198
  version: '2.2'
199
+ - - "<"
200
+ - !ruby/object:Gem::Version
201
+ version: '4'
178
202
  - !ruby/object:Gem::Dependency
179
203
  name: rack-test
180
204
  requirement: !ruby/object:Gem::Requirement
181
205
  requirements:
182
206
  - - "~>"
183
207
  - !ruby/object:Gem::Version
184
- version: '1.1'
208
+ version: '2.1'
185
209
  type: :development
186
210
  prerelease: false
187
211
  version_requirements: !ruby/object:Gem::Requirement
188
212
  requirements:
189
213
  - - "~>"
190
214
  - !ruby/object:Gem::Version
191
- version: '1.1'
215
+ version: '2.1'
192
216
  - !ruby/object:Gem::Dependency
193
217
  name: rdf-spec
194
218
  requirement: !ruby/object:Gem::Requirement
@@ -223,14 +247,14 @@ dependencies:
223
247
  requirements:
224
248
  - - "~>"
225
249
  - !ruby/object:Gem::Version
226
- version: '3.11'
250
+ version: '3.12'
227
251
  type: :development
228
252
  prerelease: false
229
253
  version_requirements: !ruby/object:Gem::Requirement
230
254
  requirements:
231
255
  - - "~>"
232
256
  - !ruby/object:Gem::Version
233
- version: '3.11'
257
+ version: '3.12'
234
258
  - !ruby/object:Gem::Dependency
235
259
  name: rspec-its
236
260
  requirement: !ruby/object:Gem::Requirement
@@ -455,7 +479,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
455
479
  - !ruby/object:Gem::Version
456
480
  version: '0'
457
481
  requirements: []
458
- rubygems_version: 3.3.3
482
+ rubygems_version: 3.4.13
459
483
  signing_key:
460
484
  specification_version: 4
461
485
  summary: SPARQL Query and Update library for Ruby.