sparql 3.0.2 → 3.1.5

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 +4 -4
  2. data/README.md +189 -74
  3. data/UNLICENSE +1 -1
  4. data/VERSION +1 -1
  5. data/bin/sparql +44 -24
  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 +17 -16
  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 +70 -44
  14. data/lib/sparql/algebra/extensions.rb +181 -34
  15. data/lib/sparql/algebra/operator.rb +44 -23
  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 +13 -4
  23. data/lib/sparql/algebra/operator/base.rb +10 -10
  24. data/lib/sparql/algebra/operator/bgp.rb +2 -2
  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 +6 -17
  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 +9 -7
  41. data/lib/sparql/algebra/operator/delete_data.rb +3 -3
  42. data/lib/sparql/algebra/operator/delete_where.rb +6 -6
  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 +2 -2
  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 +19 -18
  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 +6 -17
  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 +7 -5
  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 +19 -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 +13 -4
  79. data/lib/sparql/algebra/operator/md5.rb +1 -1
  80. data/lib/sparql/algebra/operator/min.rb +13 -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 +11 -4
  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 +3 -3
  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 +9 -8
  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 +7 -7
  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 +11 -17
  145. data/lib/sparql/grammar.rb +113 -13
  146. data/lib/sparql/grammar/meta.rb +2340 -907
  147. data/lib/sparql/grammar/parser11.rb +57 -52
  148. data/lib/sparql/grammar/terminals11.rb +2 -0
  149. data/lib/sparql/results.rb +73 -46
  150. data/lib/sparql/version.rb +1 -1
  151. metadata +46 -63
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (abs ?x)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-abs
10
- # @see http://www.w3.org/TR/xpath-functions/#func-abs
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-abs
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-abs
11
11
  class Abs < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # @example
10
10
  # (add default <a>)
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-update/#add
12
+ # @see https://www.w3.org/TR/sparql11-update/#add
13
13
  class Add < 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) {"Add"}
34
34
  silent = operands.first == :silent
35
35
  operands.shift if silent
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # @example
11
11
  # (alt a b)
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#defn_evalPP_alternative
13
+ # @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_alternative
14
14
  class Alt < Operator::Binary
15
15
  include Query
16
16
 
@@ -32,8 +32,8 @@ module SPARQL; module Algebra
32
32
  # each matching solution
33
33
  # @yieldparam [RDF::Query::Solution] solution
34
34
  # @yieldreturn [void] ignored
35
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
36
- def execute(queryable, options = {}, &block)
35
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
36
+ def execute(queryable, **options, &block)
37
37
  subject, object = options[:subject], options[:object]
38
38
  debug(options) {"Alt #{[subject, operands, object].to_sse}"}
39
39
 
@@ -55,7 +55,7 @@ module SPARQL; module Algebra
55
55
  end
56
56
 
57
57
  query = Union.new(qa, qb)
58
- queryable.query(query, options.merge(depth: options[:depth].to_i + 1), &block)
58
+ queryable.query(query, depth: options[:depth].to_i + 1, **options, &block)
59
59
  end
60
60
  end # Alt
61
61
  end # Operator
@@ -7,8 +7,8 @@ module SPARQL; module Algebra
7
7
  # (&& ?x ?y)
8
8
  # (and ?x ?y)
9
9
  #
10
- # @see http://www.w3.org/TR/sparql11-query/#func-logical-and
11
- # @see http://www.w3.org/TR/sparql11-query/#evaluation
10
+ # @see https://www.w3.org/TR/sparql11-query/#func-logical-and
11
+ # @see https://www.w3.org/TR/sparql11-query/#evaluation
12
12
  class And < 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
 
@@ -37,20 +37,20 @@ module SPARQL; module Algebra
37
37
  # options passed from query
38
38
  # @return [RDF::Literal::Boolean] `true` or `false`
39
39
  # @raise [TypeError] if the operands could not be coerced to boolean literals
40
- def evaluate(bindings, options = {})
40
+ def evaluate(bindings, **options)
41
41
  begin
42
- left = boolean(operand(0).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))).true?
42
+ left = boolean(operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
43
43
  rescue TypeError
44
44
  left = nil
45
45
  end
46
46
 
47
47
  begin
48
- right = boolean(operand(1).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))).true?
48
+ right = boolean(operand(1).evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true?
49
49
  rescue TypeError
50
50
  right = nil
51
51
  end
52
52
 
53
- # From http://www.w3.org/TR/sparql11-query/#evaluation
53
+ # From https://www.w3.org/TR/sparql11-query/#evaluation
54
54
  # A logical-and that encounters an error on only one branch will return an error if the other branch is
55
55
  # TRUE and FALSE if the other branch is FALSE.
56
56
  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 Asc < Operator::Unary
14
14
  include Evaluatable
15
15
 
@@ -24,8 +24,8 @@ module SPARQL; module Algebra
24
24
  # @param [Hash{Symbol => Object}] options ({})
25
25
  # options passed from query
26
26
  # @return [RDF::Term]
27
- def evaluate(bindings, options = {})
28
- operand(0).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))
27
+ def evaluate(bindings, **options)
28
+ operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options)
29
29
  end
30
30
  end # Asc
31
31
  end # Operator
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (ask
11
11
  # (bgp (triple :x :p ?x))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#ask
13
+ # @see https://www.w3.org/TR/sparql11-query/#ask
14
14
  class Ask < Operator::Unary
15
15
  include Query
16
16
 
@@ -28,23 +28,13 @@ module SPARQL; module Algebra
28
28
  # @yieldparam [RDF::Query::Solution] solution
29
29
  # @yieldreturn [void] ignored
30
30
  # @return [RDF::Literal::Boolean]\
31
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
32
- def execute(queryable, options = {})
31
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
32
+ def execute(queryable, **options)
33
33
  debug(options) {"Ask #{operands.first}"}
34
- res = boolean(!queryable.query(operands.last, options.merge(depth: options[:depth].to_i + 1)).empty?)
34
+ res = boolean(!queryable.query(operands.last, depth: options[:depth].to_i + 1, **options).empty?)
35
35
  yield res if block_given?
36
36
  res
37
37
  end
38
-
39
- ##
40
- # Returns an optimized version of this query.
41
- #
42
- # Return optimized query
43
- #
44
- # @return [Union, RDF::Query] `self`
45
- def optimize
46
- operands = operands.map(&:optimize)
47
- end
48
38
 
49
39
  # Query results in a boolean result (e.g., ASK)
50
40
  # @return [Boolean]
@@ -6,16 +6,23 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (prefix ((: <http://www.example.org/>))
8
8
  # (project (?avg)
9
- # (extend ((?avg ?.0))
10
- # (group () ((?.0 (avg ?o)))
9
+ # (extend ((?avg ??.0))
10
+ # (group () ((??.0 (avg ?o)))
11
11
  # (bgp (triple ?s :dec ?o))))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#defn_aggAvg
14
- class Avg < Operator::Unary
13
+ # @see https://www.w3.org/TR/sparql11-query/#defn_aggAvg
14
+ class Avg < Operator
15
15
  include Aggregate
16
16
 
17
17
  NAME = :avg
18
18
 
19
+ def initialize(*operands, **options)
20
+ raise ArgumentError,
21
+ "avg operator accepts at most one argument with an optional :distinct" if
22
+ (operands - %i{distinct}).length != 1
23
+ super
24
+ end
25
+
19
26
  ##
20
27
  # The Avg set function calculates the average value for an expression over a group. It is defined in terms of Sum and Count.
21
28
  #
@@ -23,6 +30,8 @@ module SPARQL; module Algebra
23
30
  # enum of evaluated operand
24
31
  # @return [RDF::Literal::Numeric] The numeric average of the terms
25
32
  def apply(enum)
33
+ # FIXME: we don't actually do anything with distinct
34
+ operands.shift if distinct = (operands.first == :distinct)
26
35
  if enum.empty?
27
36
  RDF::Literal(0)
28
37
  elsif enum.flatten.all? {|n| n.is_a?(RDF::Literal::Numeric)}
@@ -7,7 +7,7 @@ module SPARQL; module Algebra
7
7
  # (base <http://example.org/>
8
8
  # (bgp (triple <a> <b> 123.0)))
9
9
  #
10
- # @see http://www.w3.org/TR/sparql11-query/#QSynIRI
10
+ # @see https://www.w3.org/TR/sparql11-query/#QSynIRI
11
11
  class Base < Binary
12
12
  include Query
13
13
 
@@ -28,21 +28,21 @@ module SPARQL; module Algebra
28
28
  # @yieldreturn [void] ignored
29
29
  # @return [RDF::Queryable, RDF::Query::Solutions]
30
30
  # the resulting solution sequence
31
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
32
- def execute(queryable, options = {}, &block)
31
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
32
+ def execute(queryable, **options, &block)
33
33
  debug(options) {"Base #{operands.first}"}
34
34
  Operator.base_uri = operands.first
35
- queryable.query(operands.last, options.merge(depth: options[:depth].to_i + 1), &block)
35
+ queryable.query(operands.last, depth: options[:depth].to_i + 1, **options, &block)
36
36
  end
37
-
37
+
38
38
  ##
39
- # Returns an optimized version of this query.
40
- #
41
39
  # Return optimized query
42
40
  #
43
- # @return [Union, RDF::Query] `self`
44
- def optimize
45
- operands.last.optimize
41
+ # @return [Base] a copy of `self`
42
+ # @see SPARQL::Algebra::Expression#optimize
43
+ def optimize(**options)
44
+ Operator.base_uri = operands.first
45
+ operands.last.optimize(**options)
46
46
  end
47
47
 
48
48
  # Query results in a boolean result (e.g., ASK)
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # (prefix ((: <http://example/>))
10
10
  # (bgp (triple ?s ?p ?o)))
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
12
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
13
13
  class BGP < Operator
14
14
  NAME = [:bgp]
15
15
  ##
@@ -22,7 +22,7 @@ module SPARQL; module Algebra
22
22
  # @yieldparam [RDF::Query::Solution] solution
23
23
  # @yieldreturn [void] ignored
24
24
  # @return [RDF::Query]
25
- def self.new(*patterns, &block)
25
+ def self.new(*patterns, **options, &block)
26
26
  RDF::Query.new(*patterns, graph_name: false, &block)
27
27
  end
28
28
  end # BGP
@@ -16,7 +16,7 @@ module SPARQL; module Algebra
16
16
  # (triple ?b :str ?s2)
17
17
  # )))))
18
18
  #
19
- # @see http://www.w3.org/TR/sparql11-query/#func-bnode
19
+ # @see https://www.w3.org/TR/sparql11-query/#func-bnode
20
20
  class BNode < Operator::Unary
21
21
  include Evaluatable
22
22
 
@@ -30,7 +30,7 @@ module SPARQL; module Algebra
30
30
  # @param [Hash{Symbol => Object}] options
31
31
  # any additional options (see {Operator#initialize})
32
32
  # @raise [TypeError] if any operand is invalid
33
- def initialize(literal = false, options = {})
33
+ def initialize(literal = false, **options)
34
34
  super
35
35
  end
36
36
 
@@ -42,8 +42,8 @@ module SPARQL; module Algebra
42
42
  # @param [Hash{Symbol => Object}] options ({})
43
43
  # options passed from query
44
44
  # @return [RDF::Term]
45
- def evaluate(bindings, options = {})
46
- args = operands.map { |operand| operand.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1)) }
45
+ def evaluate(bindings, **options)
46
+ args = operands.map { |operand| operand.evaluate(bindings, depth: options[:depth].to_i + 1, **options) }
47
47
  apply(args.first, bindings)
48
48
  end
49
49
 
@@ -82,7 +82,7 @@ module SPARQL; module Algebra
82
82
  # Remove the optional argument.
83
83
  #
84
84
  # @return [Array] `self`
85
- # @see http://openjena.org/wiki/SSE
85
+ # @see https://openjena.org/wiki/SSE
86
86
  def to_sxp_bin
87
87
  [NAME] + operands.reject {|o| o == false}
88
88
  end
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (bgp (triple ?a :b ?c))
12
12
  # (bgp (triple ?c :d ?e))))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#func-bound
14
+ # @see https://www.w3.org/TR/sparql11-query/#func-bound
15
15
  class Bound < Operator::Unary
16
16
  include Evaluatable
17
17
 
@@ -25,7 +25,7 @@ module SPARQL; module Algebra
25
25
  # @param [Hash{Symbol => Object}] options
26
26
  # any additional options (see {Operator#initialize})
27
27
  # @raise [TypeError] if any operand is invalid
28
- def initialize(var, options = {})
28
+ def initialize(var, **options)
29
29
  super
30
30
  end
31
31
 
@@ -38,7 +38,7 @@ module SPARQL; module Algebra
38
38
  # options passed from query
39
39
  # @return [RDF::Literal::Boolean] `true` or `false`
40
40
  # @raise [TypeError] if the operand is not a variable
41
- def evaluate(bindings, options = {})
41
+ def evaluate(bindings, **options)
42
42
  case var = operand
43
43
  when Variable
44
44
  bindings.respond_to?(:bound?) && bindings.bound?(var) ?
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (ceil ?x)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-ceil
10
- # @see http://www.w3.org/TR/xpath-functions/#func-ceil
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-ceil
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-ceil
11
11
  class Ceil < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # @example
10
10
  # (clear silent default)
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-update/#clear
12
+ # @see https://www.w3.org/TR/sparql11-update/#clear
13
13
  class Clear < 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) {"Clear"}
34
34
  silent = operands.first == :silent
35
35
  operands.shift if silent
@@ -15,7 +15,7 @@ module SPARQL; module Algebra
15
15
  # (bgp (triple ?s :p ?o))
16
16
  # (bgp (triple ?s :q ?x))))))
17
17
  #
18
- # @see http://www.w3.org/TR/sparql11-query/#func-coalesce
18
+ # @see https://www.w3.org/TR/sparql11-query/#func-coalesce
19
19
  class Coalesce < Operator
20
20
  include Evaluatable
21
21
 
@@ -41,25 +41,15 @@ module SPARQL; module Algebra
41
41
  # options passed from query
42
42
  # @return [RDF::Term]
43
43
  # @raise [TypeError] if none of the operands succeeds
44
- def evaluate(bindings, options = {})
44
+ def evaluate(bindings, **options)
45
45
  operands.each do |op|
46
46
  begin
47
- return op.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))
47
+ return op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
48
48
  rescue
49
49
  end
50
50
  end
51
51
  raise TypeError, "None of the operands evaluated"
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 # Coalesce
64
54
  end # Operator
65
55
  end; end # SPARQL::Algebra
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (<=> ?x ?y)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#OperatorMapping
10
- # @see http://www.w3.org/TR/xpath-functions/#func-compare
9
+ # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-compare
11
11
  class Compare < Operator::Binary
12
12
  include Evaluatable
13
13
 
@@ -33,14 +33,14 @@ module SPARQL; module Algebra
33
33
  # @raise [TypeError] if either operand is not a literal
34
34
  def apply(left, right)
35
35
  case
36
- # @see http://www.w3.org/TR/sparql11-query/#OperatorMapping
37
- # @see http://www.w3.org/TR/sparql11-query/#modOrderBy
36
+ # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
37
+ # @see https://www.w3.org/TR/sparql11-query/#modOrderBy
38
38
  when left.is_a?(RDF::Literal) && right.is_a?(RDF::Literal)
39
39
  case
40
- # @see http://www.w3.org/TR/xpath-functions/#string-compare
41
- # @see http://www.w3.org/TR/xpath-functions/#comp.numeric
42
- # @see http://www.w3.org/TR/xpath-functions/#op.boolean
43
- # @see http://www.w3.org/TR/xpath-functions/#comp.duration.datetime
40
+ # @see https://www.w3.org/TR/xpath-functions/#string-compare
41
+ # @see https://www.w3.org/TR/xpath-functions/#comp.numeric
42
+ # @see https://www.w3.org/TR/xpath-functions/#op.boolean
43
+ # @see https://www.w3.org/TR/xpath-functions/#comp.duration.datetime
44
44
  when (left.simple? && right.simple?) ||
45
45
  (left.is_a?(RDF::Literal::Numeric) && right.is_a?(RDF::Literal::Numeric)) ||
46
46
  (left.datatype == right.datatype && left.language == right.language)
@@ -8,8 +8,8 @@ module SPARQL; module Algebra
8
8
  # @example
9
9
  # (concat ?a ?b ...)
10
10
  #
11
- # @see http://www.w3.org/TR/sparql11-query/#func-concat
12
- # @see http://www.w3.org/TR/xpath-functions/#func-concat
11
+ # @see https://www.w3.org/TR/sparql11-query/#func-concat
12
+ # @see https://www.w3.org/TR/xpath-functions/#func-concat
13
13
  class Concat < Operator
14
14
  include Evaluatable
15
15
 
@@ -32,8 +32,8 @@ module SPARQL; module Algebra
32
32
  # options passed from query
33
33
  # @return [RDF::Term]
34
34
  # @raise [TypeError] if any operand is not a literal
35
- def evaluate(bindings, options = {})
36
- ops = operands.map {|op| op.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))}
35
+ def evaluate(bindings, **options)
36
+ ops = operands.map {|op| op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)}
37
37
 
38
38
  raise TypeError, "expected all plain literal operands" unless ops.all? {|op| op.literal? && op.plain?}
39
39
 
@@ -12,7 +12,7 @@ module SPARQL; module Algebra
12
12
  # (project (?s ?p ?o)
13
13
  # (bgp (triple ?s ?p ?o)))))
14
14
  #
15
- # @see http://www.w3.org/TR/sparql11-query/#construct
15
+ # @see https://www.w3.org/TR/sparql11-query/#construct
16
16
  class Construct < Operator::Binary
17
17
  include Query
18
18
 
@@ -34,14 +34,14 @@ module SPARQL; module Algebra
34
34
  # @yieldreturn [void] ignored
35
35
  # @return [RDF::Queryable]
36
36
  # A Queryable with constructed triples
37
- # @see http://www.w3.org/TR/sparql11-query/#construct
38
- def execute(queryable, options = {}, &block)
37
+ # @see https://www.w3.org/TR/sparql11-query/#construct
38
+ def execute(queryable, **options, &block)
39
39
  debug(options) {"Construct #{operands.first}, #{options.inspect}"}
40
40
  graph = RDF::Graph.new
41
41
  patterns = operands.first
42
42
  query = operands.last
43
43
 
44
- queryable.query(query, options.merge(depth: options[:depth].to_i + 1)).each do |solution|
44
+ queryable.query(query, depth: options[:depth].to_i + 1, **options).each do |solution|
45
45
  debug(options) {"(construct apply) #{solution.inspect} to BGP"}
46
46
 
47
47
  # Create a mapping from BNodes within the pattern list to newly constructed BNodes
@@ -74,16 +74,6 @@ module SPARQL; module Algebra
74
74
  graph.each(&block) if block_given?
75
75
  graph
76
76
  end
77
-
78
- ##
79
- # Returns an optimized version of this query.
80
- #
81
- # Return optimized query
82
- #
83
- # @return [Union, RDF::Query] `self`
84
- def optimize
85
- operands = operands.map(&:optimize)
86
- end
87
77
 
88
78
  # Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE)
89
79
  # @return [Boolean]