sparql 3.0.0 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +184 -70
  3. data/UNLICENSE +1 -1
  4. data/VERSION +1 -1
  5. data/bin/sparql +28 -17
  6. data/lib/rack/sparql.rb +1 -1
  7. data/lib/rack/sparql/conneg.rb +3 -3
  8. data/lib/sinatra/sparql.rb +5 -5
  9. data/lib/sparql.rb +14 -10
  10. data/lib/sparql/algebra.rb +15 -23
  11. data/lib/sparql/algebra/aggregate.rb +4 -4
  12. data/lib/sparql/algebra/evaluatable.rb +2 -2
  13. data/lib/sparql/algebra/expression.rb +28 -21
  14. data/lib/sparql/algebra/extensions.rb +142 -16
  15. data/lib/sparql/algebra/operator.rb +37 -16
  16. data/lib/sparql/algebra/operator/abs.rb +2 -2
  17. data/lib/sparql/algebra/operator/add.rb +3 -3
  18. data/lib/sparql/algebra/operator/alt.rb +4 -4
  19. data/lib/sparql/algebra/operator/and.rb +7 -7
  20. data/lib/sparql/algebra/operator/asc.rb +3 -3
  21. data/lib/sparql/algebra/operator/ask.rb +4 -14
  22. data/lib/sparql/algebra/operator/avg.rb +6 -4
  23. data/lib/sparql/algebra/operator/base.rb +10 -10
  24. data/lib/sparql/algebra/operator/bgp.rb +1 -1
  25. data/lib/sparql/algebra/operator/bnode.rb +5 -5
  26. data/lib/sparql/algebra/operator/bound.rb +3 -3
  27. data/lib/sparql/algebra/operator/ceil.rb +2 -2
  28. data/lib/sparql/algebra/operator/clear.rb +3 -3
  29. data/lib/sparql/algebra/operator/coalesce.rb +3 -13
  30. data/lib/sparql/algebra/operator/compare.rb +8 -8
  31. data/lib/sparql/algebra/operator/concat.rb +4 -4
  32. data/lib/sparql/algebra/operator/construct.rb +4 -14
  33. data/lib/sparql/algebra/operator/contains.rb +2 -2
  34. data/lib/sparql/algebra/operator/copy.rb +3 -3
  35. data/lib/sparql/algebra/operator/count.rb +3 -3
  36. data/lib/sparql/algebra/operator/create.rb +3 -3
  37. data/lib/sparql/algebra/operator/dataset.rb +5 -16
  38. data/lib/sparql/algebra/operator/datatype.rb +1 -1
  39. data/lib/sparql/algebra/operator/day.rb +1 -1
  40. data/lib/sparql/algebra/operator/delete.rb +7 -5
  41. data/lib/sparql/algebra/operator/delete_data.rb +3 -3
  42. data/lib/sparql/algebra/operator/delete_where.rb +5 -5
  43. data/lib/sparql/algebra/operator/desc.rb +1 -1
  44. data/lib/sparql/algebra/operator/describe.rb +3 -13
  45. data/lib/sparql/algebra/operator/distinct.rb +4 -14
  46. data/lib/sparql/algebra/operator/divide.rb +1 -1
  47. data/lib/sparql/algebra/operator/drop.rb +3 -3
  48. data/lib/sparql/algebra/operator/encode_for_uri.rb +3 -3
  49. data/lib/sparql/algebra/operator/equal.rb +3 -3
  50. data/lib/sparql/algebra/operator/exists.rb +5 -5
  51. data/lib/sparql/algebra/operator/exprlist.rb +3 -13
  52. data/lib/sparql/algebra/operator/extend.rb +21 -20
  53. data/lib/sparql/algebra/operator/filter.rb +6 -16
  54. data/lib/sparql/algebra/operator/floor.rb +2 -2
  55. data/lib/sparql/algebra/operator/graph.rb +5 -16
  56. data/lib/sparql/algebra/operator/greater_than.rb +5 -5
  57. data/lib/sparql/algebra/operator/greater_than_or_equal.rb +5 -5
  58. data/lib/sparql/algebra/operator/group.rb +25 -25
  59. data/lib/sparql/algebra/operator/group_concat.rb +6 -6
  60. data/lib/sparql/algebra/operator/hours.rb +1 -1
  61. data/lib/sparql/algebra/operator/if.rb +5 -15
  62. data/lib/sparql/algebra/operator/in.rb +4 -14
  63. data/lib/sparql/algebra/operator/insert.rb +6 -4
  64. data/lib/sparql/algebra/operator/insert_data.rb +3 -3
  65. data/lib/sparql/algebra/operator/iri.rb +1 -1
  66. data/lib/sparql/algebra/operator/is_blank.rb +1 -1
  67. data/lib/sparql/algebra/operator/is_iri.rb +1 -1
  68. data/lib/sparql/algebra/operator/is_literal.rb +1 -1
  69. data/lib/sparql/algebra/operator/is_numeric.rb +1 -1
  70. data/lib/sparql/algebra/operator/join.rb +12 -10
  71. data/lib/sparql/algebra/operator/lang.rb +1 -1
  72. data/lib/sparql/algebra/operator/lang_matches.rb +3 -3
  73. data/lib/sparql/algebra/operator/lcase.rb +2 -2
  74. data/lib/sparql/algebra/operator/left_join.rb +15 -12
  75. data/lib/sparql/algebra/operator/less_than.rb +5 -5
  76. data/lib/sparql/algebra/operator/less_than_or_equal.rb +5 -5
  77. data/lib/sparql/algebra/operator/load.rb +3 -3
  78. data/lib/sparql/algebra/operator/max.rb +6 -4
  79. data/lib/sparql/algebra/operator/md5.rb +1 -1
  80. data/lib/sparql/algebra/operator/min.rb +6 -4
  81. data/lib/sparql/algebra/operator/minus.rb +12 -11
  82. data/lib/sparql/algebra/operator/minutes.rb +1 -1
  83. data/lib/sparql/algebra/operator/modify.rb +4 -4
  84. data/lib/sparql/algebra/operator/month.rb +1 -1
  85. data/lib/sparql/algebra/operator/move.rb +3 -3
  86. data/lib/sparql/algebra/operator/multiply.rb +1 -1
  87. data/lib/sparql/algebra/operator/negate.rb +1 -1
  88. data/lib/sparql/algebra/operator/not.rb +1 -1
  89. data/lib/sparql/algebra/operator/not_equal.rb +2 -2
  90. data/lib/sparql/algebra/operator/notexists.rb +4 -4
  91. data/lib/sparql/algebra/operator/notin.rb +4 -14
  92. data/lib/sparql/algebra/operator/notoneof.rb +5 -6
  93. data/lib/sparql/algebra/operator/now.rb +1 -1
  94. data/lib/sparql/algebra/operator/or.rb +7 -7
  95. data/lib/sparql/algebra/operator/order.rb +6 -16
  96. data/lib/sparql/algebra/operator/path.rb +6 -5
  97. data/lib/sparql/algebra/operator/path_opt.rb +16 -16
  98. data/lib/sparql/algebra/operator/path_plus.rb +8 -8
  99. data/lib/sparql/algebra/operator/path_star.rb +4 -4
  100. data/lib/sparql/algebra/operator/plus.rb +3 -3
  101. data/lib/sparql/algebra/operator/prefix.rb +10 -10
  102. data/lib/sparql/algebra/operator/project.rb +4 -14
  103. data/lib/sparql/algebra/operator/rand.rb +1 -1
  104. data/lib/sparql/algebra/operator/reduced.rb +4 -14
  105. data/lib/sparql/algebra/operator/regex.rb +6 -6
  106. data/lib/sparql/algebra/operator/replace.rb +4 -4
  107. data/lib/sparql/algebra/operator/reverse.rb +4 -4
  108. data/lib/sparql/algebra/operator/round.rb +2 -2
  109. data/lib/sparql/algebra/operator/same_term.rb +8 -5
  110. data/lib/sparql/algebra/operator/sample.rb +3 -3
  111. data/lib/sparql/algebra/operator/seconds.rb +1 -1
  112. data/lib/sparql/algebra/operator/seq.rb +5 -6
  113. data/lib/sparql/algebra/operator/sequence.rb +4 -4
  114. data/lib/sparql/algebra/operator/sha1.rb +1 -1
  115. data/lib/sparql/algebra/operator/sha256.rb +1 -1
  116. data/lib/sparql/algebra/operator/sha384.rb +1 -1
  117. data/lib/sparql/algebra/operator/sha512.rb +1 -1
  118. data/lib/sparql/algebra/operator/slice.rb +4 -14
  119. data/lib/sparql/algebra/operator/str.rb +1 -1
  120. data/lib/sparql/algebra/operator/strafter.rb +2 -2
  121. data/lib/sparql/algebra/operator/strbefore.rb +2 -2
  122. data/lib/sparql/algebra/operator/strdt.rb +2 -2
  123. data/lib/sparql/algebra/operator/strends.rb +2 -2
  124. data/lib/sparql/algebra/operator/strlang.rb +2 -2
  125. data/lib/sparql/algebra/operator/strlen.rb +2 -2
  126. data/lib/sparql/algebra/operator/strstarts.rb +2 -2
  127. data/lib/sparql/algebra/operator/struuid.rb +1 -1
  128. data/lib/sparql/algebra/operator/substr.rb +4 -4
  129. data/lib/sparql/algebra/operator/subtract.rb +1 -1
  130. data/lib/sparql/algebra/operator/sum.rb +6 -4
  131. data/lib/sparql/algebra/operator/table.rb +6 -4
  132. data/lib/sparql/algebra/operator/timezone.rb +1 -1
  133. data/lib/sparql/algebra/operator/tz.rb +1 -1
  134. data/lib/sparql/algebra/operator/ucase.rb +2 -2
  135. data/lib/sparql/algebra/operator/union.rb +10 -9
  136. data/lib/sparql/algebra/operator/update.rb +4 -4
  137. data/lib/sparql/algebra/operator/using.rb +4 -4
  138. data/lib/sparql/algebra/operator/uuid.rb +1 -1
  139. data/lib/sparql/algebra/operator/with.rb +6 -6
  140. data/lib/sparql/algebra/operator/year.rb +1 -1
  141. data/lib/sparql/algebra/query.rb +2 -2
  142. data/lib/sparql/algebra/update.rb +2 -2
  143. data/lib/sparql/algebra/version.rb +1 -1
  144. data/lib/sparql/extensions.rb +5 -5
  145. data/lib/sparql/grammar.rb +111 -11
  146. data/lib/sparql/grammar/meta.rb +1372 -333
  147. data/lib/sparql/grammar/parser11.rb +56 -42
  148. data/lib/sparql/grammar/terminals11.rb +1 -0
  149. data/lib/sparql/results.rb +63 -44
  150. data/lib/sparql/version.rb +1 -1
  151. metadata +40 -47
@@ -11,8 +11,8 @@ module SPARQL; module Algebra
11
11
  # (filter (|| (= ?type ex:Reptile) (= ?type ex:Insect))
12
12
  # (bgp (triple ?animal <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type))))))
13
13
  #
14
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-unary-minus
15
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
14
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-unary-minus
15
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
16
16
  class Minus < Operator::Binary
17
17
  include Query
18
18
 
@@ -33,18 +33,18 @@ module SPARQL; module Algebra
33
33
  # @yieldreturn [void] ignored
34
34
  # @return [RDF::Query::Solutions]
35
35
  # the resulting solution sequence
36
- # @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#defn_algMinus
37
- # @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#negation
38
- def execute(queryable, options = {}, &block)
36
+ # @see https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#defn_algMinus
37
+ # @see https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#negation
38
+ def execute(queryable, **options, &block)
39
39
  # Let Ω1 and Ω2 be multisets of solution mappings. We define:
40
40
  #
41
41
  # Minus(Ω1, Ω2) = { μ | μ in Ω1 . ∀ μ' in Ω2, either μ and μ' are not compatible or dom(μ) and dom(μ') are disjoint }
42
42
  #
43
43
  # card[Minus(Ω1, Ω2)](μ) = card[Ω1](μ)
44
44
  debug(options) {"Minus"}
45
- left = queryable.query(operand(0), options.merge(depth: options[:depth].to_i + 1))
45
+ left = queryable.query(operand(0), depth: options[:depth].to_i + 1, **options)
46
46
  debug(options) {"(minus left) #{left.inspect}"}
47
- right = queryable.query(operand(1), options.merge(depth: options[:depth].to_i + 1))
47
+ right = queryable.query(operand(1), depth: options[:depth].to_i + 1, **options)
48
48
  debug(options) {"(minus right) #{right.inspect}"}
49
49
  @solutions = left.minus(right)
50
50
  @solutions.each(&block) if block_given?
@@ -52,16 +52,17 @@ module SPARQL; module Algebra
52
52
  end
53
53
 
54
54
  ##
55
- # Returns an optimized version of this query.
55
+ # Optimizes this query.
56
56
  #
57
57
  # Groups of one graph pattern (not a filter) become join(Z, A) and can be replaced by A.
58
58
  # The empty graph pattern Z is the identity for join:
59
59
  # Replace join(Z, A) by A
60
60
  # Replace join(A, Z) by A
61
61
  #
62
- # @return [Join, RDF::Query] `self`
63
- def optimize
64
- ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?}
62
+ # @return [self]
63
+ # @see SPARQL::Algebra::Expression#optimize!
64
+ def optimize!(**options)
65
+ ops = operands.map {|o| o.optimize(**options) }.select {|o| o.respond_to?(:empty?) && !o.empty?}
65
66
  @operands = ops
66
67
  self
67
68
  end
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (extend ((?x (minutes ?date)))
12
12
  # (bgp (triple ?s :date ?date)))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#func-minutes
14
+ # @see https://www.w3.org/TR/sparql11-query/#func-minutes
15
15
  class Minutes < Operator::Unary
16
16
  include Evaluatable
17
17
 
@@ -33,17 +33,17 @@ module SPARQL; module Algebra
33
33
  # Returns queryable.
34
34
  # @raise [IOError]
35
35
  # If `from` does not exist, unless the `silent` operator is present
36
- # @see http://www.w3.org/TR/sparql11-update/
37
- def execute(queryable, options = {})
36
+ # @see https://www.w3.org/TR/sparql11-update/
37
+ def execute(queryable, **options)
38
38
  debug(options) {"Modify"}
39
39
  query = operands.shift
40
40
 
41
- queryable.query(query, options.merge(depth: options[:depth].to_i + 1)) do |solution|
41
+ queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
42
42
  debug(options) {"(solution)=>#{solution.inspect}"}
43
43
 
44
44
  # Execute each operand with queryable and solution
45
45
  operands.each do |op|
46
- op.execute(queryable, solution, options.merge(depth: options[:depth].to_i + 1))
46
+ op.execute(queryable, solutions: solution, depth: options[:depth].to_i + 1, **options)
47
47
  end
48
48
  end
49
49
  queryable
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (extend ((?x (month ?date)))
12
12
  # (bgp (triple ?s :date ?date)))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#func-month
14
+ # @see https://www.w3.org/TR/sparql11-query/#func-month
15
15
  class Month < Operator::Unary
16
16
  include Evaluatable
17
17
 
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # @example
10
10
  # (move silent <iri> to default)
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-update/#move
12
+ # @see https://www.w3.org/TR/sparql11-update/#move
13
13
  class Move < Operator
14
14
  include SPARQL::Algebra::Update
15
15
 
@@ -28,8 +28,8 @@ module SPARQL; module Algebra
28
28
  # Returns queryable.
29
29
  # @raise [IOError]
30
30
  # If `from` does not exist, unless the `silent` operator is present
31
- # @see http://www.w3.org/TR/sparql11-update/
32
- def execute(queryable, options = {})
31
+ # @see https://www.w3.org/TR/sparql11-update/
32
+ def execute(queryable, **options)
33
33
  debug(options) {"Move"}
34
34
  silent = operands.first == :silent
35
35
  operands.shift if silent
@@ -7,7 +7,7 @@ module SPARQL; module Algebra
7
7
  # (* ?x ?y)
8
8
  # (multiply ?x ?y)
9
9
  #
10
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-multiply
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-multiply
11
11
  class Multiply < Operator::Binary
12
12
  include Evaluatable
13
13
 
@@ -7,7 +7,7 @@ module SPARQL; module Algebra
7
7
  # (- ?x)
8
8
  # (negate ?x)
9
9
  #
10
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-unary-minus
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-unary-minus
11
11
  class Negate < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -7,7 +7,7 @@ module SPARQL; module Algebra
7
7
  # (! ?x)
8
8
  # (not ?x)
9
9
  #
10
- # @see http://www.w3.org/TR/xpath-functions/#func-not
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-not
11
11
  class Not < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -3,8 +3,8 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL relational `!=` (not equal) comparison operator.
5
5
  #
6
- # @see http://www.w3.org/TR/sparql11-query/#OperatorMapping
7
- # @see http://www.w3.org/TR/sparql11-query/#func-RDFterm-equal
6
+ # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
7
+ # @see https://www.w3.org/TR/sparql11-query/#func-RDFterm-equal
8
8
  class NotEqual < Equal
9
9
  NAME = :'!='
10
10
 
@@ -12,8 +12,8 @@ module SPARQL; module Algebra
12
12
  # (bgp (triple ?s ?p ex:o1))))
13
13
  # (bgp (triple ?s ?p ex:o))))
14
14
  #
15
- # @see http://www.w3.org/TR/sparql11-query/#func-abs
16
- # @see http://www.w3.org/TR/xpath-functions/#func-abs
15
+ # @see https://www.w3.org/TR/sparql11-query/#func-abs
16
+ # @see https://www.w3.org/TR/xpath-functions/#func-abs
17
17
  class NotExists < Operator::Unary
18
18
  include Evaluatable
19
19
 
@@ -29,10 +29,10 @@ module SPARQL; module Algebra
29
29
  # @option options[RDF::Queryable] queryable
30
30
  # queryable to execute, using bindings as an initial solution.
31
31
  # @return [RDF::Literal::Boolean] `true` or `false`
32
- def evaluate(bindings, options = {})
32
+ def evaluate(bindings, **options)
33
33
  solutions = RDF::Query::Solutions(bindings)
34
34
  queryable = options[:queryable]
35
- operand(0).execute(queryable, options.merge(solutions: solutions)).empty?
35
+ operand(0).execute(queryable, solutions: solutions, **options).empty?
36
36
  end
37
37
  end # NotExists
38
38
  end # Operator
@@ -8,7 +8,7 @@ module SPARQL; module Algebra
8
8
  # @example
9
9
  # (ask (filter (notin ?o 1 2) (bgp)))
10
10
  #
11
- # @see http://www.w3.org/TR/sparql11-query/#func-notin
11
+ # @see https://www.w3.org/TR/sparql11-query/#func-notin
12
12
  class NotIn < Operator
13
13
  include Evaluatable
14
14
 
@@ -42,12 +42,12 @@ module SPARQL; module Algebra
42
42
  # options passed from query
43
43
  # @return [RDF::Literal::Boolean] `true` or `false`
44
44
  # @raise [TypeError] if term is not found and any operand raises an error
45
- def evaluate(bindings, options = {})
46
- lhs = operands.first.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))
45
+ def evaluate(bindings, **options)
46
+ lhs = operands.first.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
47
47
  error_found = false
48
48
  found = operands[1..-1].any? do |op|
49
49
  begin
50
- lhs == op.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))
50
+ lhs == op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
51
51
  rescue TypeError
52
52
  error_found = true
53
53
  end
@@ -58,16 +58,6 @@ module SPARQL; module Algebra
58
58
  else RDF::Literal::TRUE
59
59
  end
60
60
  end
61
-
62
- ##
63
- # Returns an optimized version of this query.
64
- #
65
- # Return optimized query
66
- #
67
- # @return [Union, RDF::Query] `self`
68
- def optimize
69
- operands = operands.map(&:optimize)
70
- end
71
61
  end # Exprlist
72
62
  end # Operator
73
63
  end; end # SPARQL::Algebra
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (notoneof ex:p1 ex:p2)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#eval_negatedPropertySet
9
+ # @see https://www.w3.org/TR/sparql11-query/#eval_negatedPropertySet
10
10
  class NotOneOf < Operator
11
11
  include Query
12
12
 
@@ -30,18 +30,17 @@ module SPARQL; module Algebra
30
30
  # each matching solution
31
31
  # @yieldparam [RDF::Query::Solution] solution
32
32
  # @yieldreturn [void] ignored
33
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
34
- def execute(queryable, options = {}, &block)
33
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
34
+ def execute(queryable, **options, &block)
35
35
  debug(options) {"NotOneOf #{operands.to_sse}"}
36
36
  subject, object = options[:subject], options[:object]
37
37
 
38
- v = RDF::Query::Variable.new
39
- v.distinguished = false
38
+ v = RDF::Query::Variable.new(distinguished: false)
40
39
  bgp = RDF::Query.new do |q|
41
40
  q.pattern [subject, v, object]
42
41
  end
43
42
  query = Filter.new(NotIn.new(v, *operands), bgp)
44
- queryable.query(query, options.merge(depth: options[:depth].to_i + 1)) do |solution|
43
+ queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
45
44
  solution.bindings.delete(v.to_sym)
46
45
  debug(options) {"(solution)-> #{solution.to_h.to_sse}"}
47
46
  block.call(solution)
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
13
13
  # (extend ((?n (now)))
14
14
  # (bgp)))))
15
15
  #
16
- # @see http://www.w3.org/TR/sparql11-query/#func-now
16
+ # @see https://www.w3.org/TR/sparql11-query/#func-now
17
17
  class Now < Operator::Nullary
18
18
  include Evaluatable
19
19
 
@@ -7,8 +7,8 @@ module SPARQL; module Algebra
7
7
  # (|| ?x ?y)
8
8
  # (or ?x ?y)
9
9
  #
10
- # @see http://www.w3.org/TR/sparql11-query/#func-logical-or
11
- # @see http://www.w3.org/TR/sparql11-query/#evaluation
10
+ # @see https://www.w3.org/TR/sparql11-query/#func-logical-or
11
+ # @see https://www.w3.org/TR/sparql11-query/#evaluation
12
12
  class Or < Operator::Binary
13
13
  include Evaluatable
14
14
 
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
24
24
  # @param [Hash{Symbol => Object}] options
25
25
  # any additional options (see {Operator#initialize})
26
26
  # @raise [TypeError] if any operand is invalid
27
- def initialize(left, right, options = {})
27
+ def initialize(left, right, **options)
28
28
  super
29
29
  end
30
30
 
@@ -40,20 +40,20 @@ module SPARQL; module Algebra
40
40
  # options passed from query
41
41
  # @return [RDF::Literal::Boolean] `true` or `false`
42
42
  # @raise [TypeError] if the operands could not be coerced to a boolean literal
43
- def evaluate(bindings, options = {})
43
+ def evaluate(bindings, **options)
44
44
  begin
45
- left = boolean(operand(0).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))).true?
45
+ left = boolean(operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
46
46
  rescue TypeError
47
47
  left = nil
48
48
  end
49
49
 
50
50
  begin
51
- right = boolean(operand(1).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))).true?
51
+ right = boolean(operand(1).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
52
52
  rescue TypeError
53
53
  right = nil
54
54
  end
55
55
 
56
- # From http://www.w3.org/TR/sparql11-query/#evaluation
56
+ # From https://www.w3.org/TR/sparql11-query/#evaluation
57
57
  # A logical-or that encounters an error on only one branch will return TRUE if the other branch is TRUE
58
58
  # and an error if the other branch is FALSE.
59
59
  case
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # (order ((asc ?name))
10
10
  # (bgp (triple ?x foaf:name ?name)))))
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-query/#modOrderBy
12
+ # @see https://www.w3.org/TR/sparql11-query/#modOrderBy
13
13
  class Order < Operator::Binary
14
14
  include Query
15
15
 
@@ -30,16 +30,16 @@ module SPARQL; module Algebra
30
30
  # @yieldreturn [void] ignored
31
31
  # @return [RDF::Query::Solutions]
32
32
  # the resulting solution sequence
33
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
34
- def execute(queryable, options = {}, &block)
33
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
34
+ def execute(queryable, **options, &block)
35
35
 
36
36
  debug(options) {"Order"}
37
- @solutions = queryable.query(operands.last, options.merge(depth: options[:depth].to_i + 1)).order do |a, b|
37
+ @solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options).order do |a, b|
38
38
  operand(0).inject(0) do |memo, op|
39
39
  debug(options) {"(order) #{op.inspect}"}
40
40
  memo = begin
41
- a_eval = op.evaluate(a, options.merge(queryable: queryable, depth: options[:depth].to_i + 1)) rescue nil
42
- b_eval = op.evaluate(b, options.merge(queryable: queryable, depth: options[:depth].to_i + 1)) rescue nil
41
+ a_eval = op.evaluate(a, queryable: queryable, depth: options[:depth].to_i + 1, **options) rescue nil
42
+ b_eval = op.evaluate(b, queryable: queryable, depth: options[:depth].to_i + 1, **options) rescue nil
43
43
  comp = Operator::Compare.evaluate(a_eval, b_eval).to_i
44
44
  comp = -comp if op.is_a?(Operator::Desc)
45
45
  comp
@@ -50,16 +50,6 @@ module SPARQL; module Algebra
50
50
  @solutions.each(&block) if block_given?
51
51
  @solutions
52
52
  end
53
-
54
- ##
55
- # Returns an optimized version of this query.
56
- #
57
- # Return optimized query
58
- #
59
- # @return [Union, RDF::Query] `self`
60
- def optimize
61
- operands = operands.map(&:optimize)
62
- end
63
53
  end # Order
64
54
  end # Operator
65
55
  end; end # SPARQL::Algebra
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (path :a (path+ :p) ?z)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#sparqlTranslatePathExpressions
9
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlTranslatePathExpressions
10
10
  class Path < Operator::Ternary
11
11
  include Query
12
12
 
@@ -25,17 +25,18 @@ module SPARQL; module Algebra
25
25
  # @yieldreturn [void] ignored
26
26
  # @return [RDF::Query::Solutions]
27
27
  # the resulting solution sequence
28
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
29
- def execute(queryable, options = {}, &block)
28
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
29
+ def execute(queryable, **options, &block)
30
30
  debug(options) {"Path #{operands.to_sse}"}
31
31
  subject, path_op, object = operands
32
32
 
33
33
  @solutions = RDF::Query::Solutions.new
34
- path_op.execute(queryable, options.merge(
34
+ path_op.execute(queryable,
35
35
  subject: subject,
36
36
  object: object,
37
37
  graph_name: options.fetch(:graph_name, false),
38
- depth: options[:depth].to_i + 1)
38
+ depth: options[:depth].to_i + 1,
39
+ **options
39
40
  ) do |solution|
40
41
  @solutions << solution
41
42
  end
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (path? :p)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#defn_evalPP_ZeroOrOnePath
9
+ # @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_ZeroOrOnePath
10
10
  class PathOpt < Operator::Unary
11
11
  include Query
12
12
 
@@ -29,8 +29,8 @@ module SPARQL; module Algebra
29
29
  # each matching solution
30
30
  # @yieldparam [RDF::Query::Solution] solution
31
31
  # @yieldreturn [void] ignored
32
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
33
- def execute(queryable, options = {}, &block)
32
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
33
+ def execute(queryable, **options, &block)
34
34
  subject, object = options[:subject], options[:object]
35
35
  debug(options) {"Path? #{[subject, operands, object].to_sse}"}
36
36
 
@@ -41,48 +41,48 @@ module SPARQL; module Algebra
41
41
  # Nodes is the set of all subjects and objects in queryable
42
42
  # FIXME: should this be Queryable#enum_nodes?
43
43
  # All subjects which are `object`
44
- query = RDF::Query.new {|q| q.pattern(subject: subject)}
45
- queryable.query(query, options) do |solution|
44
+ query = RDF::Query.new {|q| q.pattern({subject: subject})}
45
+ queryable.query(query, **options) do |solution|
46
46
  solution.merge!(object.to_sym => solution[subject])
47
47
  debug(options) {"(solution-s0)-> #{solution.to_h.to_sse}"}
48
48
  solutions << solution
49
49
  end if query.valid?
50
50
 
51
51
  # All objects which are `object`
52
- query = RDF::Query.new {|q| q.pattern(object: object)}
53
- queryable.query(query, options) do |solution|
52
+ query = RDF::Query.new {|q| q.pattern({object: object})}
53
+ queryable.query(query, **options) do |solution|
54
54
  solution.merge!(subject.to_sym => solution[object])
55
55
  debug(options) {"(solution-o0)-> #{solution.to_h.to_sse}"}
56
56
  solutions << solution
57
57
  end if query.valid?
58
58
  when subject.variable?
59
59
  # All subjects which are `object`
60
- query = RDF::Query.new {|q| q.pattern(subject: object)}
61
- queryable.query(query, options) do |solution|
60
+ query = RDF::Query.new {|q| q.pattern({subject: object})}
61
+ queryable.query(query, **options) do |solution|
62
62
  solution.merge!(subject.to_sym => object)
63
63
  debug(options) {"(solution-s0)-> #{solution.to_h.to_sse}"}
64
64
  solutions << solution
65
65
  end if query.valid?
66
66
 
67
67
  # All objects which are `object`
68
- query = RDF::Query.new {|q| q.pattern(object: object)}
69
- queryable.query(query, options) do |solution|
68
+ query = RDF::Query.new {|q| q.pattern({object: object})}
69
+ queryable.query(query, **options) do |solution|
70
70
  solution.merge!(subject.to_sym => object)
71
71
  debug(options) {"(solution-o0)-> #{solution.to_h.to_sse}"}
72
72
  solutions << solution
73
73
  end if query.valid?
74
74
  when object.variable?
75
75
  # All subjects which are `subject`
76
- query = RDF::Query.new {|q| q.pattern(subject: subject)}
77
- queryable.query(query, options) do |solution|
76
+ query = RDF::Query.new {|q| q.pattern({subject: subject})}
77
+ queryable.query(query, **options) do |solution|
78
78
  solution.merge!(object.to_sym => subject)
79
79
  debug(options) {"(solution-s0)-> #{solution.to_h.to_sse}"}
80
80
  solutions << solution
81
81
  end if query.valid?
82
82
 
83
83
  # All objects which are `subject
84
- query = RDF::Query.new {|q| q.pattern(object: subject)}
85
- queryable.query(query, options) do |solution|
84
+ query = RDF::Query.new {|q| q.pattern({object: subject})}
85
+ queryable.query(query, **options) do |solution|
86
86
  solution.merge!(object.to_sym => subject)
87
87
  debug(options) {"(solution-o0)-> #{solution.to_h.to_sse}"}
88
88
  solutions << solution
@@ -103,7 +103,7 @@ module SPARQL; module Algebra
103
103
 
104
104
  # Recurse into query
105
105
  solutions +=
106
- queryable.query(query, options.merge(depth: options[:depth].to_i + 1))
106
+ queryable.query(query, depth: options[:depth].to_i + 1, **options)
107
107
  solutions.each(&block) if block_given?
108
108
  solutions
109
109
  end