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
@@ -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/#evaluation
12
+ # @see https://www.w3.org/TR/sparql11-query/#evaluation
13
13
  class Filter < Operator::Binary
14
14
  include Query
15
15
 
@@ -34,15 +34,15 @@ module SPARQL; module Algebra
34
34
  # @yieldreturn [void] ignored
35
35
  # @return [RDF::Query::Solutions]
36
36
  # the resulting solution sequence
37
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
38
- # @see http://www.w3.org/TR/sparql11-query/#ebv
39
- def execute(queryable, options = {}, &block)
37
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
38
+ # @see https://www.w3.org/TR/sparql11-query/#ebv
39
+ def execute(queryable, **options, &block)
40
40
  debug(options) {"Filter #{operands.first.to_sxp}"}
41
41
  opts = options.merge(queryable: queryable, depth: options[:depth].to_i + 1)
42
42
  @solutions = RDF::Query::Solutions()
43
- queryable.query(operands.last, options.merge(depth: options[:depth].to_i + 1)) do |solution|
43
+ queryable.query(operands.last, depth: options[:depth].to_i + 1, **options) do |solution|
44
44
  begin
45
- pass = boolean(operands.first.evaluate(solution, opts)).true?
45
+ pass = boolean(operands.first.evaluate(solution, **opts)).true?
46
46
  debug(options) {"(filter) #{pass.inspect} #{solution.to_h.inspect}"}
47
47
  @solutions << solution if pass
48
48
  rescue
@@ -69,16 +69,6 @@ module SPARQL; module Algebra
69
69
  end
70
70
  self
71
71
  end
72
-
73
- ##
74
- # Returns an optimized version of this query.
75
- #
76
- # Return optimized query
77
- #
78
- # @return [Union, RDF::Query] `self`
79
- def optimize
80
- operands = operands.map(&:optimize)
81
- end
82
72
  end # Filter
83
73
  end # Operator
84
74
  end; end # SPARQL::Algebra
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (floor ?x)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-floor
10
- # @see http://www.w3.org/TR/xpath-functions/#func-floor
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-floor
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-floor
11
11
  class Floor < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -15,7 +15,7 @@ module SPARQL; module Algebra
15
15
  # (graph :g
16
16
  # ((triple :s :p :o))))
17
17
  #
18
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
18
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
19
19
  class Graph < Operator::Binary
20
20
  include Query
21
21
 
@@ -36,7 +36,7 @@ module SPARQL; module Algebra
36
36
  # @param [Array<RDF::Query::Pattern>] patterns
37
37
  # Quads
38
38
  # @return [RDF::Query]
39
- def self.new(name, patterns, &block)
39
+ def self.new(name, patterns, **options, &block)
40
40
  case patterns
41
41
  when RDF::Query
42
42
  # Record that the argument as a (bgp) for re-serialization back to SSE
@@ -63,26 +63,15 @@ module SPARQL; module Algebra
63
63
  # @yieldreturn [void] ignored
64
64
  # @return [RDF::Query::Solutions]
65
65
  # the resulting solution sequence
66
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
67
- def execute(queryable, options = {}, &block)
66
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
67
+ def execute(queryable, **options, &block)
68
68
  debug(options) {"Graph #{operands.first}"}
69
69
  graph_name, query = operands.first, operands.last
70
- @solutions = queryable.query(query, options.merge(graph_name: graph_name), &block)
70
+ @solutions = queryable.query(query, graph_name: graph_name, **options, &block)
71
71
  end
72
-
73
- ##
74
- # Returns an optimized version of this query.
75
- #
76
- # Return optimized query
77
- #
78
- # @return [Union, RDF::Query] `self`
79
- def optimize
80
- operands = operands.map(&:optimize)
81
- end
82
-
72
+
83
73
  ##
84
74
  # Don't do any more rewriting
85
- # FIXME: if ooperator is JOIN, and rewritten sub-operators are queries, can do simple merge of sub-graphs
86
75
  # @return [SPARQL::Algebra::Expression] `self`
87
76
  def rewrite(&block)
88
77
  self
@@ -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-greater-than
12
- # @see http://www.w3.org/TR/xpath-functions/#func-boolean-greater-than
13
- # @see http://www.w3.org/TR/xpath-functions/#func-dateTime-greater-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-greater-than
12
+ # @see https://www.w3.org/TR/xpath-functions/#func-boolean-greater-than
13
+ # @see https://www.w3.org/TR/xpath-functions/#func-dateTime-greater-than
14
14
  class GreaterThan < Compare
15
15
  NAME = :>
16
16
 
@@ -7,11 +7,11 @@ module SPARQL; module Algebra
7
7
  # @example
8
8
  # (>= ?x ?y)
9
9
  #
10
- # @see http://www.w3.org/TR/sparql11-query/#OperatorMapping
11
- # @see http://www.w3.org/TR/xpath-functions/#func-compare
12
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-greater-than
13
- # @see http://www.w3.org/TR/xpath-functions/#func-boolean-greater-than
14
- # @see http://www.w3.org/TR/xpath-functions/#func-dateTime-greater-than
10
+ # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
11
+ # @see https://www.w3.org/TR/xpath-functions/#func-compare
12
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-greater-than
13
+ # @see https://www.w3.org/TR/xpath-functions/#func-boolean-greater-than
14
+ # @see https://www.w3.org/TR/xpath-functions/#func-dateTime-greater-than
15
15
  class GreaterThanOrEqual < Compare
16
16
  NAME = :>=
17
17
 
@@ -11,13 +11,13 @@ module SPARQL; module Algebra
11
11
  # @example
12
12
  # (prefix ((: <http://example/>))
13
13
  # (project (?w ?S)
14
- # (extend ((?S ?.0))
15
- # (group (?w) ((?.0 (sample ?v)))
14
+ # (extend ((?S ??.0))
15
+ # (group (?w) ((??.0 (sample ?v)))
16
16
  # (leftjoin
17
17
  # (bgp (triple ?s :p ?v))
18
18
  # (bgp (triple ?s :q ?w)))))))
19
19
  #
20
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
20
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
21
21
  class Group < Operator
22
22
  include Query
23
23
 
@@ -37,13 +37,13 @@ module SPARQL; module Algebra
37
37
  # @yieldreturn [void] ignored
38
38
  # @return [RDF::Query::Solutions]
39
39
  # the resulting solution sequence
40
- # @see http://www.w3.org/TR/sparql11-query/#sparqlGroupAggregate
41
- def execute(queryable, options = {}, &block)
40
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlGroupAggregate
41
+ def execute(queryable, **options, &block)
42
42
  debug(options) {"Group"}
43
43
  exprlist = operands.first
44
44
  query = operands.last
45
45
  aggregates = operands.length == 3 ? operand(1) : []
46
- solutions = queryable.query(query, options.merge(depth: options[:depth].to_i + 1))
46
+ solutions = queryable.query(query, depth: options[:depth].to_i + 1, **options)
47
47
 
48
48
  groups = solutions.group_by do |solution|
49
49
  # Evaluate each exprlist operand to get groups where each key is a new solution
@@ -54,14 +54,14 @@ module SPARQL; module Algebra
54
54
  if operand.is_a?(Array)
55
55
  # Form is [variable, expression]
56
56
  soln[operand.first] = operand.last.evaluate(solution,
57
- options.merge(
58
- queryable: queryable,
59
- depth: options[:depth].to_i + 1))
57
+ queryable: queryable,
58
+ depth: options[:depth].to_i + 1,
59
+ **options)
60
60
  else
61
61
  # Form is variable
62
- soln[operand] = operand.evaluate(solution, options.merge(
63
- queryable: queryable,
64
- depth: options[:depth].to_i + 1))
62
+ soln[operand] = operand.evaluate(solution, queryable: queryable,
63
+ depth: options[:depth].to_i + 1,
64
+ **options)
65
65
  end
66
66
  rescue TypeError
67
67
  # Ignore expression
@@ -76,7 +76,7 @@ module SPARQL; module Algebra
76
76
  @solutions = RDF::Query::Solutions(groups.map do |group_soln, solns|
77
77
  aggregates.each do |(var, aggregate)|
78
78
  begin
79
- group_soln[var] = aggregate.aggregate(solns, options)
79
+ group_soln[var] = aggregate.aggregate(solns, **options)
80
80
  rescue TypeError
81
81
  # Ignored in output
82
82
  end
@@ -84,8 +84,18 @@ module SPARQL; module Algebra
84
84
  group_soln
85
85
  end)
86
86
 
87
- # Make sure that's at least an empty solution
88
- @solutions << RDF::Query::Solution.new if @solutions.empty?
87
+ # If there exprlist is empty, make sure that's at least an empty solution
88
+ if @solutions.empty? && exprlist.empty?
89
+ soln = RDF::Query::Solution.new
90
+ aggregates.each do |(var, aggregate)|
91
+ begin
92
+ soln[var] = aggregate.aggregate([], **options)
93
+ rescue TypeError
94
+ # Ignored in output
95
+ end
96
+ end
97
+ @solutions << soln
98
+ end
89
99
 
90
100
  debug(options) {"=>(solutions) #{@solutions.inspect}"}
91
101
  @solutions.each(&block) if block_given?
@@ -112,16 +122,6 @@ module SPARQL; module Algebra
112
122
  end
113
123
  super
114
124
  end
115
-
116
- ##
117
- # Returns an optimized version of this query.
118
- #
119
- # TODO
120
- #
121
- # @return [Group] `self`
122
- def optimize
123
- self
124
- end
125
125
  end # Group
126
126
  end # Operator
127
127
  end; end # SPARQL::Algebra
@@ -9,11 +9,11 @@ module SPARQL; module Algebra
9
9
  # (prefix ((: <http://www.example.org/>))
10
10
  # (filter (|| (= ?g "1 22") (= ?g "22 1"))
11
11
  # (project (?g)
12
- # (extend ((?g ?.0))
13
- # (group () ((?.0 (group_concat ?o)))
14
- # (bgp (triple ??0 :p1 ?o)))))))
12
+ # (extend ((?g ??.0))
13
+ # (group () ((??.0 (group_concat ?o)))
14
+ # (bgp (triple ??.0 :p1 ?o)))))))
15
15
  #
16
- # @see http://www.w3.org/TR/sparql11-query/#defn_aggGroupConcat
16
+ # @see https://www.w3.org/TR/sparql11-query/#defn_aggGroupConcat
17
17
  class GroupConcat < Operator
18
18
  include Aggregate
19
19
 
@@ -29,12 +29,12 @@ module SPARQL; module Algebra
29
29
  # @return [RDF::Term]
30
30
  # @raise [TypeError]
31
31
  # @abstract
32
- def aggregate(solutions = [], options = {})
32
+ def aggregate(solutions = [], **options)
33
33
  operands.shift if distinct = (operands.first == :distinct)
34
34
  sep = operands.length == 2 ? operand(0).last : RDF::Literal(' ')
35
35
  args_enum = solutions.map do |solution|
36
36
  begin
37
- operands.last.evaluate(solution, options.merge(depth: options[:depth].to_i + 1))
37
+ operands.last.evaluate(solution, depth: options[:depth].to_i + 1, **options)
38
38
  rescue TypeError
39
39
  # Ignore errors
40
40
  nil
@@ -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)
@@ -43,7 +45,7 @@ module SPARQL; module Algebra
43
45
  end
44
46
  patterns.each do |pattern|
45
47
  pattern = pattern.dup.bind(solution)
46
- debug(options) {"Insert statement #{statement.to_sse}"}
48
+ debug(options) {"Insert pattern #{pattern.to_sse}"}
47
49
  # Only insert bound or constant patterns
48
50
  queryable.insert(RDF::Statement.from(pattern)) if pattern.bound? || pattern.constant?
49
51
  end
@@ -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