sparql 3.2.4 → 3.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/sparql/algebra/aggregate.rb +1 -1
  4. data/lib/sparql/algebra/evaluatable.rb +1 -1
  5. data/lib/sparql/algebra/expression.rb +2 -2
  6. data/lib/sparql/algebra/operator/alt.rb +1 -1
  7. data/lib/sparql/algebra/operator/and.rb +2 -2
  8. data/lib/sparql/algebra/operator/asc.rb +1 -1
  9. data/lib/sparql/algebra/operator/ask.rb +1 -1
  10. data/lib/sparql/algebra/operator/base.rb +1 -1
  11. data/lib/sparql/algebra/operator/bnode.rb +1 -1
  12. data/lib/sparql/algebra/operator/coalesce.rb +1 -1
  13. data/lib/sparql/algebra/operator/concat.rb +1 -1
  14. data/lib/sparql/algebra/operator/construct.rb +1 -1
  15. data/lib/sparql/algebra/operator/dataset.rb +2 -2
  16. data/lib/sparql/algebra/operator/delete_where.rb +1 -1
  17. data/lib/sparql/algebra/operator/distinct.rb +1 -1
  18. data/lib/sparql/algebra/operator/exprlist.rb +1 -1
  19. data/lib/sparql/algebra/operator/extend.rb +2 -3
  20. data/lib/sparql/algebra/operator/filter.rb +1 -1
  21. data/lib/sparql/algebra/operator/group.rb +1 -1
  22. data/lib/sparql/algebra/operator/group_concat.rb +1 -1
  23. data/lib/sparql/algebra/operator/if.rb +3 -3
  24. data/lib/sparql/algebra/operator/in.rb +1 -1
  25. data/lib/sparql/algebra/operator/join.rb +2 -2
  26. data/lib/sparql/algebra/operator/left_join.rb +26 -2
  27. data/lib/sparql/algebra/operator/minus.rb +2 -2
  28. data/lib/sparql/algebra/operator/modify.rb +2 -2
  29. data/lib/sparql/algebra/operator/notin.rb +2 -2
  30. data/lib/sparql/algebra/operator/notoneof.rb +1 -1
  31. data/lib/sparql/algebra/operator/or.rb +2 -2
  32. data/lib/sparql/algebra/operator/order.rb +3 -3
  33. data/lib/sparql/algebra/operator/path.rb +1 -2
  34. data/lib/sparql/algebra/operator/path_plus.rb +1 -1
  35. data/lib/sparql/algebra/operator/path_star.rb +1 -1
  36. data/lib/sparql/algebra/operator/prefix.rb +1 -1
  37. data/lib/sparql/algebra/operator/project.rb +1 -1
  38. data/lib/sparql/algebra/operator/reduced.rb +1 -1
  39. data/lib/sparql/algebra/operator/sequence.rb +2 -2
  40. data/lib/sparql/algebra/operator/slice.rb +1 -1
  41. data/lib/sparql/algebra/operator/union.rb +1 -1
  42. data/lib/sparql/algebra/operator/update.rb +1 -1
  43. data/lib/sparql/algebra/operator/using.rb +1 -1
  44. data/lib/sparql/algebra/operator/with.rb +2 -2
  45. data/lib/sparql/grammar/terminals11.rb +2 -2
  46. data/lib/sparql/results.rb +2 -1
  47. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 932897287930ea7265a07628e73c13a06b02b9e0d1572b578356166d3c8fe70a
4
- data.tar.gz: 9d17310bc07080475780c8acccbe57acb4bbeb40e3f66ab7b74a09b15ccf0863
3
+ metadata.gz: eaf1d4f46a557ae2b96d66c5a8fc8b774eb9819a71304fa2d25ada151ba39671
4
+ data.tar.gz: e61f360e22fcaf413e71be501368ef36fa8860c71e7a714222a59ec021e44bbc
5
5
  SHA512:
6
- metadata.gz: e701784500aece828b2cfd41eb0af78a809bda575eed047158e962ff38678d524b179c0c3faef21fc5b5724894ada3066637b608778a1809fdc7b9bda2ffe2a2
7
- data.tar.gz: 77c2520a5f4923a1fe27d589ea6a09b6f5a36fa9c17b564184f206971204fec6988b0941c350e10d812ccfd9b0934e6ae629b82207abfaabf8d7bcc3a380ab33
6
+ metadata.gz: ee8251bc196d3851505802091dbcfbc206a26ac01d86eecaa5c90ebaa4b6d2f8ce23b5f9fd4b8e6b8cce5ca7e4a588ef90f981d7c950538986fb3fbf953cc324
7
+ data.tar.gz: 7392fb08ce46900aea2792bb565c880349e4c2f1f19d42d90e6ada7058d501a18bc5acce45728207800bd74356a331107a20a70ac7ba25497dec9eb3a6a9fd3c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.4
1
+ 3.2.5
@@ -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)
@@ -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
@@ -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.5
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-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -455,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
455
455
  - !ruby/object:Gem::Version
456
456
  version: '0'
457
457
  requirements: []
458
- rubygems_version: 3.3.3
458
+ rubygems_version: 3.3.7
459
459
  signing_key:
460
460
  specification_version: 4
461
461
  summary: SPARQL Query and Update library for Ruby.