sparql 3.0.1 → 3.1.4

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 +188 -73
  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 +63 -40
  14. data/lib/sparql/algebra/extensions.rb +180 -33
  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 +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 +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 +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 +5 -5
  145. data/lib/sparql/grammar.rb +111 -11
  146. data/lib/sparql/grammar/meta.rb +2340 -907
  147. data/lib/sparql/grammar/parser11.rb +69 -69
  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 +38 -65
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (strlen ?x)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-strlen
10
- # @see http://www.w3.org/TR/xpath-functions/#func-string-length
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-strlen
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-string-length
11
11
  class StrLen < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (strstarts ?x ?y)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-strstarts
10
- # @see http://www.w3.org/TR/xpath-functions/#func-starts-with
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-strstarts
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-starts-with
11
11
  class StrStarts < Operator::Binary
12
12
  include Evaluatable
13
13
 
@@ -14,7 +14,7 @@ module SPARQL; module Algebra
14
14
  # (extend ((?uuid (struuid)))
15
15
  # (bgp))))))
16
16
  #
17
- # @see http://www.w3.org/TR/sparql11-query/#func-struuid
17
+ # @see https://www.w3.org/TR/sparql11-query/#func-struuid
18
18
  class StrUUID < Operator::Nullary
19
19
  include Evaluatable
20
20
 
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (substr ?x ?y)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-substr
10
- # @see http://www.w3.org/TR/xpath-functions/#func-substring
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-substr
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-substring
11
11
  class SubStr < Operator::Ternary
12
12
  include Evaluatable
13
13
 
@@ -22,7 +22,7 @@ module SPARQL; module Algebra
22
22
  # @param [Hash{Symbol => Object}] options
23
23
  # any additional options (see {Operator#initialize})
24
24
  # @raise [TypeError] if any operand is invalid
25
- def initialize(source, startingLoc, length = RDF::Literal(""), options = {})
25
+ def initialize(source, startingLoc, length = RDF::Literal(""), **options)
26
26
  super
27
27
  end
28
28
 
@@ -71,7 +71,7 @@ module SPARQL; module Algebra
71
71
  # Remove the optional argument.
72
72
  #
73
73
  # @return [Array] `self`
74
- # @see http://openjena.org/wiki/SSE
74
+ # @see https://openjena.org/wiki/SSE
75
75
  def to_sxp_bin
76
76
  [NAME] + operands.reject {|o| o.to_s == ""}
77
77
  end
@@ -5,7 +5,7 @@ module SPARQL; module Algebra
5
5
  # (- ?x ?y)
6
6
  # (subtract ?x ?y)
7
7
  #
8
- # @see http://www.w3.org/TR/xpath-functions/#func-numeric-subtract
8
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-subtract
9
9
  class Subtract < Operator::Binary
10
10
  include Evaluatable
11
11
 
@@ -6,12 +6,12 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (prefix ((: <http://www.example.org/>))
8
8
  # (project (?sum)
9
- # (extend ((?sum ?.0))
10
- # (group () ((?.0 (sum ?o)))
9
+ # (extend ((?sum ??.0))
10
+ # (group () ((??.0 (sum ?o)))
11
11
  # (bgp (triple ?s :dec ?o))))))
12
12
  #
13
- # @see http://www.w3.org/TR/sparql11-query/#defn_aggSum
14
- class Sum < Operator::Unary
13
+ # @see https://www.w3.org/TR/sparql11-query/#defn_aggSum
14
+ class Sum < Operator
15
15
  include Aggregate
16
16
 
17
17
  NAME = :sum
@@ -23,6 +23,8 @@ module SPARQL; module Algebra
23
23
  # enum of evaluated operand
24
24
  # @return [RDF::Literal::Numeric] The sum of the terms
25
25
  def apply(enum)
26
+ # FIXME: we don't actually do anything with distinct
27
+ operands.shift if distinct = (operands.first == :distinct)
26
28
  if enum.empty?
27
29
  RDF::Literal(0)
28
30
  elsif enum.flatten.all? {|n| n.is_a?(RDF::Literal::Numeric)}
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
13
13
  #
14
14
  # @example empty table
15
15
  # (table unit)
16
- # @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data
16
+ # @see https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data
17
17
  class Table < Operator
18
18
  include Query
19
19
 
@@ -32,8 +32,8 @@ module SPARQL; module Algebra
32
32
  # @yieldreturn [void] ignored
33
33
  # @return [RDF::Query::Solutions]
34
34
  # the resulting solution sequence
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
  @solutions = RDF::Query::Solutions()
38
38
  Array(operands[1..-1]).each do |row|
39
39
  next unless row.is_a?(Array)
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (extend ((?x (timezone ?date)))
12
12
  # (bgp (triple ?s :date ?date)))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#func-timezone
14
+ # @see https://www.w3.org/TR/sparql11-query/#func-timezone
15
15
  class Timezone < Operator::Unary
16
16
  include Evaluatable
17
17
 
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (extend ((?x (tz ?date)))
12
12
  # (bgp (triple ?s :date ?date)))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#func-tz
14
+ # @see https://www.w3.org/TR/sparql11-query/#func-tz
15
15
  class TZ < Operator::Unary
16
16
  include Evaluatable
17
17
 
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
6
6
  # @example
7
7
  # (ucase ?x)
8
8
  #
9
- # @see http://www.w3.org/TR/sparql11-query/#func-ucase
10
- # @see http://www.w3.org/TR/xpath-functions/#func-ucase
9
+ # @see https://www.w3.org/TR/sparql11-query/#func-ucase
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-ucase
11
11
  class UCase < Operator::Unary
12
12
  include Evaluatable
13
13
 
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
10
10
  # (graph ?g
11
11
  # (bgp (triple ?s ?p ?o)))))
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 Union < Operator::Binary
15
15
  include Query
16
16
 
@@ -30,11 +30,11 @@ 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
  debug(options) {"Union"}
36
36
  @solutions = RDF::Query::Solutions(operands.inject([]) do |memo, op|
37
- solns = op.execute(queryable, options.merge(depth: options[:depth].to_i + 1))
37
+ solns = op.execute(queryable, depth: options[:depth].to_i + 1, **options)
38
38
  debug(options) {"=> (op) #{solns.inspect}"}
39
39
  memo + solns
40
40
  end)
@@ -55,13 +55,14 @@ module SPARQL; module Algebra
55
55
  end
56
56
 
57
57
  ##
58
- # Returns an optimized version of this query.
58
+ # Optimizes this query.
59
59
  #
60
60
  # Optimize operands and remove any which are empty.
61
61
  #
62
- # @return [Union, RDF::Query] `self`
63
- def optimize
64
- ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?}
62
+ # @return [self]
63
+ # @see SPARQL::Algebra::Expression#optimize!
64
+ def optimize!(**options)
65
+ ops = operands.map {|o| o.optimize(**options) }.select {|o| o.respond_to?(:empty?) && !o.empty?}
65
66
  @operands = ops
66
67
  self
67
68
  end
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # (bgp (triple ?s ?p ?o))
10
10
  # (insert ((triple ?s ?p "q")))))
11
11
  #
12
- # @see http://www.w3.org/TR/sparql11-update/#graphUpdate
12
+ # @see https://www.w3.org/TR/sparql11-update/#graphUpdate
13
13
  class Update < Operator
14
14
  include SPARQL::Algebra::Update
15
15
 
@@ -30,12 +30,12 @@ module SPARQL; module Algebra
30
30
  # If an attempt is made to perform an unsupported operation
31
31
  # @raise [IOError]
32
32
  # If `queryable` is immutable
33
- # @see http://www.w3.org/TR/sparql11-update/
34
- def execute(queryable, options = {})
33
+ # @see https://www.w3.org/TR/sparql11-update/
34
+ def execute(queryable, **options)
35
35
  debug(options) {"Update"}
36
36
  raise IOError, "queryable is not mutable" unless queryable.mutable?
37
37
  operands.each do |op|
38
- op.execute(queryable, options.merge(depth: options[:depth].to_i + 1))
38
+ op.execute(queryable, depth: options[:depth].to_i + 1, **options)
39
39
  end
40
40
  queryable
41
41
  end
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
9
9
  # @example
10
10
  # (using (:g1) (bgp (triple ?s ?p ?o)))
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 Using < Operator
14
14
  include SPARQL::Algebra::Query
15
15
 
@@ -30,10 +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, options = {}, &block)
33
+ # @see https://www.w3.org/TR/sparql11-update/
34
+ def execute(queryable, **options, &block)
35
35
  debug(options) {"Using"}
36
- Dataset.new(*operands).execute(queryable, options.merge(depth: options[:depth].to_i + 1), &block)
36
+ Dataset.new(*operands).execute(queryable, depth: options[:depth].to_i + 1, **options, &block)
37
37
  end
38
38
  end # Using
39
39
  end # Operator
@@ -14,7 +14,7 @@ module SPARQL; module Algebra
14
14
  # (extend ((?uuid (uuid)))
15
15
  # (bgp))))))
16
16
  #
17
- # @see http://www.w3.org/TR/sparql11-query/#func-uuid
17
+ # @see https://www.w3.org/TR/sparql11-query/#func-uuid
18
18
  class UUID < Operator::Nullary
19
19
  include Evaluatable
20
20
 
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (bgp (triple ?s ?p ?o))
12
12
  # (insert ((triple ?s ?p "z"))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-update/#deleteInsert
14
+ # @see https://www.w3.org/TR/sparql11-update/#deleteInsert
15
15
  class With < Operator
16
16
  include SPARQL::Algebra::Update
17
17
 
@@ -32,17 +32,17 @@ module SPARQL; module Algebra
32
32
  # Returns queryable.
33
33
  # @raise [IOError]
34
34
  # If `from` does not exist, unless the `silent` operator is present
35
- # @see http://www.w3.org/TR/sparql11-update/
36
- def execute(queryable, options = {})
35
+ # @see https://www.w3.org/TR/sparql11-update/
36
+ def execute(queryable, **options)
37
37
  debug(options) {"With: #{operand.to_sse}"}
38
38
  # Bound variable
39
39
  name = operands.shift
40
40
 
41
41
  unless queryable.has_graph?(name)
42
42
  debug(options) {"=> default data source #{name}"}
43
- load_opts = {debug: options.fetch(:debug, nil), base_uri: name}
43
+ load_opts = {logger: options.fetch(:logger, false), base_uri: name}
44
44
  debug(options) {"=> load #{name}"}
45
- queryable.load(name.to_s, load_opts)
45
+ queryable.load(name.to_s, **load_opts)
46
46
  end
47
47
 
48
48
  # Set name for RDF::Graph descendants having no graph_name to the name variable
@@ -58,12 +58,12 @@ module SPARQL; module Algebra
58
58
  query = operands.shift
59
59
 
60
60
  # Restrict query portion to this graph
61
- queryable.query(query, options.merge(depth: options[:depth].to_i + 1)) do |solution|
61
+ queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
62
62
  debug(options) {"(solution)=>#{solution.inspect}"}
63
63
 
64
64
  # Execute each operand with queryable and solution
65
65
  operands.each do |op|
66
- op.execute(queryable, solution, options.merge(depth: options[:depth].to_i + 1))
66
+ op.execute(queryable, solutions: solution, depth: options[:depth].to_i + 1, **options)
67
67
  end
68
68
  end
69
69
  end
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
11
11
  # (extend ((?x (year ?date)))
12
12
  # (bgp (triple ?s :date ?date)))))
13
13
  #
14
- # @see http://www.w3.org/TR/sparql11-query/#func-year
14
+ # @see https://www.w3.org/TR/sparql11-query/#func-year
15
15
  class Year < Operator::Unary
16
16
  include Evaluatable
17
17
 
@@ -49,8 +49,8 @@ module SPARQL; module Algebra
49
49
  # Note, results may be used with {SPARQL.serialize_results} to obtain appropriate output encoding.
50
50
  # @raise [NotImplementedError]
51
51
  # If an attempt is made to perform an unsupported operation
52
- # @see http://www.w3.org/TR/sparql11-query/#sparqlAlgebra
53
- def execute(queryable, options = {}, &block)
52
+ # @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
53
+ def execute(queryable, **options, &block)
54
54
  raise NotImplementedError, "#{self.class}#execute(#{queryable})"
55
55
  end
56
56
 
@@ -38,8 +38,8 @@ module SPARQL; module Algebra
38
38
  # Returns the dataset.
39
39
  # @raise [NotImplementedError]
40
40
  # If an attempt is made to perform an unsupported operation
41
- # @see http://www.w3.org/TR/sparql11-update/
42
- def execute(queryable, options = {}, &block)
41
+ # @see https://www.w3.org/TR/sparql11-update/
42
+ def execute(queryable, **options, &block)
43
43
  raise NotImplementedError, "#{self.class}#execute(#{queryable})"
44
44
  end
45
45
 
@@ -1,6 +1,6 @@
1
1
  module SPARQL; module Algebra
2
2
  module VERSION
3
- VERSION_FILE = File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "VERSION")
3
+ VERSION_FILE = File.expand_path("../../../../VERSION", __FILE__)
4
4
  MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chop.split(".")
5
5
 
6
6
  STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
@@ -43,7 +43,7 @@ module RDF::Queryable
43
43
  # @yieldreturn [void] ignored
44
44
  # @return [RDF::Graph]
45
45
  #
46
- # @see http://www.w3.org/Submission/CBD/
46
+ # @see https://www.w3.org/Submission/CBD/
47
47
  def concise_bounded_description(*terms, &block)
48
48
  options = terms.last.is_a?(Hash) ? terms.pop.dup : {}
49
49
 
@@ -54,11 +54,11 @@ module RDF::Queryable
54
54
 
55
55
  # Find terms not in self as a subject and recurse with their subjects
56
56
  terms.reject {|term| self.first(subject: term)}.each do |term|
57
- self.query(predicate: term) do |statement|
57
+ self.query({predicate: term}) do |statement|
58
58
  query_terms << statement.subject
59
59
  end
60
60
 
61
- self.query(object: term) do |statement|
61
+ self.query({object: term}) do |statement|
62
62
  query_terms << statement.subject
63
63
  end
64
64
  end
@@ -69,7 +69,7 @@ module RDF::Queryable
69
69
  # Don't consider term if already in graph
70
70
  terms.reject {|term| graph.first(subject: term)}.each do |term|
71
71
  # Find statements from queryiable with term as a subject
72
- self.query(subject: term) do |statement|
72
+ self.query({subject: term}) do |statement|
73
73
  yield(statement) if block_given?
74
74
  graph << statement
75
75
 
@@ -81,7 +81,7 @@ module RDF::Queryable
81
81
  RDF.predicate => statement.predicate,
82
82
  RDF.object => statement.object,
83
83
  }
84
- }).execute(self).each do |solution|
84
+ }, **{}).execute(self).each do |solution|
85
85
  # Recurse to include this subject
86
86
  recurse_opts = options.merge(non_subjects: false, graph: graph)
87
87
  self.concise_bounded_description(solution[:s], recurse_opts, &block)
@@ -1,7 +1,6 @@
1
- require 'rdf' # @see http://rubygems.org/gems/rdf
1
+ require 'rdf' # @see https://rubygems.org/gems/rdf
2
2
  require 'sparql/algebra'
3
3
  require 'json'
4
- require 'sxp'
5
4
 
6
5
  module SPARQL
7
6
  ##
@@ -21,7 +20,7 @@ module SPARQL
21
20
  #
22
21
  # The native SSE representation may be serialized to a textual representation of SSE as
23
22
  # serialized general S-Expressions (SXP).
24
- # The SXP generated closely follows that of [OpenJena ARQ](http://openjena.org/wiki/SSE), which is intended principally for
23
+ # The SXP generated closely follows that of [OpenJena ARQ](https://openjena.org/wiki/SSE), which is intended principally for
25
24
  # running the SPARQL rules. Additionally, SSE is generated for CONSTRUCT, ASK, DESCRIBE and FROM operators.
26
25
  #
27
26
  # SXP is generated by serializing the parser result as follows:
@@ -143,7 +142,108 @@ module SPARQL
143
142
  # (using (:g1 :g2)
144
143
  # (bgp (triple ?s ?p ?o)))
145
144
  # (insert ((triple ?s ?p "q"))))))
145
+ #
146
+ # SPARQL:
147
+ #
148
+ # PREFIX : <http://example.org/>
149
+ #
150
+ # SELECT * WHERE
151
+ # {
152
+ # ?s :p ?v .
153
+ # BIND (2*?v AS ?v2) .
154
+ # ?s :p1 ?v2 .
155
+ # }
156
+ #
157
+ # SXP:
158
+ #
159
+ # (prefix ((: <http://example.org/>))
160
+ # (join
161
+ # (extend ((?v2 (* 2 ?v)))
162
+ # (bgp (triple ?s :p ?v)))
163
+ # (bgp (triple ?s :p1 ?v2))))
164
+ #
165
+ # SPARQL:
166
+ #
167
+ # PREFIX : <http://bigdata.com>
168
+ # PREFIX foaf: <http://xmlns.com/foaf/0.1/>
169
+ # PREFIX dct: <http://purl.org/dc/elements/1.1/>
170
+ #
171
+ # SELECT ?age ?src WHERE {
172
+ # ?bob foaf:name "Bob" .
173
+ # <<?bob foaf:age ?age>> dct:source ?src .
174
+ # }
175
+ #
176
+ # SXP:
146
177
  #
178
+ # (prefix
179
+ # (
180
+ # (: <http://bigdata.com>)
181
+ # (foaf: <http://xmlns.com/foaf/0.1/>)
182
+ # (dct: <http://purl.org/dc/elements/1.1/>))
183
+ # (project
184
+ # (?age ?src)
185
+ # (bgp
186
+ # (triple ?bob foaf:name "Bob")
187
+ # (triple (triple ?bob foaf:age ?age) dct:source ?src)) ))
188
+ #
189
+ # SPARQL:
190
+ #
191
+ # PREFIX : <http://bigdata.com>
192
+ # PREFIX foaf: <http://xmlns.com/foaf/0.1/>
193
+ # PREFIX dct: <http://purl.org/dc/elements/1.1/>
194
+ #
195
+ # SELECT ?age ?src WHERE {
196
+ # ?bob foaf:name "Bob" .
197
+ # BIND( <<?bob foaf:age ?age>> AS ?t ) .
198
+ # ?t dct:source ?src .
199
+ # }
200
+ #
201
+ # SXP:
202
+ #
203
+ # (prefix
204
+ # (
205
+ # (: <http://bigdata.com>)
206
+ # (foaf: <http://xmlns.com/foaf/0.1/>)
207
+ # (dct: <http://purl.org/dc/elements/1.1/>))
208
+ # (project
209
+ # (?age ?src)
210
+ # (join
211
+ # (extend ((?t (triple ?bob foaf:age ?age))) (bgp (triple ?bob foaf:name "Bob")))
212
+ # (bgp (triple ?t dct:source ?src))) ))
213
+ #
214
+ # SPARQL:
215
+ #
216
+ # PREFIX : <http://bigdata.com>
217
+ # PREFIX foaf: <http://xmlns.com/foaf/0.1/>
218
+ # PREFIX dct: <http://purl.org/dc/elements/1.1/>
219
+ #
220
+ # CONSTRUCT {
221
+ # ?bob foaf:name "Bob" .
222
+ # <<?bob foaf:age ?age>> dct:creator <http://example.com/crawlers#c1>;
223
+ # dct:source ?src .
224
+ # }
225
+ # WHERE {
226
+ # ?bob foaf:name "Bob" .
227
+ # <<?bob foaf:age ?age>> dct:source ?src .
228
+ # }
229
+ #
230
+ # SXP:
231
+ #
232
+ # (prefix
233
+ # (
234
+ # (: <http://bigdata.com>)
235
+ # (foaf: <http://xmlns.com/foaf/0.1/>)
236
+ # (dct: <http://purl.org/dc/elements/1.1/>))
237
+ # (construct
238
+ # (
239
+ # (triple ?bob foaf:name "Bob")
240
+ # (triple (triple ?bob foaf:age ?age) dct:creator <http://example.com/crawlers#c1>)
241
+ # (triple (triple ?bob foaf:age ?age) dct:source ?src))
242
+ # (bgp
243
+ # (triple ?bob foaf:name "Bob")
244
+ # (triple (triple ?bob foaf:age ?age) dct:source ?src)) ))
245
+
246
+
147
247
  # ## Implementation Notes
148
248
  # The parser is driven through a rules table contained in lib/sparql/grammar/meta.rb. This includes branch rules to indicate productions to be taken based on a current production.
149
249
  #
@@ -155,7 +255,7 @@ module SPARQL
155
255
  # etc/sparql11.bnf
156
256
  #
157
257
  # @see http://www.w3.org/TR/sparql11-query/#grammar
158
- # @see http://rubygems.org/gems/ebnf
258
+ # @see https://rubygems.org/gems/ebnf
159
259
  module Grammar
160
260
  autoload :Parser, 'sparql/grammar/parser11'
161
261
  autoload :Terminals, 'sparql/grammar/terminals11'
@@ -175,8 +275,8 @@ module SPARQL
175
275
  # @param [Hash{Symbol => Object}] options
176
276
  # @return [Parser]
177
277
  # @raise [Parser::Error] on invalid input
178
- def self.parse(query, options = {}, &block)
179
- Parser.new(query, options).parse(options[:update] ? :UpdateUnit : :QueryUnit)
278
+ def self.parse(query, **options, &block)
279
+ Parser.new(query, **options).parse(options[:update] ? :UpdateUnit : :QueryUnit)
180
280
  end
181
281
 
182
282
  ##
@@ -190,8 +290,8 @@ module SPARQL
190
290
  # @yieldparam [RDF::Reader] reader
191
291
  # @yieldreturn [void] ignored
192
292
  # @raise [RDF::FormatError] if no reader found for the specified format
193
- def self.open(filename, options = {}, &block)
194
- RDF::Util::File.open_file(filename, options) do |file|
293
+ def self.open(filename, **options, &block)
294
+ RDF::Util::File.open_file(filename, **options) do |file|
195
295
  self.parse(file, options, &block)
196
296
  end
197
297
  end
@@ -206,8 +306,8 @@ module SPARQL
206
306
  # @param [String, #to_s] query
207
307
  # @param [Hash{Symbol => Object}] options
208
308
  # @return [Boolean]
209
- def self.valid?(query, options = {})
210
- Parser.new(query, options).valid?
309
+ def self.valid?(query, **options)
310
+ Parser.new(query, **options).valid?
211
311
  end
212
312
 
213
313
  ##
@@ -225,7 +325,7 @@ module SPARQL
225
325
  # @yieldparam [Lexer] lexer
226
326
  # @return [Lexer]
227
327
  # @raise [Lexer::Error] on invalid input
228
- def self.tokenize(query, options = {}, &block)
328
+ def self.tokenize(query, **options, &block)
229
329
  Lexer.tokenize(query, options, &block)
230
330
  end
231
331
  end # Grammar