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
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # (extend ((?x (hours ?date)))
10
10
  # (bgp (triple ?s :date ?date)))))
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-query/#func-hours
12
+ # @see https://www.w3.org/TR/sparql11-query/#func-hours
13
13
  class Hours < Operator::Unary
14
14
  include Evaluatable
15
15
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (extend ((?integer (if (= (lang ?o) "ja") true false)))
11
11
  # (bgp (triple ?s ?p ?o))))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#func-if
13
+ # @see https://www.w3.org/TR/sparql11-query/#func-if
14
14
  class If < Operator::Ternary
15
15
  include Evaluatable
16
16
 
@@ -33,23 +33,13 @@ module SPARQL; module Algebra
33
33
  # a query solution containing zero or more variable bindings
34
34
  # @return [RDF::Term]
35
35
  # @raise [TypeError]
36
- def evaluate(bindings, options = {})
37
- operand(0).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1)) == RDF::Literal::TRUE ?
38
- operand(1).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1).merge(depth: options[:depth].to_i + 1)) :
39
- operand(2).evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))
36
+ def evaluate(bindings, **options)
37
+ operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options) == RDF::Literal::TRUE ?
38
+ operand(1).evaluate(bindings, depth: options[:depth].to_i + 1, **options) :
39
+ operand(2).evaluate(bindings, depth: options[:depth].to_i + 1, **options)
40
40
  rescue
41
41
  raise TypeError
42
42
  end
43
-
44
- ##
45
- # Returns an optimized version of this query.
46
- #
47
- # Return optimized query
48
- #
49
- # @return [Union, RDF::Query] `self`
50
- def optimize
51
- operands = operands.map(&:optimize)
52
- end
53
43
  end # If
54
44
  end # Operator
55
45
  end; end # SPARQL::Algebra
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (ask (filter (in 2 1 2 3) (bgp)))
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-in
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-in
10
10
  class In < Operator
11
11
  include Evaluatable
12
12
 
@@ -38,12 +38,12 @@ module SPARQL; module Algebra
38
38
  # options passed from query
39
39
  # @return [RDF::Literal::Boolean] `true` or `false`
40
40
  # @raise [TypeError] if term is not found and any operand raises an error
41
- def evaluate(bindings, options = {})
42
- lhs = operands.first.evaluate(bindings, options)
41
+ def evaluate(bindings, **options)
42
+ lhs = operands.first.evaluate(bindings, **options)
43
43
  error_found = false
44
44
  found = operands[1..-1].any? do |op|
45
45
  begin
46
- lhs == op.evaluate(bindings, options.merge(depth: options[:depth].to_i + 1))
46
+ lhs == op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)
47
47
  rescue TypeError
48
48
  error_found = true
49
49
  end
@@ -54,16 +54,6 @@ module SPARQL; module Algebra
54
54
  else RDF::Literal::FALSE
55
55
  end
56
56
  end
57
-
58
- ##
59
- # Returns an optimized version of this query.
60
- #
61
- # Return optimized query
62
- #
63
- # @return [Union, RDF::Query] `self`
64
- def optimize
65
- operands = operands.map(&:optimize)
66
- end
67
57
  end # In
68
58
  end # Operator
69
59
  end; end # SPARQL::Algebra
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # @example
10
10
  # (insert ((triple ?s ?p "q")))
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-update/#insert
12
+ # @see https://www.w3.org/TR/sparql11-update/#insert
13
13
  class Insert < Operator::Unary
14
14
  include SPARQL::Algebra::Update
15
15
 
@@ -20,7 +20,7 @@ module SPARQL; module Algebra
20
20
  #
21
21
  # @param [RDF::Queryable] queryable
22
22
  # the graph or repository to write
23
- # @param [RDF::Query::Solution] solution
23
+ # @param [RDF::Query::Solutions] solutions
24
24
  # Solution to map to patterns for this operation
25
25
  # @param [Hash{Symbol => Object}] options
26
26
  # any additional keyword options
@@ -30,8 +30,10 @@ module SPARQL; module Algebra
30
30
  # Returns queryable.
31
31
  # @raise [IOError]
32
32
  # If `from` does not exist, unless the `silent` operator is present
33
- # @see http://www.w3.org/TR/sparql11-update/
34
- def execute(queryable, solution, options = {})
33
+ # @see https://www.w3.org/TR/sparql11-update/
34
+ def execute(queryable, solutions: nil, **options)
35
+ # Only binds the first solution
36
+ solution = solutions.is_a?(RDF::Query::Solutions) ? solutions.first : solutions
35
37
  debug(options) {"Insert"}
36
38
  patterns = operand.inject([]) do |memo, op|
37
39
  if op.respond_to?(:statements)
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # @example
10
10
  # (insertData ((graph <http://example.org/g1> ((triple :s :p :o)))))
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-update/#insertData
12
+ # @see https://www.w3.org/TR/sparql11-update/#insertData
13
13
  class InsertData < Operator::Unary
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
  operand.each do |op|
34
34
  debug(options) {"InsertData #{op.to_sxp}"}
35
35
  queryable.insert(op)
@@ -8,7 +8,7 @@ module SPARQL; module Algebra
8
8
  # (extend ((?uri (uri "uri")) (?iri (iri "iri")))
9
9
  # (bgp))))
10
10
  #
11
- # @see http://www.w3.org/TR/sparql11-query/#func-iri
11
+ # @see https://www.w3.org/TR/sparql11-query/#func-iri
12
12
  class IRI < Operator::Unary
13
13
  include Evaluatable
14
14
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (filter (isBlank ?v)
11
11
  # (bgp (triple ?x :p ?v)))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#func-isBlank
13
+ # @see https://www.w3.org/TR/sparql11-query/#func-isBlank
14
14
  class IsBlank < Operator::Unary
15
15
  include Evaluatable
16
16
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (filter (isIRI ?v)
11
11
  # (bgp (triple ?x :p ?v)))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#func-isIRI
13
+ # @see https://www.w3.org/TR/sparql11-query/#func-isIRI
14
14
  class IsIRI < Operator::Unary
15
15
  include Evaluatable
16
16
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (filter (isLiteral ?v)
11
11
  # (bgp (triple ?x :p ?v)))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#func-isLiteral
13
+ # @see https://www.w3.org/TR/sparql11-query/#func-isLiteral
14
14
  class IsLiteral < Operator::Unary
15
15
  include Evaluatable
16
16
 
@@ -12,7 +12,7 @@ module SPARQL; module Algebra
12
12
  # (filter (isNumeric ?v)
13
13
  # (bgp (triple ?x :p ?v)))))
14
14
  #
15
- # @see http://www.w3.org/TR/sparql11-query/#func-isNumeric
15
+ # @see https://www.w3.org/TR/sparql11-query/#func-isNumeric
16
16
  class IsNumeric < Operator::Unary
17
17
  include Evaluatable
18
18
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (graph ?g
11
11
  # (bgp (triple ?s ?q ?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 Join < Operator::Binary
15
15
  include Query
16
16
 
@@ -31,20 +31,20 @@ module SPARQL; module Algebra
31
31
  # @yieldreturn [void] ignored
32
32
  # @return [RDF::Query::Solutions]
33
33
  # the resulting solution sequence
34
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
35
- # @see http://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#merge-instance_method
36
- # @see http://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#compatible%3F-instance_method
37
- def execute(queryable, options = {}, &block)
34
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
35
+ # @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#merge-instance_method
36
+ # @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#compatible%3F-instance_method
37
+ def execute(queryable, **options, &block)
38
38
  # Join(Ω1, Ω2) = { merge(μ1, μ2) | μ1 in Ω1 and μ2 in Ω2, and μ1 and μ2 are compatible }
39
39
  # eval(D(G), Join(P1, P2)) = Join(eval(D(G), P1), eval(D(G), P2))
40
40
  #
41
41
  # Generate solutions independently, merge based on solution compatibility
42
42
  debug(options) {"Join #{operands.to_sse}"}
43
43
 
44
- left = queryable.query(operand(0), options.merge(depth: options[:depth].to_i + 1))
44
+ left = queryable.query(operand(0), depth: options[:depth].to_i + 1, **options)
45
45
  debug(options) {"(join)=>(left) #{left.map(&:to_h).to_sse}"}
46
46
 
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) {"(join)=>(right) #{right.map(&:to_h).to_sse}"}
49
49
 
50
50
  @solutions = RDF::Query::Solutions(left.map do |s1|
@@ -67,7 +67,7 @@ module SPARQL; module Algebra
67
67
  end
68
68
 
69
69
  ##
70
- # Returns an optimized version of this query.
70
+ # Optimizes this query.
71
71
  #
72
72
  # Groups of one graph pattern (not a filter) become join(Z, A) and can be replaced by A.
73
73
  # The empty graph pattern Z is the identity for join:
@@ -75,8 +75,10 @@ module SPARQL; module Algebra
75
75
  # Replace join(A, Z) by A
76
76
  #
77
77
  # @return [Join, RDF::Query] `self`
78
- def optimize
79
- ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?}
78
+ # @return [self]
79
+ # @see SPARQL::Algebra::Expression#optimize!
80
+ def optimize!(**options)
81
+ ops = operands.map {|o| o.optimize(**options) }.select {|o| o.respond_to?(:empty?) && !o.empty?}
80
82
  @operands = ops
81
83
  self
82
84
  end
@@ -3,7 +3,7 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `lang` operator.
5
5
  #
6
- # @see http://www.w3.org/TR/sparql11-query/#func-lang
6
+ # @see https://www.w3.org/TR/sparql11-query/#func-lang
7
7
  class Lang < Operator::Unary
8
8
  include Evaluatable
9
9
 
@@ -8,8 +8,8 @@ module SPARQL; module Algebra
8
8
  # (filter (langMatches (lang ?v) "en-GB")
9
9
  # (bgp (triple :x ?p ?v))))
10
10
  #
11
- # @see http://www.w3.org/TR/sparql11-query/#func-langMatches
12
- # @see http://tools.ietf.org/html/rfc4647#section-3.3.1
11
+ # @see https://www.w3.org/TR/sparql11-query/#func-langMatches
12
+ # @see https://tools.ietf.org/html/rfc4647#section-3.3.1
13
13
  class LangMatches < Operator::Binary
14
14
  include Evaluatable
15
15
 
@@ -23,7 +23,7 @@ module SPARQL; module Algebra
23
23
  # a simple literal containing a language tag
24
24
  # @param [RDF::Literal] language_range
25
25
  # a simple literal containing a language range, per
26
- # [RFC 4647 section 2.1](http://tools.ietf.org/html/rfc4647#section-2.1)
26
+ # [RFC 4647 section 2.1](https://tools.ietf.org/html/rfc4647#section-2.1)
27
27
  # @return [RDF::Literal::Boolean] `true` or `false`
28
28
  # @raise [TypeError] if either operand is unbound
29
29
  # @raise [TypeError] if either operand is not a simple literal
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (lcase ?x)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-lcase
10
- # @see http://www.w3.org/TR/xpath-functions/#func-lcase
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-lcase
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-lcase
11
11
  class LCase < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (bgp (triple ?y :q ?w))
11
11
  # (= ?v 2)))
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 LeftJoin < Operator
15
15
  include Query
16
16
 
@@ -31,17 +31,17 @@ module SPARQL; module Algebra
31
31
  # @yieldreturn [void] ignored
32
32
  # @return [RDF::Query::Solutions]
33
33
  # the resulting solution sequence
34
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
35
- # @see http://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#merge-instance_method
36
- # @see http://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#compatible%3F-instance_method
37
- def execute(queryable, options = {}, &block)
34
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
35
+ # @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#merge-instance_method
36
+ # @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Query/Solution#compatible%3F-instance_method
37
+ def execute(queryable, **options, &block)
38
38
  filter = operand(2)
39
39
 
40
40
  debug(options) {"LeftJoin"}
41
- left = queryable.query(operand(0), options.merge(depth: options[:depth].to_i + 1))
41
+ left = queryable.query(operand(0), depth: options[:depth].to_i + 1, **options)
42
42
  debug(options) {"=>(leftjoin left) #{left.inspect}"}
43
43
 
44
- right = queryable.query(operand(1), options.merge(depth: options[:depth].to_i + 1))
44
+ right = queryable.query(operand(1), depth: options[:depth].to_i + 1, **options)
45
45
  debug(options) {"=>(leftjoin right) #{right.inspect}"}
46
46
 
47
47
  # LeftJoin(Ω1, Ω2, expr) =
@@ -83,14 +83,17 @@ module SPARQL; module Algebra
83
83
  end
84
84
 
85
85
  ##
86
- # Returns an optimized version of this query.
86
+ # Optimizes this query.
87
87
  #
88
88
  # If optimize operands, and if the first two operands are both Queries, replace
89
89
  # with the unique sum of the query elements
90
90
  #
91
- # @return [Union, RDF::Query] `self`
92
- def optimize
93
- ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?}
91
+ # @return [Object] a copy of `self`
92
+ # @see SPARQL::Algebra::Expression#optimize
93
+ # FIXME
94
+ def optimize!(**options)
95
+ return self
96
+ ops = operands.map {|o| o.optimize(**options) }.select {|o| o.respond_to?(:empty?) && !o.empty?}
94
97
  expr = ops.pop unless ops.last.executable?
95
98
  expr = nil if expr.respond_to?(:true?) && expr.true?
96
99
 
@@ -102,7 +105,7 @@ module SPARQL; module Algebra
102
105
  when 1
103
106
  expr ? Filter.new(expr, ops.first) : ops.first
104
107
  else
105
- expr ? LeftJoin(ops[0], ops[1], expr) : LeftJoin(ops[0], ops[1])
108
+ expr ? LeftJoin.new(ops[0], ops[1], expr) : LeftJoin.new(ops[0], ops[1])
106
109
  end
107
110
  end
108
111
  end # LeftJoin
@@ -6,11 +6,11 @@ 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
11
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-less-than
12
- # @see http://www.w3.org/TR/xpath-functions/#func-boolean-less-than
13
- # @see http://www.w3.org/TR/xpath-functions/#func-dateTime-less-than
9
+ # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-compare
11
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-less-than
12
+ # @see https://www.w3.org/TR/xpath-functions/#func-boolean-less-than
13
+ # @see https://www.w3.org/TR/xpath-functions/#func-dateTime-less-than
14
14
  class LessThan < Compare
15
15
  NAME = :<
16
16
 
@@ -6,11 +6,11 @@ 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
11
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-less-than
12
- # @see http://www.w3.org/TR/xpath-functions/#func-boolean-less-than
13
- # @see http://www.w3.org/TR/xpath-functions/#func-dateTime-less-than
9
+ # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-compare
11
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-less-than
12
+ # @see https://www.w3.org/TR/xpath-functions/#func-boolean-less-than
13
+ # @see https://www.w3.org/TR/xpath-functions/#func-dateTime-less-than
14
14
  class LessThanOrEqual < Compare
15
15
  NAME = :<=
16
16
 
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # @example
10
10
  # (load <remote> <g>)
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-update/#load
12
+ # @see https://www.w3.org/TR/sparql11-update/#load
13
13
  class Load < 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) {"Load"}
34
34
  silent = operands.first == :silent
35
35
  operands.shift if silent
@@ -6,12 +6,12 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (prefix ((: <http://www.example.org/>))
8
8
  # (project (?max)
9
- # (extend ((?max ?.0))
10
- # (group () ((?.0 (max ?o)))
9
+ # (extend ((?max ??.0))
10
+ # (group () ((??.0 (max ?o)))
11
11
  # (bgp (triple ?s ?p ?o))))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#defn_aggMax
14
- class Max < Operator::Unary
13
+ # @see https://www.w3.org/TR/sparql11-query/#defn_aggMax
14
+ class Max < Operator
15
15
  include Aggregate
16
16
 
17
17
  NAME = :max
@@ -25,6 +25,8 @@ module SPARQL; module Algebra
25
25
  # enum of evaluated operand
26
26
  # @return [RDF::Literal] The maximum value of the terms
27
27
  def apply(enum)
28
+ # FIXME: we don't actually do anything with distinct
29
+ operands.shift if distinct = (operands.first == :distinct)
28
30
  if enum.empty?
29
31
  raise TypeError, "Maximum of an empty multiset"
30
32
  elsif enum.flatten.all? {|n| n.literal?}
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
13
13
  # (extend ((?hash (md5 ?l)))
14
14
  # (bgp (triple :s1 :str ?l)))))
15
15
  #
16
- # @see http://www.w3.org/TR/sparql11-query/#func-md5
16
+ # @see https://www.w3.org/TR/sparql11-query/#func-md5
17
17
  class MD5 < Operator::Unary
18
18
  include Evaluatable
19
19
 
@@ -6,12 +6,12 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (prefix ((: <http://www.example.org/>))
8
8
  # (project (?max)
9
- # (extend ((?min ?.0))
10
- # (group () ((?.0 (min ?o)))
9
+ # (extend ((?min ??.0))
10
+ # (group () ((??.0 (min ?o)))
11
11
  # (bgp (triple ?s ?p ?o))))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#defn_aggMin
14
- class Min < Operator::Unary
13
+ # @see https://www.w3.org/TR/sparql11-query/#defn_aggMin
14
+ class Min < Operator
15
15
  include Aggregate
16
16
 
17
17
  NAME = :min
@@ -25,6 +25,8 @@ module SPARQL; module Algebra
25
25
  # enum of evaluated operand
26
26
  # @return [RDF::Literal] The maximum value of the terms
27
27
  def apply(enum)
28
+ # FIXME: we don't actually do anything with distinct
29
+ operands.shift if distinct = (operands.first == :distinct)
28
30
  if enum.empty?
29
31
  raise TypeError, "Minumuim of an empty multiset"
30
32
  elsif enum.flatten.all? {|n| n.literal?}