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
@@ -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_OneOrMorePath
9
+ # @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_OneOrMorePath
10
10
  class PathPlus < Operator::Unary
11
11
  include Query
12
12
 
@@ -25,8 +25,8 @@ module SPARQL; module Algebra
25
25
  # each matching solution
26
26
  # @yieldparam [RDF::Query::Solution] solution
27
27
  # @yieldreturn [void] ignored
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
  subject, object = options[:subject], options[:object]
31
31
  debug(options) {"Path+ #{[subject, operands, object].to_sse}"}
32
32
 
@@ -53,7 +53,7 @@ module SPARQL; module Algebra
53
53
  # Keep track of solutions
54
54
  # Recurse into query
55
55
  immediate_solutions = []
56
- queryable.query(query, options.merge(depth: options[:depth].to_i + 1)) do |solution|
56
+ queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
57
57
  immediate_solutions << solution
58
58
  end
59
59
 
@@ -66,23 +66,23 @@ module SPARQL; module Algebra
66
66
  case
67
67
  when subject.variable? && object.variable?
68
68
  # Query starting with bound object as subject, but replace result with subject
69
- rs = queryable.query(self, options.merge(
69
+ rs = queryable.query(self, **options.merge(
70
70
  subject: solution[object],
71
71
  accumulator: (cumulative_solutions + immediate_solutions),
72
72
  depth: options[:depth].to_i + 1)).map {|s| s.merge(subject.to_sym => solution[subject])}
73
73
  # Query starting with bound subject as object, but replace result with subject
74
- ro = queryable.query(self, options.merge(
74
+ ro = queryable.query(self, **options.merge(
75
75
  object: solution[subject],
76
76
  accumulator: (cumulative_solutions + immediate_solutions),
77
77
  depth: options[:depth].to_i + 1)).map {|s| s.merge(object.to_sym => solution[object])}
78
78
  recursive_solutions += (rs + ro).uniq
79
79
  when subject.variable?
80
- recursive_solutions += queryable.query(self, options.merge(
80
+ recursive_solutions += queryable.query(self, **options.merge(
81
81
  object: solution[subject],
82
82
  accumulator: (cumulative_solutions + immediate_solutions),
83
83
  depth: options[:depth].to_i + 1)).uniq
84
84
  when object.variable?
85
- recursive_solutions += queryable.query(self, options.merge(
85
+ recursive_solutions += queryable.query(self, **options.merge(
86
86
  subject: solution[object],
87
87
  accumulator: (cumulative_solutions + immediate_solutions),
88
88
  depth: options[:depth].to_i + 1)).uniq
@@ -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_ZeroOrMorePath
9
+ # @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_ZeroOrMorePath
10
10
  class PathStar < Operator::Unary
11
11
  include Query
12
12
 
@@ -28,14 +28,14 @@ module SPARQL; module Algebra
28
28
  # each matching solution
29
29
  # @yieldparam [RDF::Query::Solution] solution
30
30
  # @yieldreturn [void] ignored
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
  subject, object = options[:subject], options[:object]
34
34
  debug(options) {"Path* #{[subject, operands, object].to_sse}"}
35
35
 
36
36
  # (:x :p* :y) => (:x (:p+)? :y)
37
37
  query = PathOpt.new(PathPlus.new(*operands))
38
- query.execute(queryable, options.merge(depth: options[:depth].to_i + 1), &block)
38
+ query.execute(queryable, depth: options[:depth].to_i + 1, **options, &block)
39
39
  end
40
40
  end # PathStar
41
41
  end # Operator
@@ -7,9 +7,9 @@ module SPARQL; module Algebra
7
7
  # (+ ?x ?y)
8
8
  # (plus ?x ?y)
9
9
  #
10
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-unary-plus
11
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-add
12
- class Plus < Operator::Unary
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-unary-plus
11
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-add
12
+ class Plus < Operator
13
13
  include Evaluatable
14
14
 
15
15
  NAME = [:+, :plus]
@@ -8,7 +8,7 @@ module SPARQL; module Algebra
8
8
  # (graph ?g
9
9
  # (bgp (triple ?s ?p ?o))))
10
10
  #
11
- # @see http://www.w3.org/TR/sparql11-query/#QSynIRI
11
+ # @see https://www.w3.org/TR/sparql11-query/#QSynIRI
12
12
  class Prefix < Binary
13
13
  include Query
14
14
 
@@ -29,21 +29,21 @@ module SPARQL; module Algebra
29
29
  # @yieldreturn [void] ignored
30
30
  # @return [RDF::Query::Solutions]
31
31
  # the resulting solution sequence
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
  debug(options) {"Prefix"}
35
- @solutions = queryable.query(operands.last, options.merge(depth: options[:depth].to_i + 1), &block)
35
+ @solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options, &block)
36
36
  end
37
-
37
+
38
38
  ##
39
39
  # Returns an optimized version of this query.
40
40
  #
41
- # If optimize operands, and if the first two operands are both Queries, replace
42
- # with the unique sum of the query elements
41
+ # Replace with the query with URIs having their lexical shortcut removed
43
42
  #
44
- # @return [Union, RDF::Query] `self`
45
- def optimize
46
- operands.last.optimize
43
+ # @return [Prefix] a copy of `self`
44
+ # @see SPARQL::Algebra::Expression#optimize
45
+ def optimize(**options)
46
+ operands.last.optimize(**options)
47
47
  end
48
48
 
49
49
  # Combine two prefix definitions, merging their definitions
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # (filter (= ?v 2)
10
10
  # (bgp (triple ?s <http://example/p> ?v)))))
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-query/#modProjection
12
+ # @see https://www.w3.org/TR/sparql11-query/#modProjection
13
13
  class Project < Operator::Binary
14
14
  include Query
15
15
 
@@ -29,23 +29,13 @@ module SPARQL; module Algebra
29
29
  # @yieldreturn [void] ignored
30
30
  # @return [RDF::Query::Solutions]
31
31
  # the resulting solution sequence
32
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
33
- def execute(queryable, options = {}, &block)
34
- @solutions = queryable.query(operands.last, options.merge(depth: options[:depth].to_i + 1))
32
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
33
+ def execute(queryable, **options, &block)
34
+ @solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options)
35
35
  @solutions = @solutions.project(*(operands.first))
36
36
  @solutions.each(&block) if block_given?
37
37
  @solutions
38
38
  end
39
-
40
- ##
41
- # Returns an optimized version of this query.
42
- #
43
- # Return optimized query
44
- #
45
- # @return [Union, RDF::Query] `self`
46
- def optimize
47
- operands = operands.map(&:optimize)
48
- end
49
39
  end # Project
50
40
  end # Operator
51
41
  end; end # SPARQL::Algebra
@@ -8,7 +8,7 @@ module SPARQL; module Algebra
8
8
  # @example
9
9
  # (rand)
10
10
  #
11
- # @see http://www.w3.org/TR/sparql11-query/#idp2130040
11
+ # @see https://www.w3.org/TR/sparql11-query/#idp2130040
12
12
  class Rand < Operator::Nullary
13
13
  include Evaluatable
14
14
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (project (?v)
11
11
  # (bgp (triple ?x ?p ?v)))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
13
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
14
14
  class Reduced < Operator::Unary
15
15
  include Query
16
16
 
@@ -30,23 +30,13 @@ 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
  @solutions = operands.last.
36
- execute(queryable, options.merge(depth: options[:depth].to_i + 1)).reduced
36
+ execute(queryable, depth: options[:depth].to_i + 1, **options).reduced
37
37
  @solutions.each(&block) if block_given?
38
38
  @solutions
39
39
  end
40
-
41
- ##
42
- # Returns an optimized version of this query.
43
- #
44
- # Return optimized query
45
- #
46
- # @return [Union, RDF::Query] `self`
47
- def optimize
48
- operands = operands.map(&:optimize)
49
- end
50
40
  end # Reduced
51
41
  end # Operator
52
42
  end; end # SPARQL::Algebra
@@ -10,8 +10,8 @@ module SPARQL; module Algebra
10
10
  # (filter (regex ?val "GHI")
11
11
  # (bgp (triple ex:foo rdf:value ?val)))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#funcex-regex
14
- # @see http://www.w3.org/TR/xpath-functions/#func-matches
13
+ # @see https://www.w3.org/TR/sparql11-query/#funcex-regex
14
+ # @see https://www.w3.org/TR/xpath-functions/#func-matches
15
15
  class Regex < Operator::Ternary
16
16
  include Evaluatable
17
17
 
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
26
26
  # @param [Hash{Symbol => Object}] options
27
27
  # any additional options (see {Operator#initialize})
28
28
  # @raise [TypeError] if any operand is invalid
29
- def initialize(text, pattern, flags = RDF::Literal(''), options = {})
29
+ def initialize(text, pattern, flags = RDF::Literal(''), **options)
30
30
  super
31
31
  end
32
32
 
@@ -43,17 +43,17 @@ module SPARQL; module Algebra
43
43
  # @raise [TypeError] if any operand is unbound
44
44
  # @raise [TypeError] if any operand is not a simple literal
45
45
  def apply(text, pattern, flags = RDF::Literal(''))
46
- # @see http://www.w3.org/TR/xpath-functions/#regex-syntax
46
+ # @see https://www.w3.org/TR/xpath-functions/#regex-syntax
47
47
  raise TypeError, "expected a plain RDF::Literal, but got #{text.inspect}" unless text.is_a?(RDF::Literal) && text.plain?
48
48
  text = text.to_s
49
49
  # TODO: validate text syntax
50
50
 
51
- # @see http://www.w3.org/TR/xpath-functions/#regex-syntax
51
+ # @see https://www.w3.org/TR/xpath-functions/#regex-syntax
52
52
  raise TypeError, "expected a plain RDF::Literal, but got #{pattern.inspect}" unless pattern.is_a?(RDF::Literal) && pattern.plain?
53
53
  pattern = pattern.to_s
54
54
  # TODO: validate pattern syntax
55
55
 
56
- # @see http://www.w3.org/TR/xpath-functions/#flags
56
+ # @see https://www.w3.org/TR/xpath-functions/#flags
57
57
  raise TypeError, "expected a plain RDF::Literal, but got #{flags.inspect}" unless flags.is_a?(RDF::Literal) && flags.plain?
58
58
  flags = flags.to_s
59
59
  # TODO: validate flag syntax
@@ -10,8 +10,8 @@ module SPARQL; module Algebra
10
10
  # (extend ((?new (replace ?str "[^a-z0-9]" "-")))
11
11
  # (bgp (triple ?s :str ?str)))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#funcex-replace
14
- # @see http://www.w3.org/TR/xpath-functions/#func-replace
13
+ # @see https://www.w3.org/TR/sparql11-query/#funcex-replace
14
+ # @see https://www.w3.org/TR/xpath-functions/#func-replace
15
15
  class Replace < Operator::Quaternary
16
16
  include Evaluatable
17
17
 
@@ -27,7 +27,7 @@ module SPARQL; module Algebra
27
27
  # @param [Hash{Symbol => Object}] options
28
28
  # any additional options (see {Operator#initialize})
29
29
  # @raise [TypeError] if any operand is invalid
30
- def initialize(text, pattern, replacement, flags = RDF::Literal(''), options = {})
30
+ def initialize(text, pattern, replacement, flags = RDF::Literal(''), **options)
31
31
  super
32
32
  end
33
33
 
@@ -72,7 +72,7 @@ module SPARQL; module Algebra
72
72
  # Remove the optional argument.
73
73
  #
74
74
  # @return [Array] `self`
75
- # @see http://openjena.org/wiki/SSE
75
+ # @see https://openjena.org/wiki/SSE
76
76
  def to_sxp_bin
77
77
  [NAME] + operands.reject {|o| o.to_s == ""}
78
78
  end
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (reverse :p)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#defn_evalPP_inverse
9
+ # @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_inverse
10
10
  class Reverse < 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
  debug(options) {"Reverse #{operands.to_sse}"}
35
35
  subject, object = options[:subject], options[:object]
36
36
 
@@ -42,7 +42,7 @@ module SPARQL; module Algebra
42
42
  else
43
43
  operand(0)
44
44
  end
45
- queryable.query(query, options.merge(
45
+ queryable.query(query, **options.merge(
46
46
  subject: object,
47
47
  object: subject,
48
48
  depth: options[:depth].to_i + 1
@@ -8,8 +8,8 @@ module SPARQL; module Algebra
8
8
  # @example
9
9
  # (round ?x)
10
10
  #
11
- # @see http://www.w3.org/TR/sparql11-query/#func-round
12
- # @see http://www.w3.org/TR/xpath-functions/#func-round
11
+ # @see https://www.w3.org/TR/sparql11-query/#func-round
12
+ # @see https://www.w3.org/TR/xpath-functions/#func-round
13
13
  class Round < Operator::Unary
14
14
  include Evaluatable
15
15
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (filter (sameTerm ?v)
11
11
  # (bgp (triple ?x :p ?v)))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#func-sameTerm
13
+ # @see https://www.w3.org/TR/sparql11-query/#func-sameTerm
14
14
  class SameTerm < Operator::Binary
15
15
  include Evaluatable
16
16
 
@@ -33,12 +33,15 @@ module SPARQL; module Algebra
33
33
  ##
34
34
  # Returns an optimized version of this expression.
35
35
  #
36
- # @return [SPARQL::Algebra::Expression]
37
- def optimize
38
- if operand(0).is_a?(Variable) && operand(0).eql?(operand(1))
36
+ # Return true if variable operand1 is a bound variable and equals operand2
37
+ #
38
+ # @return [SameTerm] a copy of `self`
39
+ # @see SPARQL::Algebra::Expression#optimize
40
+ def optimize(**options)
41
+ if operand(0).is_a?(Variable) && operand(0).bound? && operand(0).eql?(operand(1))
39
42
  RDF::Literal::TRUE
40
43
  else
41
- super # @see Operator#optimize
44
+ super # @see Operator#optimize!
42
45
  end
43
46
  end
44
47
  end # SameTerm
@@ -7,11 +7,11 @@ module SPARQL; module Algebra
7
7
  # (prefix ((: <http://www.example.org/>))
8
8
  # (filter (|| (|| (= ?sample 1.0) (= ?sample 2.2)) (= ?sample 3.5))
9
9
  # (project (?sample)
10
- # (extend ((?sample ?.0))
11
- # (group () ((?.0 (sample ?o)))
10
+ # (extend ((?sample ??.0))
11
+ # (group () ((??.0 (sample ?o)))
12
12
  # (bgp (triple ?s :dec ?o)))))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#defn_aggSample
14
+ # @see https://www.w3.org/TR/sparql11-query/#defn_aggSample
15
15
  class Sample < Operator::Unary
16
16
  include Aggregate
17
17
 
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (extend ((?x (seconds ?date)))
12
12
  # (bgp (triple ?s :date ?date)))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#func-seconds
14
+ # @see https://www.w3.org/TR/sparql11-query/#func-seconds
15
15
  class Seconds < Operator::Unary
16
16
  include Evaluatable
17
17
 
@@ -28,13 +28,12 @@ module SPARQL; module Algebra
28
28
  # each matching solution
29
29
  # @yieldparam [RDF::Query::Solution] solution
30
30
  # @yieldreturn [void] ignored
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
  subject, object = options[:subject], options[:object]
34
34
  debug(options) {"Seq #{[subject, operands, object].to_sse}"}
35
35
 
36
- v = RDF::Query::Variable.new
37
- v.distinguished = false
36
+ v = RDF::Query::Variable.new(distinguished: false)
38
37
  q1 = if operand(0).is_a?(RDF::Term)
39
38
  RDF::Query.new do |q|
40
39
  q.pattern [subject, operand(0), v]
@@ -50,10 +49,10 @@ module SPARQL; module Algebra
50
49
  operand(1)
51
50
  end
52
51
 
53
- left = queryable.query(q1, options.merge(object: v, depth: options[:depth].to_i + 1))
52
+ left = queryable.query(q1, **options.merge(object: v, depth: options[:depth].to_i + 1))
54
53
  debug(options) {"(seq)=>(left) #{left.map(&:to_h).to_sse}"}
55
54
 
56
- right = queryable.query(q2, options.merge(subject: v, depth: options[:depth].to_i + 1))
55
+ right = queryable.query(q2, **options.merge(subject: v, depth: options[:depth].to_i + 1))
57
56
  debug(options) {"(seq)=>(right) #{right.map(&:to_h).to_sse}"}
58
57
 
59
58
  @solutions = RDF::Query::Solutions(left.map do |s1|
@@ -34,15 +34,15 @@ module SPARQL; module Algebra
34
34
  # each matching solution
35
35
  # @yieldparam [RDF::Query::Solution] solution
36
36
  # @yieldreturn [void] ignored
37
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
38
- def execute(queryable, options = {})
37
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
38
+ def execute(queryable, **options)
39
39
  debug(options) {"Sequence #{operands.to_sse}"}
40
40
 
41
- last = queryable.query(operands.shift, options.merge(depth: options[:depth].to_i + 1))
41
+ last = queryable.query(operands.shift, depth: options[:depth].to_i + 1, **options)
42
42
  debug(options) {"(sequence)=>(last) #{last.map(&:to_h).to_sse}"}
43
43
 
44
44
  operands.each do |op|
45
- this = queryable.query(op, options.merge(depth: options[:depth].to_i + 1))
45
+ this = queryable.query(op, depth: options[:depth].to_i + 1, **options)
46
46
  debug(options) {"(sequence)=>(this) #{this.map(&:to_h).to_sse}"}
47
47
 
48
48
  last = last.map do |s1|
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
13
13
  # (extend ((?hash (sha1 ?l)))
14
14
  # (bgp (triple :s1 :str ?l)))))
15
15
  #
16
- # @see http://www.w3.org/TR/sparql11-query/#func-sha1
16
+ # @see https://www.w3.org/TR/sparql11-query/#func-sha1
17
17
  class SHA1 < Operator::Unary
18
18
  include Evaluatable
19
19
 
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
13
13
  # (extend ((?hash (sha256 ?l)))
14
14
  # (bgp (triple :s1 :str ?l)))))
15
15
  #
16
- # @see http://www.w3.org/TR/sparql11-query/#func-sha256
16
+ # @see https://www.w3.org/TR/sparql11-query/#func-sha256
17
17
  class SHA256 < Operator::Unary
18
18
  include Evaluatable
19
19