sparql 3.1.2 → 3.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -12
  3. data/VERSION +1 -1
  4. data/bin/sparql +20 -11
  5. data/lib/sinatra/sparql.rb +1 -1
  6. data/lib/sparql.rb +5 -6
  7. data/lib/sparql/algebra.rb +4 -4
  8. data/lib/sparql/algebra/aggregate.rb +1 -1
  9. data/lib/sparql/algebra/evaluatable.rb +4 -4
  10. data/lib/sparql/algebra/expression.rb +46 -31
  11. data/lib/sparql/algebra/extensions.rb +52 -25
  12. data/lib/sparql/algebra/operator.rb +22 -17
  13. data/lib/sparql/algebra/operator/abs.rb +1 -1
  14. data/lib/sparql/algebra/operator/avg.rb +8 -1
  15. data/lib/sparql/algebra/operator/bgp.rb +1 -1
  16. data/lib/sparql/algebra/operator/bnode.rb +1 -1
  17. data/lib/sparql/algebra/operator/ceil.rb +1 -1
  18. data/lib/sparql/algebra/operator/compare.rb +39 -33
  19. data/lib/sparql/algebra/operator/construct.rb +2 -1
  20. data/lib/sparql/algebra/operator/contains.rb +1 -1
  21. data/lib/sparql/algebra/operator/count.rb +1 -1
  22. data/lib/sparql/algebra/operator/dataset.rb +1 -1
  23. data/lib/sparql/algebra/operator/datatype.rb +1 -1
  24. data/lib/sparql/algebra/operator/day.rb +1 -1
  25. data/lib/sparql/algebra/operator/delete.rb +2 -2
  26. data/lib/sparql/algebra/operator/delete_where.rb +1 -1
  27. data/lib/sparql/algebra/operator/divide.rb +1 -1
  28. data/lib/sparql/algebra/operator/encode_for_uri.rb +1 -1
  29. data/lib/sparql/algebra/operator/equal.rb +1 -1
  30. data/lib/sparql/algebra/operator/extend.rb +2 -12
  31. data/lib/sparql/algebra/operator/floor.rb +1 -1
  32. data/lib/sparql/algebra/operator/graph.rb +1 -1
  33. data/lib/sparql/algebra/operator/greater_than.rb +3 -2
  34. data/lib/sparql/algebra/operator/greater_than_or_equal.rb +2 -2
  35. data/lib/sparql/algebra/operator/group_concat.rb +1 -1
  36. data/lib/sparql/algebra/operator/hours.rb +1 -1
  37. data/lib/sparql/algebra/operator/insert.rb +1 -1
  38. data/lib/sparql/algebra/operator/iri.rb +1 -1
  39. data/lib/sparql/algebra/operator/is_blank.rb +1 -1
  40. data/lib/sparql/algebra/operator/is_iri.rb +1 -1
  41. data/lib/sparql/algebra/operator/is_literal.rb +1 -1
  42. data/lib/sparql/algebra/operator/is_numeric.rb +1 -1
  43. data/lib/sparql/algebra/operator/is_triple.rb +30 -0
  44. data/lib/sparql/algebra/operator/lang.rb +1 -1
  45. data/lib/sparql/algebra/operator/lang_matches.rb +1 -1
  46. data/lib/sparql/algebra/operator/lcase.rb +1 -1
  47. data/lib/sparql/algebra/operator/left_join.rb +4 -0
  48. data/lib/sparql/algebra/operator/less_than.rb +3 -2
  49. data/lib/sparql/algebra/operator/less_than_or_equal.rb +2 -2
  50. data/lib/sparql/algebra/operator/max.rb +8 -1
  51. data/lib/sparql/algebra/operator/md5.rb +1 -1
  52. data/lib/sparql/algebra/operator/min.rb +8 -1
  53. data/lib/sparql/algebra/operator/minutes.rb +1 -1
  54. data/lib/sparql/algebra/operator/month.rb +1 -1
  55. data/lib/sparql/algebra/operator/multiply.rb +1 -1
  56. data/lib/sparql/algebra/operator/negate.rb +1 -1
  57. data/lib/sparql/algebra/operator/not.rb +1 -1
  58. data/lib/sparql/algebra/operator/not_equal.rb +3 -1
  59. data/lib/sparql/algebra/operator/now.rb +1 -1
  60. data/lib/sparql/algebra/operator/object.rb +27 -0
  61. data/lib/sparql/algebra/operator/order.rb +7 -1
  62. data/lib/sparql/algebra/operator/plus.rb +1 -1
  63. data/lib/sparql/algebra/operator/predicate.rb +27 -0
  64. data/lib/sparql/algebra/operator/rand.rb +1 -1
  65. data/lib/sparql/algebra/operator/regex.rb +1 -1
  66. data/lib/sparql/algebra/operator/replace.rb +1 -1
  67. data/lib/sparql/algebra/operator/round.rb +1 -1
  68. data/lib/sparql/algebra/operator/same_term.rb +1 -1
  69. data/lib/sparql/algebra/operator/sample.rb +9 -2
  70. data/lib/sparql/algebra/operator/seconds.rb +1 -1
  71. data/lib/sparql/algebra/operator/sha1.rb +1 -1
  72. data/lib/sparql/algebra/operator/sha256.rb +1 -1
  73. data/lib/sparql/algebra/operator/sha384.rb +1 -1
  74. data/lib/sparql/algebra/operator/sha512.rb +1 -1
  75. data/lib/sparql/algebra/operator/str.rb +1 -1
  76. data/lib/sparql/algebra/operator/strafter.rb +1 -1
  77. data/lib/sparql/algebra/operator/strbefore.rb +1 -1
  78. data/lib/sparql/algebra/operator/strdt.rb +1 -1
  79. data/lib/sparql/algebra/operator/strends.rb +1 -1
  80. data/lib/sparql/algebra/operator/strlang.rb +1 -1
  81. data/lib/sparql/algebra/operator/strlen.rb +1 -1
  82. data/lib/sparql/algebra/operator/strstarts.rb +1 -1
  83. data/lib/sparql/algebra/operator/struuid.rb +1 -1
  84. data/lib/sparql/algebra/operator/subject.rb +29 -0
  85. data/lib/sparql/algebra/operator/substr.rb +1 -1
  86. data/lib/sparql/algebra/operator/subtract.rb +1 -1
  87. data/lib/sparql/algebra/operator/sum.rb +1 -1
  88. data/lib/sparql/algebra/operator/timezone.rb +1 -1
  89. data/lib/sparql/algebra/operator/triple.rb +27 -0
  90. data/lib/sparql/algebra/operator/tz.rb +1 -1
  91. data/lib/sparql/algebra/operator/ucase.rb +1 -1
  92. data/lib/sparql/algebra/operator/uuid.rb +1 -1
  93. data/lib/sparql/algebra/operator/with.rb +1 -1
  94. data/lib/sparql/algebra/operator/year.rb +1 -1
  95. data/lib/sparql/extensions.rb +6 -12
  96. data/lib/sparql/grammar.rb +2 -28
  97. data/lib/sparql/grammar/meta.rb +5739 -2365
  98. data/lib/sparql/grammar/parser11.rb +119 -59
  99. data/lib/sparql/grammar/terminals11.rb +3 -0
  100. data/lib/sparql/results.rb +17 -9
  101. metadata +31 -42
@@ -42,7 +42,7 @@ module SPARQL; module Algebra
42
42
  # @return [RDF::Literal]
43
43
  # @raise [TypeError] if any operand is unbound
44
44
  # @raise [TypeError] if any operand is not a plain literal
45
- def apply(text, pattern, replacement, flags = RDF::Literal(''))
45
+ def apply(text, pattern, replacement, flags = RDF::Literal(''), **options)
46
46
  raise TypeError, "expected a plain RDF::Literal, but got #{text.inspect}" unless text.literal? && text.plain?
47
47
  # TODO: validate text syntax
48
48
 
@@ -22,7 +22,7 @@ module SPARQL; module Algebra
22
22
  # the operand
23
23
  # @return [RDF::Literal] literal of same type
24
24
  # @raise [TypeError] if the operand is not a numeric value
25
- def apply(operand)
25
+ def apply(operand, **options)
26
26
  case operand
27
27
  when RDF::Literal::Numeric then operand.round
28
28
  else raise TypeError, "expected an RDF::Literal::Numeric, but got #{operand.inspect}"
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
26
26
  # an RDF term
27
27
  # @return [RDF::Literal::Boolean] `true` or `false`
28
28
  # @raise [TypeError] if either operand is unbound
29
- def apply(term1, term2)
29
+ def apply(term1, term2, **options)
30
30
  RDF::Literal(term1.eql?(term2))
31
31
  end
32
32
 
@@ -12,11 +12,18 @@ module SPARQL; module Algebra
12
12
  # (bgp (triple ?s :dec ?o)))))))
13
13
  #
14
14
  # @see https://www.w3.org/TR/sparql11-query/#defn_aggSample
15
- class Sample < Operator::Unary
15
+ class Sample < Operator
16
16
  include Aggregate
17
17
 
18
18
  NAME = :sample
19
19
 
20
+ def initialize(*operands, **options)
21
+ raise ArgumentError,
22
+ "sample operator accepts at most one argument with an optional :distinct" if
23
+ (operands - %i{distinct}).length != 1
24
+ super
25
+ end
26
+
20
27
  ##
21
28
  # Sample is a set function which returns an arbitrary value from the multiset passed to it.
22
29
  #
@@ -24,7 +31,7 @@ module SPARQL; module Algebra
24
31
  # enum of evaluated operand
25
32
  # @return [RDF::Term] An arbitrary term
26
33
  # @raise [TypeError] If enum is empty
27
- def apply(enum)
34
+ def apply(enum, **options)
28
35
  enum.detect(lambda {raise TypeError, "Sampling an empty multiset"}) {|e| e.first}.first
29
36
  end
30
37
  end # LCase
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
24
24
  # the operand
25
25
  # @return [RDF::Literal]
26
26
  # @raise [TypeError] if the operand is not a simple literal
27
- def apply(operand)
27
+ def apply(operand, **options)
28
28
  raise TypeError, "expected an RDF::Literal::DateTime, but got #{operand.inspect}" unless operand.is_a?(RDF::Literal::DateTime)
29
29
  RDF::Literal(operand.object.second)
30
30
  end
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
26
26
  # the operand
27
27
  # @return [RDF::Literal]
28
28
  # @raise [TypeError] if the operand is not a simple literal
29
- def apply(operand)
29
+ def apply(operand, **options)
30
30
  raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}" unless operand.literal?
31
31
  raise TypeError, "expected simple literal or xsd:string, but got #{operand.inspect}" unless (operand.datatype || RDF::XSD.string) == RDF::XSD.string
32
32
  RDF::Literal(Digest::SHA1.new.hexdigest(operand.to_s))
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
26
26
  # the operand
27
27
  # @return [RDF::Literal]
28
28
  # @raise [TypeError] if the operand is not a simple literal
29
- def apply(operand)
29
+ def apply(operand, **options)
30
30
  raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}" unless operand.literal?
31
31
  raise TypeError, "expected simple literal or xsd:string, but got #{operand.inspect}" unless (operand.datatype || RDF::XSD.string) == RDF::XSD.string
32
32
  RDF::Literal(Digest::SHA256.new.hexdigest(operand.to_s))
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
26
26
  # the operand
27
27
  # @return [RDF::Literal]
28
28
  # @raise [TypeError] if the operand is not a simple literal
29
- def apply(operand)
29
+ def apply(operand, **options)
30
30
  raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}" unless operand.literal?
31
31
  raise TypeError, "expected simple literal or xsd:string, but got #{operand.inspect}" unless (operand.datatype || RDF::XSD.string) == RDF::XSD.string
32
32
  RDF::Literal(Digest::SHA384.new.hexdigest(operand.to_s))
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
26
26
  # the operand
27
27
  # @return [RDF::Literal]
28
28
  # @raise [TypeError] if the operand is not a simple literal
29
- def apply(operand)
29
+ def apply(operand, **options)
30
30
  raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}" unless operand.literal?
31
31
  raise TypeError, "expected simple literal or xsd:string, but got #{operand.inspect}" unless (operand.datatype || RDF::XSD.string) == RDF::XSD.string
32
32
  RDF::Literal(Digest::SHA512.new.hexdigest(operand.to_s))
@@ -23,7 +23,7 @@ module SPARQL; module Algebra
23
23
  # a literal or IRI
24
24
  # @return [RDF::Literal] a simple literal
25
25
  # @raise [TypeError] if the operand is not a literal or IRI
26
- def apply(term)
26
+ def apply(term, **options)
27
27
  case term
28
28
  when RDF::Literal then RDF::Literal(term.value)
29
29
  when RDF::URI then RDF::Literal(term.to_s)
@@ -37,7 +37,7 @@ module SPARQL; module Algebra
37
37
  # a literal
38
38
  # @return [RDF::Literal]
39
39
  # @raise [TypeError] if operands are not compatible
40
- def apply(left, right)
40
+ def apply(left, right, **options)
41
41
  case
42
42
  when !left.compatible?(right)
43
43
  raise TypeError, "expected two RDF::Literal operands, but got #{left.inspect} and #{right.inspect}"
@@ -37,7 +37,7 @@ module SPARQL; module Algebra
37
37
  # a literal
38
38
  # @return [RDF::Literal]
39
39
  # @raise [TypeError] if operands are not compatible
40
- def apply(left, right)
40
+ def apply(left, right, **options)
41
41
  case
42
42
  when !left.plain? || !right.plain?
43
43
  raise TypeError, "expected two RDF::Literal operands, but got #{left.inspect} and #{right.inspect}"
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
24
24
  # datatype
25
25
  # @return [RDF::Literal] a datatyped literal
26
26
  # @see https://www.w3.org/TR/sparql11-query/#func-strdt
27
- def apply(value, datatypeIRI)
27
+ def apply(value, datatypeIRI, **options)
28
28
  raise TypeError, "Literal #{value.inspect} is not simple" unless value.simple?
29
29
  RDF::Literal.new(value.to_s, datatype: datatypeIRI)
30
30
  end
@@ -33,7 +33,7 @@ module SPARQL; module Algebra
33
33
  # a literal
34
34
  # @return [RDF::Literal::Boolean]
35
35
  # @raise [TypeError] if operands are not compatible
36
- def apply(left, right)
36
+ def apply(left, right, **options)
37
37
  case
38
38
  when !left.compatible?(right)
39
39
  raise TypeError, "expected two RDF::Literal operands, but got #{left.inspect} and #{right.inspect}"
@@ -25,7 +25,7 @@ module SPARQL; module Algebra
25
25
  # datatype
26
26
  # @return [RDF::Literal] a datatyped literal
27
27
  # @see https://www.w3.org/TR/sparql11-query/#func-strlang
28
- def apply(value, langTag)
28
+ def apply(value, langTag, **options)
29
29
  raise TypeError, "Literal #{value.inspect} is not simple" unless value.simple?
30
30
  RDF::Literal.new(value.to_s, language: langTag.to_s)
31
31
  end
@@ -25,7 +25,7 @@ module SPARQL; module Algebra
25
25
  # the operand
26
26
  # @return [RDF::Literal::Integer] length of string
27
27
  # @raise [TypeError] if the operand is not a numeric value
28
- def apply(operand)
28
+ def apply(operand, **options)
29
29
  raise TypeError, "expected a plain RDF::Literal, but got #{operand.inspect}" unless operand.literal? && operand.plain?
30
30
  RDF::Literal(operand.to_s.length)
31
31
  end
@@ -33,7 +33,7 @@ module SPARQL; module Algebra
33
33
  # a literal
34
34
  # @return [RDF::Literal::Boolean]
35
35
  # @raise [TypeError] if operands are not compatible
36
- def apply(left, right)
36
+ def apply(left, right, **options)
37
37
  case
38
38
  when !left.compatible?(right)
39
39
  raise TypeError, "expected two RDF::Literal operands, but got #{left.inspect} and #{right.inspect}"
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
24
24
  # Return a string that is the scheme specific part of UUID. That is, as a simple literal, the result of generating a UUID, converting to a simple literal and removing the initial urn:uuid:.
25
25
  #
26
26
  # @return [RDF::URI]
27
- def apply
27
+ def apply(**options)
28
28
  RDF::Literal(SecureRandom.uuid)
29
29
  end
30
30
  end # StrUUID
@@ -0,0 +1,29 @@
1
+ module SPARQL; module Algebra
2
+ class Operator
3
+ ##
4
+ # The SPARQL `SUBJECT` operator.
5
+ #
6
+ # Returns the subject part of `arg` as a term.
7
+ #
8
+ # If triple is an RDF-star triple, the function returns the subject of this triple. Passing anything other than an RDF-star triple is an error.
9
+ #
10
+ # @see https://w3c.github.io/rdf-star/rdf-star-cg-spec.html#subject
11
+ class Subject < Operator::Unary
12
+ include Evaluatable
13
+
14
+ NAME = :subject
15
+
16
+ ##
17
+ # Returns the subject part of arg.
18
+ #
19
+ # @param [RDF::Statement] operand
20
+ # the operand
21
+ # @return [RDF::Literal]
22
+ # @raise [TypeError] if the operand is not a statement
23
+ def apply(operand, **options)
24
+ raise TypeError, "expected an RDF::Statement, but got #{operand.inspect}" unless operand.is_a?(RDF::Statement)
25
+ operand.subject
26
+ end
27
+ end # Subject
28
+ end # Operator
29
+ end; end # SPARQL::Algebra
@@ -49,7 +49,7 @@ module SPARQL; module Algebra
49
49
  # an optional length of the substring.
50
50
  # @return [RDF::Literal]
51
51
  # @raise [TypeError] if operands are not compatible
52
- def apply(source, startingLoc, length)
52
+ def apply(source, startingLoc, length, **options)
53
53
  raise TypeError, "expected a plain RDF::Literal, but got #{source.inspect}" unless source.literal? && source.plain?
54
54
  text = text.to_s
55
55
 
@@ -20,7 +20,7 @@ module SPARQL; module Algebra
20
20
  # a numeric literal
21
21
  # @return [RDF::Literal::Numeric]
22
22
  # @raise [TypeError] if either operand is not a numeric literal
23
- def apply(left, right)
23
+ def apply(left, right, **options)
24
24
  case
25
25
  when left.is_a?(RDF::Literal::Numeric) && right.is_a?(RDF::Literal::Numeric)
26
26
  left - right
@@ -22,7 +22,7 @@ module SPARQL; module Algebra
22
22
  # @param [Enumerable<Array<RDF::Term>>] enum
23
23
  # enum of evaluated operand
24
24
  # @return [RDF::Literal::Numeric] The sum of the terms
25
- def apply(enum)
25
+ def apply(enum, **options)
26
26
  # FIXME: we don't actually do anything with distinct
27
27
  operands.shift if distinct = (operands.first == :distinct)
28
28
  if enum.empty?
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
26
26
  # the operand
27
27
  # @return [RDF::Literal]
28
28
  # @raise [TypeError] if the operand is not a simple literal
29
- def apply(operand)
29
+ def apply(operand, **options)
30
30
  raise TypeError, "expected an RDF::Literal::DateTime, but got #{operand.inspect}" unless operand.is_a?(RDF::Literal::DateTime)
31
31
  raise TypeError, "literal has no timezone" unless res = operand.timezone
32
32
  res
@@ -0,0 +1,27 @@
1
+ module SPARQL; module Algebra
2
+ class Operator
3
+ ##
4
+ # The SPARQL `triple` operator.
5
+ #
6
+ # If the 3-tuple (term1, term2, term3) is an RDF-star triple, the function returns this triple. If the 3-tuple is not an RDF-star triple, then the function raises an error.
7
+ #
8
+ # @see https://w3c.github.io/rdf-star/rdf-star-cg-spec.html#triple
9
+ class Triple < Operator::Ternary
10
+ include Evaluatable
11
+
12
+ NAME = :triple
13
+
14
+ ##
15
+ # @param [RDF::Term] subject
16
+ # @param [RDF::Term] predicate
17
+ # @param [RDF::Term] object
18
+ # @return [RDF::URI]
19
+ # @raise [TypeError] if the operand is not a simple literal
20
+ def apply(subject, predicate, object, **options)
21
+ triple = RDF::Statement(subject, predicate, object)
22
+ raise TypeError, "valid components, but got #{triple.inspect}" unless triple.valid?
23
+ triple
24
+ end
25
+ end # Triple
26
+ end # Operator
27
+ end; end # SPARQL::Algebra
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
24
24
  # the operand
25
25
  # @return [RDF::Literal]
26
26
  # @raise [TypeError] if the operand is not a simple literal
27
- def apply(operand)
27
+ def apply(operand, **options)
28
28
  raise TypeError, "expected an RDF::Literal::DateTime, but got #{operand.inspect}" unless operand.is_a?(RDF::Literal::DateTime)
29
29
  operand.tz
30
30
  end
@@ -20,7 +20,7 @@ module SPARQL; module Algebra
20
20
  # the operand
21
21
  # @return [RDF::Literal] literal of same type
22
22
  # @raise [TypeError] if the operand is not a literal value
23
- def apply(operand)
23
+ def apply(operand, **options)
24
24
  case operand
25
25
  when RDF::Literal then RDF::Literal(operand.to_s.upcase, datatype: operand.datatype, language: operand.language)
26
26
  else raise TypeError, "expected an RDF::Literal::Numeric, but got #{operand.inspect}"
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
24
24
  # Return a fresh IRI from the UUID URN scheme. Each call of UUID() returns a different UUID. It must not be the "nil" UUID (all zeroes). The variant and version of the UUID is implementation dependent.
25
25
  #
26
26
  # @return [RDF::URI]
27
- def apply
27
+ def apply(**options)
28
28
  RDF::URI("urn:uuid:#{SecureRandom.uuid}")
29
29
  end
30
30
  end # UUID
@@ -40,7 +40,7 @@ module SPARQL; module Algebra
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
45
  queryable.load(name.to_s, **load_opts)
46
46
  end
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
24
24
  # the operand
25
25
  # @return [RDF::Literal]
26
26
  # @raise [TypeError] if the operand is not a simple literal
27
- def apply(operand)
27
+ def apply(operand, **options)
28
28
  raise TypeError, "expected an RDF::Literal::DateTime, but got #{operand.inspect}" unless operand.is_a?(RDF::Literal::DateTime)
29
29
  RDF::Literal(operand.object.year)
30
30
  end
@@ -25,11 +25,7 @@ module RDF::Queryable
25
25
  #
26
26
  # Used to implement the SPARQL `DESCRIBE` operator.
27
27
  #
28
- # @overload concise_bounded_description(*terms, &block)
29
- # @param [Array<RDF::Term>] terms
30
- # List of terms to include in the results.
31
- #
32
- # @overload concise_bounded_description(*terms, options, &block)
28
+ # @overload concise_bounded_description(*terms, **options, &block)
33
29
  # @param [Array<RDF::Term>] terms
34
30
  # List of terms to include in the results.
35
31
  # @param [Hash{Symbol => Object}] options
@@ -44,16 +40,14 @@ module RDF::Queryable
44
40
  # @return [RDF::Graph]
45
41
  #
46
42
  # @see https://www.w3.org/Submission/CBD/
47
- def concise_bounded_description(*terms, &block)
48
- options = terms.last.is_a?(Hash) ? terms.pop.dup : {}
49
-
43
+ def concise_bounded_description(*terms, **options, &block)
50
44
  graph = options[:graph] || RDF::Graph.new
51
45
 
52
46
  if options[:non_subjects]
53
47
  query_terms = terms.dup
54
48
 
55
49
  # Find terms not in self as a subject and recurse with their subjects
56
- terms.reject {|term| self.first(subject: term)}.each do |term|
50
+ terms.reject {|term| self.first({subject: term})}.each do |term|
57
51
  self.query({predicate: term}) do |statement|
58
52
  query_terms << statement.subject
59
53
  end
@@ -67,7 +61,7 @@ module RDF::Queryable
67
61
  end
68
62
 
69
63
  # Don't consider term if already in graph
70
- terms.reject {|term| graph.first(subject: term)}.each do |term|
64
+ terms.reject {|term| graph.first({subject: term})}.each do |term|
71
65
  # Find statements from queryiable with term as a subject
72
66
  self.query({subject: term}) do |statement|
73
67
  yield(statement) if block_given?
@@ -84,13 +78,13 @@ module RDF::Queryable
84
78
  }, **{}).execute(self).each do |solution|
85
79
  # Recurse to include this subject
86
80
  recurse_opts = options.merge(non_subjects: false, graph: graph)
87
- self.concise_bounded_description(solution[:s], recurse_opts, &block)
81
+ self.concise_bounded_description(solution[:s], **recurse_opts, &block)
88
82
  end
89
83
 
90
84
  # Recurse if object is a BNode and it is not already in subjects
91
85
  if statement.object.node?
92
86
  recurse_opts = options.merge(non_subjects: false, graph: graph)
93
- self.concise_bounded_description(statement.object, recurse_opts, &block)
87
+ self.concise_bounded_description(statement.object, **recurse_opts, &block)
94
88
  end
95
89
  end
96
90
  end
@@ -1,7 +1,6 @@
1
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
  ##
@@ -193,31 +192,6 @@ module SPARQL
193
192
  # PREFIX foaf: <http://xmlns.com/foaf/0.1/>
194
193
  # PREFIX dct: <http://purl.org/dc/elements/1.1/>
195
194
  #
196
- # SELECT ?age ?src WHERE {
197
- # ?bob foaf:name "Bob" .
198
- # BIND( <<?bob foaf:age ?age>> AS ?t ) .
199
- # ?t dct:source ?src .
200
- # }
201
- #
202
- # SXP:
203
- #
204
- # (prefix
205
- # (
206
- # (: <http://bigdata.com>)
207
- # (foaf: <http://xmlns.com/foaf/0.1/>)
208
- # (dct: <http://purl.org/dc/elements/1.1/>))
209
- # (project
210
- # (?age ?src)
211
- # (join
212
- # (extend ((?t (triple ?bob foaf:age ?age))) (bgp (triple ?bob foaf:name "Bob")))
213
- # (bgp (triple ?t dct:source ?src))) ))
214
- #
215
- # SPARQL:
216
- #
217
- # PREFIX : <http://bigdata.com>
218
- # PREFIX foaf: <http://xmlns.com/foaf/0.1/>
219
- # PREFIX dct: <http://purl.org/dc/elements/1.1/>
220
- #
221
195
  # CONSTRUCT {
222
196
  # ?bob foaf:name "Bob" .
223
197
  # <<?bob foaf:age ?age>> dct:creator <http://example.com/crawlers#c1>;
@@ -293,7 +267,7 @@ module SPARQL
293
267
  # @raise [RDF::FormatError] if no reader found for the specified format
294
268
  def self.open(filename, **options, &block)
295
269
  RDF::Util::File.open_file(filename, **options) do |file|
296
- self.parse(file, options, &block)
270
+ self.parse(file, **options, &block)
297
271
  end
298
272
  end
299
273
 
@@ -327,7 +301,7 @@ module SPARQL
327
301
  # @return [Lexer]
328
302
  # @raise [Lexer::Error] on invalid input
329
303
  def self.tokenize(query, **options, &block)
330
- Lexer.tokenize(query, options, &block)
304
+ Lexer.tokenize(query, **options, &block)
331
305
  end
332
306
  end # Grammar
333
307
  end # SPARQL