sparql 3.1.8 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -22
  3. data/VERSION +1 -1
  4. data/bin/sparql +13 -4
  5. data/lib/sparql/algebra/extensions.rb +93 -33
  6. data/lib/sparql/algebra/operator/abs.rb +22 -2
  7. data/lib/sparql/algebra/operator/add.rb +21 -2
  8. data/lib/sparql/algebra/operator/alt.rb +26 -2
  9. data/lib/sparql/algebra/operator/and.rb +25 -3
  10. data/lib/sparql/algebra/operator/asc.rb +20 -1
  11. data/lib/sparql/algebra/operator/ask.rb +17 -1
  12. data/lib/sparql/algebra/operator/avg.rb +17 -1
  13. data/lib/sparql/algebra/operator/base.rb +18 -1
  14. data/lib/sparql/algebra/operator/bgp.rb +5 -1
  15. data/lib/sparql/algebra/operator/bnode.rb +33 -10
  16. data/lib/sparql/algebra/operator/bound.rb +22 -1
  17. data/lib/sparql/algebra/operator/ceil.rb +25 -2
  18. data/lib/sparql/algebra/operator/clear.rb +16 -2
  19. data/lib/sparql/algebra/operator/coalesce.rb +33 -11
  20. data/lib/sparql/algebra/operator/compare.rb +9 -0
  21. data/lib/sparql/algebra/operator/concat.rb +26 -2
  22. data/lib/sparql/algebra/operator/construct.rb +29 -6
  23. data/lib/sparql/algebra/operator/contains.rb +24 -2
  24. data/lib/sparql/algebra/operator/copy.rb +19 -2
  25. data/lib/sparql/algebra/operator/count.rb +17 -1
  26. data/lib/sparql/algebra/operator/create.rb +19 -2
  27. data/lib/sparql/algebra/operator/dataset.rb +17 -0
  28. data/lib/sparql/algebra/operator/datatype.rb +25 -6
  29. data/lib/sparql/algebra/operator/day.rb +23 -5
  30. data/lib/sparql/algebra/operator/delete.rb +27 -2
  31. data/lib/sparql/algebra/operator/delete_data.rb +23 -2
  32. data/lib/sparql/algebra/operator/delete_where.rb +24 -2
  33. data/lib/sparql/algebra/operator/desc.rb +20 -1
  34. data/lib/sparql/algebra/operator/describe.rb +27 -4
  35. data/lib/sparql/algebra/operator/distinct.rb +18 -1
  36. data/lib/sparql/algebra/operator/divide.rb +26 -2
  37. data/lib/sparql/algebra/operator/drop.rb +17 -2
  38. data/lib/sparql/algebra/operator/encode_for_uri.rb +24 -2
  39. data/lib/sparql/algebra/operator/equal.rb +12 -2
  40. data/lib/sparql/algebra/operator/exists.rb +28 -4
  41. data/lib/sparql/algebra/operator/exprlist.rb +12 -1
  42. data/lib/sparql/algebra/operator/extend.rb +31 -6
  43. data/lib/sparql/algebra/operator/filter.rb +27 -5
  44. data/lib/sparql/algebra/operator/floor.rb +25 -2
  45. data/lib/sparql/algebra/operator/graph.rb +13 -0
  46. data/lib/sparql/algebra/operator/greater_than.rb +12 -3
  47. data/lib/sparql/algebra/operator/greater_than_or_equal.rb +12 -2
  48. data/lib/sparql/algebra/operator/group.rb +34 -8
  49. data/lib/sparql/algebra/operator/group_concat.rb +19 -7
  50. data/lib/sparql/algebra/operator/hours.rb +23 -5
  51. data/lib/sparql/algebra/operator/if.rb +21 -4
  52. data/lib/sparql/algebra/operator/in.rb +18 -1
  53. data/lib/sparql/algebra/operator/insert.rb +22 -2
  54. data/lib/sparql/algebra/operator/insert_data.rb +23 -2
  55. data/lib/sparql/algebra/operator/iri.rb +21 -4
  56. data/lib/sparql/algebra/operator/is_blank.rb +19 -1
  57. data/lib/sparql/algebra/operator/is_iri.rb +19 -1
  58. data/lib/sparql/algebra/operator/is_literal.rb +19 -1
  59. data/lib/sparql/algebra/operator/is_numeric.rb +21 -3
  60. data/lib/sparql/algebra/operator/is_triple.rb +32 -0
  61. data/lib/sparql/algebra/operator/join.rb +22 -1
  62. data/lib/sparql/algebra/operator/lang.rb +25 -0
  63. data/lib/sparql/algebra/operator/lang_matches.rb +22 -1
  64. data/lib/sparql/algebra/operator/lcase.rb +23 -2
  65. data/lib/sparql/algebra/operator/left_join.rb +29 -1
  66. data/lib/sparql/algebra/operator/less_than.rb +12 -3
  67. data/lib/sparql/algebra/operator/less_than_or_equal.rb +12 -2
  68. data/lib/sparql/algebra/operator/load.rb +25 -2
  69. data/lib/sparql/algebra/operator/max.rb +17 -1
  70. data/lib/sparql/algebra/operator/md5.rb +22 -5
  71. data/lib/sparql/algebra/operator/min.rb +18 -2
  72. data/lib/sparql/algebra/operator/minus.rb +25 -7
  73. data/lib/sparql/algebra/operator/minutes.rb +23 -5
  74. data/lib/sparql/algebra/operator/modify.rb +41 -5
  75. data/lib/sparql/algebra/operator/month.rb +23 -5
  76. data/lib/sparql/algebra/operator/move.rb +20 -2
  77. data/lib/sparql/algebra/operator/multiply.rb +26 -3
  78. data/lib/sparql/algebra/operator/negate.rb +23 -3
  79. data/lib/sparql/algebra/operator/not.rb +24 -3
  80. data/lib/sparql/algebra/operator/not_equal.rb +13 -0
  81. data/lib/sparql/algebra/operator/notexists.rb +30 -6
  82. data/lib/sparql/algebra/operator/notin.rb +20 -3
  83. data/lib/sparql/algebra/operator/notoneof.rb +12 -2
  84. data/lib/sparql/algebra/operator/now.rb +24 -5
  85. data/lib/sparql/algebra/operator/object.rb +32 -0
  86. data/lib/sparql/algebra/operator/or.rb +26 -3
  87. data/lib/sparql/algebra/operator/order.rb +20 -1
  88. data/lib/sparql/algebra/operator/path.rb +29 -2
  89. data/lib/sparql/algebra/operator/path_opt.rb +21 -2
  90. data/lib/sparql/algebra/operator/path_plus.rb +21 -2
  91. data/lib/sparql/algebra/operator/path_star.rb +20 -2
  92. data/lib/sparql/algebra/operator/plus.rb +42 -3
  93. data/lib/sparql/algebra/operator/predicate.rb +32 -0
  94. data/lib/sparql/algebra/operator/prefix.rb +24 -3
  95. data/lib/sparql/algebra/operator/project.rb +51 -5
  96. data/lib/sparql/algebra/operator/rand.rb +30 -2
  97. data/lib/sparql/algebra/operator/reduced.rb +18 -1
  98. data/lib/sparql/algebra/operator/regex.rb +26 -18
  99. data/lib/sparql/algebra/operator/replace.rb +26 -6
  100. data/lib/sparql/algebra/operator/reverse.rb +20 -2
  101. data/lib/sparql/algebra/operator/round.rb +25 -2
  102. data/lib/sparql/algebra/operator/same_term.rb +24 -6
  103. data/lib/sparql/algebra/operator/sample.rb +30 -8
  104. data/lib/sparql/algebra/operator/seconds.rb +23 -5
  105. data/lib/sparql/algebra/operator/seq.rb +20 -2
  106. data/lib/sparql/algebra/operator/sequence.rb +0 -10
  107. data/lib/sparql/algebra/operator/sha1.rb +18 -1
  108. data/lib/sparql/algebra/operator/sha256.rb +18 -1
  109. data/lib/sparql/algebra/operator/sha384.rb +18 -1
  110. data/lib/sparql/algebra/operator/sha512.rb +18 -1
  111. data/lib/sparql/algebra/operator/slice.rb +27 -5
  112. data/lib/sparql/algebra/operator/str.rb +21 -1
  113. data/lib/sparql/algebra/operator/strafter.rb +25 -2
  114. data/lib/sparql/algebra/operator/strbefore.rb +25 -2
  115. data/lib/sparql/algebra/operator/strdt.rb +22 -1
  116. data/lib/sparql/algebra/operator/strends.rb +25 -3
  117. data/lib/sparql/algebra/operator/strlang.rb +25 -6
  118. data/lib/sparql/algebra/operator/strlen.rb +23 -2
  119. data/lib/sparql/algebra/operator/strstarts.rb +25 -2
  120. data/lib/sparql/algebra/operator/struuid.rb +29 -9
  121. data/lib/sparql/algebra/operator/subject.rb +32 -0
  122. data/lib/sparql/algebra/operator/substr.rb +23 -2
  123. data/lib/sparql/algebra/operator/subtract.rb +28 -2
  124. data/lib/sparql/algebra/operator/sum.rb +17 -1
  125. data/lib/sparql/algebra/operator/table.rb +42 -4
  126. data/lib/sparql/algebra/operator/timezone.rb +23 -5
  127. data/lib/sparql/algebra/operator/tz.rb +22 -5
  128. data/lib/sparql/algebra/operator/ucase.rb +23 -2
  129. data/lib/sparql/algebra/operator/union.rb +29 -6
  130. data/lib/sparql/algebra/operator/update.rb +25 -4
  131. data/lib/sparql/algebra/operator/using.rb +32 -2
  132. data/lib/sparql/algebra/operator/uuid.rb +27 -8
  133. data/lib/sparql/algebra/operator/with.rb +38 -4
  134. data/lib/sparql/algebra/operator/year.rb +23 -5
  135. data/lib/sparql/algebra/operator.rb +99 -6
  136. data/lib/sparql/algebra/sxp_extensions.rb +3 -3
  137. data/lib/sparql/grammar/parser11.rb +4 -4
  138. metadata +22 -35
  139. data/lib/sparql/algebra/operator/triple.rb +0 -27
@@ -3,11 +3,20 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL logical `hours` operator.
5
5
  #
6
- # @example
7
- # (prefix ((: <http://example.org/>))
8
- # (project (?s ?x)
9
- # (extend ((?x (hours ?date)))
10
- # (bgp (triple ?s :date ?date)))))
6
+ # [121] BuiltInCall ::= ... | 'HOURS' '(' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example.org/>
10
+ # SELECT ?s (HOURS(?date) AS ?x) WHERE {
11
+ # ?s :date ?date
12
+ # }
13
+ #
14
+ # @example SSE
15
+ # (prefix
16
+ # ((: <http://example.org/>))
17
+ # (project (?s ?x)
18
+ # (extend ((?x (hours ?date)))
19
+ # (bgp (triple ?s :date ?date)))))
11
20
  #
12
21
  # @see https://www.w3.org/TR/sparql11-query/#func-hours
13
22
  class Hours < Operator::Unary
@@ -26,6 +35,15 @@ module SPARQL; module Algebra
26
35
  raise TypeError, "expected an RDF::Literal::DateTime, but got #{operand.inspect}" unless operand.is_a?(RDF::Literal::DateTime)
27
36
  RDF::Literal(operand.object.hour)
28
37
  end
38
+
39
+ ##
40
+ #
41
+ # Returns a partial SPARQL grammar for this operator.
42
+ #
43
+ # @return [String]
44
+ def to_sparql(**options)
45
+ "HOURS(#{operands.last.to_sparql(**options)})"
46
+ end
29
47
  end # Hours
30
48
  end # Operator
31
49
  end; end # SPARQL::Algebra
@@ -3,7 +3,15 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `if` function.
5
5
  #
6
- # @example
6
+ # [121] BuiltInCall ::= ... | 'IF' '(' Expression ',' Expression ',' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # BASE <http://example.org/>
10
+ # PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
11
+ # SELECT ?o (IF(lang(?o) = "ja", true, false) AS ?integer)
12
+ # WHERE { ?s ?p ?o }
13
+ #
14
+ # @example SSE
7
15
  # (base <http://example.org/>
8
16
  # (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>))
9
17
  # (project (?o ?integer)
@@ -37,9 +45,18 @@ module SPARQL; module Algebra
37
45
  operand(0).evaluate(bindings, depth: options[:depth].to_i + 1, **options) == RDF::Literal::TRUE ?
38
46
  operand(1).evaluate(bindings, depth: options[:depth].to_i + 1, **options) :
39
47
  operand(2).evaluate(bindings, depth: options[:depth].to_i + 1, **options)
40
- rescue
41
- raise TypeError
48
+ rescue
49
+ raise TypeError
42
50
  end
43
51
  end # If
44
- end # Operator
52
+
53
+ ##
54
+ #
55
+ # Returns a partial SPARQL grammar for this operator.
56
+ #
57
+ # @return [String]
58
+ def to_sparql(**options)
59
+ "IF(" + operands.to_sparql(delimiter: ', ', **options) + ")"
60
+ end
61
+ end # If
45
62
  end; end # SPARQL::Algebra
@@ -3,7 +3,12 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL GraphPattern `in` operator.
5
5
  #
6
- # @example
6
+ # [114] RelationalExpression ::= NumericExpression ('IN' ExpressionList)?
7
+ #
8
+ # @example SPARQL Grammar
9
+ # ASK { FILTER(2 IN (1, 2, 3)) }
10
+ #
11
+ # @example SSE
7
12
  # (ask (filter (in 2 1 2 3) (bgp)))
8
13
  #
9
14
  # @see https://www.w3.org/TR/sparql11-query/#func-in
@@ -54,6 +59,18 @@ module SPARQL; module Algebra
54
59
  else RDF::Literal::FALSE
55
60
  end
56
61
  end
62
+
63
+ ##
64
+ #
65
+ # Returns a partial SPARQL grammar for this operator.
66
+ #
67
+ # @return [String]
68
+ def to_sparql(**options)
69
+ "(" + operands.first.to_sparql(**options) +
70
+ " IN (" +
71
+ operands[1..-1].map {|e| e.to_sparql(**options)}.join(", ") +
72
+ "))"
73
+ end
57
74
  end # In
58
75
  end # Operator
59
76
  end; end # SPARQL::Algebra
@@ -6,8 +6,19 @@ module SPARQL; module Algebra
6
6
  #
7
7
  # The INSERT operation is a form of the DELETE/INSERT operation having no DELETE section
8
8
  #
9
- # @example
10
- # (insert ((triple ?s ?p "q")))
9
+ # [43] InsertClause ::= 'INSERT' QuadPattern
10
+ #
11
+ # @example SPARQL Grammar
12
+ # PREFIX : <http://example.org/>
13
+ # INSERT { ?s ?p "q" }
14
+ # WHERE { ?s ?p ?o }
15
+ #
16
+ # @example SSE
17
+ # (prefix
18
+ # ((: <http://example.org/>))
19
+ # (update
20
+ # (modify (bgp (triple ?s ?p ?o))
21
+ # (insert ((triple ?s ?p "q"))))))
11
22
  #
12
23
  # @see https://www.w3.org/TR/sparql11-update/#insert
13
24
  class Insert < Operator::Unary
@@ -51,6 +62,15 @@ module SPARQL; module Algebra
51
62
  end
52
63
  queryable
53
64
  end
65
+
66
+ ##
67
+ #
68
+ # Returns a partial SPARQL grammar for this term.
69
+ #
70
+ # @return [String]
71
+ def to_sparql(**options)
72
+ "INSERT {\n" + operands.first.to_sparql(as_statement: true, **options) + "\n}"
73
+ end
54
74
  end # Insert
55
75
  end # Operator
56
76
  end; end # SPARQL::Algebra
@@ -6,8 +6,18 @@ module SPARQL; module Algebra
6
6
  #
7
7
  # The INSERT DATA operation adds some triples, given inline in the request, into the Graph Store
8
8
  #
9
- # @example
10
- # (insertData ((graph <http://example.org/g1> ((triple :s :p :o)))))
9
+ # [38] InsertData ::= 'INSERT DATA' QuadData
10
+ #
11
+ # @example SPARQL Grammar
12
+ # PREFIX : <http://example.org/ns#>
13
+ # INSERT DATA { GRAPH <http://example.org/g1> { :s :p :o } }
14
+ #
15
+ # @example SSE
16
+ # (prefix
17
+ # ((: <http://example.org/ns#>))
18
+ # (update
19
+ # (insertData (
20
+ # (graph <http://example.org/g1> ((triple :s :p :o)))))))
11
21
  #
12
22
  # @see https://www.w3.org/TR/sparql11-update/#insertData
13
23
  class InsertData < Operator::Unary
@@ -36,6 +46,17 @@ module SPARQL; module Algebra
36
46
  end
37
47
  queryable
38
48
  end
49
+
50
+ ##
51
+ #
52
+ # Returns a partial SPARQL grammar for this term.
53
+ #
54
+ # @return [String]
55
+ def to_sparql(**options)
56
+ "INSERT DATA {\n" +
57
+ operands.first.to_sparql(as_statement: true, top_level: false, delimiter: "\n", **options) +
58
+ "\n}"
59
+ end
39
60
  end # InsertData
40
61
  end # Operator
41
62
  end; end # SPARQL::Algebra
@@ -3,10 +3,18 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `iri` operator.
5
5
  #
6
- # @example
7
- # (base <http://example.org/> (project (?uri ?iri)
8
- # (extend ((?uri (uri "uri")) (?iri (iri "iri")))
9
- # (bgp))))
6
+ # [121] BuiltInCall ::= ... | 'IRI' '(' Expression ')' | 'URI' '(' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # BASE <http://example.org/>
10
+ # SELECT (URI("uri") AS ?uri) (IRI("iri") AS ?iri)
11
+ # WHERE {}
12
+ #
13
+ # @example SSE
14
+ # (base <http://example.org/>
15
+ # (project (?uri ?iri)
16
+ # (extend ((?uri (iri "uri")) (?iri (iri "iri")))
17
+ # (bgp))))
10
18
  #
11
19
  # @see https://www.w3.org/TR/sparql11-query/#func-iri
12
20
  class IRI < Operator::Unary
@@ -35,6 +43,15 @@ module SPARQL; module Algebra
35
43
  base.join(literal.to_s)
36
44
  end
37
45
 
46
+ ##
47
+ #
48
+ # Returns a partial SPARQL grammar for this operator.
49
+ #
50
+ # @return [String]
51
+ def to_sparql(**options)
52
+ "IRI(" + operands.last.to_sparql(**options) + ")"
53
+ end
54
+
38
55
  Operator::URI = IRI
39
56
  end # IRI
40
57
  end # Operator
@@ -3,7 +3,16 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `isBlank` operator.
5
5
  #
6
- # @example
6
+ # [121] BuiltInCall ::= ... | 'isBlank' '(' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example.org/things#>
10
+ # SELECT ?x ?v WHERE {
11
+ # ?x :p ?v .
12
+ # FILTER isBlank(?v) .
13
+ # }
14
+ #
15
+ # @example SSE
7
16
  # (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
8
17
  # (: <http://example.org/things#>))
9
18
  # (project (?x ?v)
@@ -30,6 +39,15 @@ module SPARQL; module Algebra
30
39
  else raise TypeError, "expected an RDF::Term, but got #{term.inspect}"
31
40
  end
32
41
  end
42
+
43
+ ##
44
+ #
45
+ # Returns a partial SPARQL grammar for this operator.
46
+ #
47
+ # @return [String]
48
+ def to_sparql(**options)
49
+ "isBlank(" + operands.first.to_sparql(**options) + ")"
50
+ end
33
51
  end # IsBlank
34
52
  end # Operator
35
53
  end; end # SPARQL::Algebra
@@ -3,7 +3,16 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `isIRI`/`isURI` operator.
5
5
  #
6
- # @example
6
+ # [121] BuiltInCall ::= ... | 'isIRI' '(' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example.org/things#>
10
+ # SELECT ?x ?v WHERE {
11
+ # ?x :p ?v .
12
+ # FILTER isIRI(?v) .
13
+ # }
14
+ #
15
+ # @example SSE
7
16
  # (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
8
17
  # (: <http://example.org/things#>))
9
18
  # (project (?x ?v)
@@ -32,6 +41,15 @@ module SPARQL; module Algebra
32
41
  end
33
42
 
34
43
  Operator::IsURI = IsIRI
44
+
45
+ ##
46
+ #
47
+ # Returns a partial SPARQL grammar for this operator.
48
+ #
49
+ # @return [String]
50
+ def to_sparql(**options)
51
+ "isIRI(" + operands.first.to_sparql(**options) + ")"
52
+ end
35
53
  end # IsIRI
36
54
  end # Operator
37
55
  end; end # SPARQL::Algebra
@@ -3,7 +3,16 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `isLiteral` operator.
5
5
  #
6
- # @example
6
+ # [121] BuiltInCall ::= ... | 'isLiteral' '(' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example.org/things#>
10
+ # SELECT ?x ?v WHERE {
11
+ # ?x :p ?v .
12
+ # FILTER isLiteral(?v) .
13
+ # }
14
+ #
15
+ # @example SSE
7
16
  # (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
8
17
  # (: <http://example.org/things#>))
9
18
  # (project (?x ?v)
@@ -31,6 +40,15 @@ module SPARQL; module Algebra
31
40
  else raise TypeError, "expected an RDF::Term, but got #{term.inspect}"
32
41
  end
33
42
  end
43
+
44
+ ##
45
+ #
46
+ # Returns a partial SPARQL grammar for this operator.
47
+ #
48
+ # @return [String]
49
+ def to_sparql(**options)
50
+ "isLiteral(" + operands.first.to_sparql(**options) + ")"
51
+ end
34
52
  end # IsLiteral
35
53
  end # Operator
36
54
  end; end # SPARQL::Algebra
@@ -3,9 +3,18 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `isNumeric` operator.
5
5
  #
6
- # Note numeric denotes typed literals with datatypes xsd:integer, xsd:decimal, xsd:float, and xsd:double, not derived types.
6
+ # Note numeric denotes typed literals with datatypes `xsd:integer`, `xsd:decimal`, `xsd:float`, and `xsd:double`, not derived types.
7
7
  #
8
- # @example
8
+ # [121] BuiltInCall ::= ... | 'isNumeric' '(' Expression ')'
9
+ #
10
+ # @example SPARQL Grammar
11
+ # PREFIX : <http://example.org/things#>
12
+ # SELECT ?x ?v WHERE {
13
+ # ?x :p ?v .
14
+ # FILTER isNumeric(?v) .
15
+ # }
16
+ #
17
+ # @example SSE
9
18
  # (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
10
19
  # (: <http://example.org/things#>))
11
20
  # (project (?x ?v)
@@ -16,7 +25,7 @@ module SPARQL; module Algebra
16
25
  class IsNumeric < Operator::Unary
17
26
  include Evaluatable
18
27
 
19
- NAME = :isnumeric
28
+ NAME = :isNumeric
20
29
 
21
30
  ##
22
31
  # Returns `true` if the operand is an `RDF::Literal::Numeric`, `false`
@@ -36,6 +45,15 @@ module SPARQL; module Algebra
36
45
  else raise TypeError, "expected an RDF::Term, but got #{term.inspect}"
37
46
  end
38
47
  end
48
+
49
+ ##
50
+ #
51
+ # Returns a partial SPARQL grammar for this operator.
52
+ #
53
+ # @return [String]
54
+ def to_sparql(**options)
55
+ "isNumeric(" + operands.first.to_sparql(**options) + ")"
56
+ end
39
57
  end # IsNumeric
40
58
  end # Operator
41
59
  end; end # SPARQL::Algebra
@@ -5,6 +5,29 @@ module SPARQL; module Algebra
5
5
  #
6
6
  # Returns true if term is an RDF-star triple. Returns false otherwise.
7
7
  #
8
+ # [121] BuiltInCall ::= ... | 'isTreiple' '(' Expression ')'
9
+ #
10
+ # @example SPARQL Grammar
11
+ # PREFIX : <http://example.com/ns#>
12
+ # SELECT * {
13
+ # ?t :source :g
14
+ # FILTER(isTriple(?t))
15
+ # FILTER(SUBJECT(?t) = :s)
16
+ # FILTER(PREDICATE(?t) = :p)
17
+ # FILTER(OBJECT(?t) = :o)
18
+ # }
19
+ #
20
+ # @example SSE
21
+ # (prefix
22
+ # ((: <http://example.com/ns#>))
23
+ # (filter
24
+ # (exprlist
25
+ # (isTRIPLE ?t)
26
+ # (= (subject ?t) :s)
27
+ # (= (predicate ?t) :p)
28
+ # (= (object ?t) :o))
29
+ # (bgp (triple ?t :source :g))) )
30
+ #
8
31
  # @see https://w3c.github.io/rdf-star/rdf-star-cg-spec.html#istriple
9
32
  class IsTriple < Operator::Unary
10
33
  include Evaluatable
@@ -25,6 +48,15 @@ module SPARQL; module Algebra
25
48
  else raise TypeError, "expected an RDF::Term, but got #{term.inspect}"
26
49
  end
27
50
  end
51
+
52
+ ##
53
+ #
54
+ # Returns a partial SPARQL grammar for this operator.
55
+ #
56
+ # @return [String]
57
+ def to_sparql(**options)
58
+ "isTRIPLE(" + operands.first.to_sparql(**options) + ")"
59
+ end
28
60
  end # IsTriple
29
61
  end # Operator
30
62
  end; end # SPARQL::Algebra
@@ -3,7 +3,16 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL GraphPattern `join` operator.
5
5
  #
6
- # @example
6
+ # [54] GroupGraphPatternSub ::= TriplesBlock? (GraphPatternNotTriples "."? TriplesBlock? )*
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example/>
10
+ # SELECT * {
11
+ # ?s ?p ?o
12
+ # GRAPH ?g { ?s ?q ?v }
13
+ # }
14
+ #
15
+ # @example SSE
7
16
  # (prefix ((: <http://example/>))
8
17
  # (join
9
18
  # (bgp (triple ?s ?p ?o))
@@ -82,6 +91,18 @@ module SPARQL; module Algebra
82
91
  @operands = ops
83
92
  self
84
93
  end
94
+
95
+ ##
96
+ #
97
+ # Returns a partial SPARQL grammar for this operator.
98
+ #
99
+ # @param [Boolean] top_level (true)
100
+ # Treat this as a top-level, generating SELECT ... WHERE {}
101
+ # @return [String]
102
+ def to_sparql(top_level: true, **options)
103
+ str = operands.to_sparql(top_level: false, delimiter: "\n", **options)
104
+ top_level ? Operator.to_sparql(str, **options) : str
105
+ end
85
106
  end # Join
86
107
  end # Operator
87
108
  end; end # SPARQL::Algebra
@@ -3,6 +3,22 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `lang` operator.
5
5
  #
6
+ # [121] BuiltInCall ::= ... | 'LANG' '(' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example/>
10
+ #
11
+ # SELECT ?x
12
+ # { ?x :p ?v .
13
+ # FILTER ( lang(?v) != '@NotALangTag@' )
14
+ # }
15
+ #
16
+ # @example SSE
17
+ # (prefix ((: <http://example/>))
18
+ # (project (?x)
19
+ # (filter (!= (lang ?v) "@NotALangTag@")
20
+ # (bgp (triple ?x :p ?v)))))
21
+ #
6
22
  # @see https://www.w3.org/TR/sparql11-query/#func-lang
7
23
  class Lang < Operator::Unary
8
24
  include Evaluatable
@@ -24,6 +40,15 @@ module SPARQL; module Algebra
24
40
  else raise TypeError, "expected an RDF::Literal, but got #{literal.inspect}"
25
41
  end
26
42
  end
43
+
44
+ ##
45
+ #
46
+ # Returns a partial SPARQL grammar for this operator.
47
+ #
48
+ # @return [String]
49
+ def to_sparql(**options)
50
+ "lang(" + operands.first.to_sparql(**options) + ")"
51
+ end
27
52
  end # Lang
28
53
  end # Operator
29
54
  end; end # SPARQL::Algebra
@@ -3,7 +3,15 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL `langMatches` operator.
5
5
  #
6
- # @example
6
+ # [121] BuiltInCall ::= ... | 'LANGMATCHES' '(' Expression ',' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example.org/#>
10
+ #
11
+ # SELECT *
12
+ # { :x ?p ?v . FILTER langMatches(lang(?v), "en-GB") . }
13
+ #
14
+ # @example SSE
7
15
  # (prefix ((: <http://example.org/#>))
8
16
  # (filter (langMatches (lang ?v) "en-GB")
9
17
  # (bgp (triple :x ?p ?v))))
@@ -48,6 +56,19 @@ module SPARQL; module Algebra
48
56
  RDF::Literal(language_tag.start_with?(language_range + '-'))
49
57
  end
50
58
  end
59
+
60
+ ##
61
+ #
62
+ # Returns a partial SPARQL grammar for this operator.
63
+ #
64
+ # @return [String]
65
+ def to_sparql(**options)
66
+ "langMatches(" +
67
+ operands.first.to_sparql(**options) +
68
+ ", " +
69
+ operands.last.to_sparql(**options) +
70
+ ")"
71
+ end
51
72
  end # LangMatches
52
73
  end # Operator
53
74
  end; end # SPARQL::Algebra
@@ -3,8 +3,20 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL logical `lcase` operator.
5
5
  #
6
- # @example
7
- # (lcase ?x)
6
+ # [121] BuiltInCall ::= ... | 'LCASE' '(' Expression ')'
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example.org/>
10
+ # SELECT ?s (LCASE(?str) AS ?lstr) WHERE {
11
+ # ?s :str ?str
12
+ # }
13
+ #
14
+ # @example SSE
15
+ # (prefix
16
+ # ((: <http://example.org/>))
17
+ # (project (?str ?lstr)
18
+ # (extend ((?lstr (lcase ?str)))
19
+ # (bgp (triple ?s :str ?str)))))
8
20
  #
9
21
  # @see https://www.w3.org/TR/sparql11-query/#func-lcase
10
22
  # @see https://www.w3.org/TR/xpath-functions/#func-lcase
@@ -26,6 +38,15 @@ module SPARQL; module Algebra
26
38
  else raise TypeError, "expected an RDF::Literal::Numeric, but got #{operand.inspect}"
27
39
  end
28
40
  end
41
+
42
+ ##
43
+ #
44
+ # Returns a partial SPARQL grammar for this operator.
45
+ #
46
+ # @return [String]
47
+ def to_sparql(**options)
48
+ "LCASE(" + operands.last.to_sparql(**options) + ")"
49
+ end
29
50
  end # LCase
30
51
  end # Operator
31
52
  end; end # SPARQL::Algebra
@@ -3,7 +3,19 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL GraphPattern `leftjoin` operator.
5
5
  #
6
- # @example
6
+ # [57] OptionalGraphPattern ::= 'OPTIONAL' GroupGraphPattern
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX : <http://example/>
10
+ # SELECT * {
11
+ # ?x :p ?v .
12
+ # OPTIONAL {
13
+ # ?y :q ?w .
14
+ # FILTER(?v=2)
15
+ # }
16
+ # }
17
+ #
18
+ # @example SSE
7
19
  # (prefix ((: <http://example/>))
8
20
  # (leftjoin
9
21
  # (bgp (triple ?x :p ?v))
@@ -112,6 +124,22 @@ module SPARQL; module Algebra
112
124
  expr ? LeftJoin.new(ops[0], ops[1], expr) : LeftJoin.new(ops[0], ops[1])
113
125
  end
114
126
  end
127
+
128
+ ##
129
+ #
130
+ # Returns a partial SPARQL grammar for this operator.
131
+ #
132
+ # @param [Boolean] top_level (true)
133
+ # Treat this as a top-level, generating SELECT ... WHERE {}
134
+ # @return [String]
135
+ def to_sparql(top_level: true, **options)
136
+ str = operands[0].to_sparql(top_level: false, **options) +
137
+ "\nOPTIONAL { \n" +
138
+ operands[1].to_sparql(top_level: false, **options) + "\n"
139
+ str << 'FILTER (' + operands[2].to_sparql(**options) + ") \n" if operands[2]
140
+ str << '}'
141
+ top_level ? Operator.to_sparql(str, **options) : str
142
+ end
115
143
  end # LeftJoin
116
144
  end # Operator
117
145
  end; end # SPARQL::Algebra
@@ -3,8 +3,18 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL relational `<` (less than) comparison operator.
5
5
  #
6
- # @example
7
- # (< ?x ?y)
6
+ # [114] RelationalExpression ::= NumericExpression ('<' NumericExpression)?
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
10
+ # PREFIX : <http://example.org/things#>
11
+ # SELECT ?x
12
+ # WHERE { ?x :p ?v . FILTER ( ?v < 1 ) }
13
+ #
14
+ # @example SSE
15
+ # (prefix
16
+ # ((xsd: <http://www.w3.org/2001/XMLSchema#>) (: <http://example.org/things#>))
17
+ # (project (?x) (filter (< ?v 1) (bgp (triple ?x :p ?v)))))
8
18
  #
9
19
  # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
10
20
  # @see https://www.w3.org/TR/xpath-functions/#func-compare
@@ -25,7 +35,6 @@ module SPARQL; module Algebra
25
35
  # @return [RDF::Literal::Boolean] `true` or `false`
26
36
  # @raise [TypeError] if either operand is not a literal
27
37
  def apply(left, right, **options)
28
- #require 'byebug'; byebug if super == RDF::Literal(-1)
29
38
  RDF::Literal(super == RDF::Literal(-1))
30
39
  end
31
40
  end # LessThan
@@ -3,8 +3,18 @@ module SPARQL; module Algebra
3
3
  ##
4
4
  # The SPARQL relational `<=` (less than or equal) comparison operator.
5
5
  #
6
- # @example
7
- # (<= ?x ?y)
6
+ # [114] RelationalExpression ::= NumericExpression ('<=' NumericExpression)?
7
+ #
8
+ # @example SPARQL Grammar
9
+ # PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
10
+ # PREFIX : <http://example.org/things#>
11
+ # SELECT ?x
12
+ # WHERE { ?x :p ?v . FILTER ( ?v <= 1 ) }
13
+ #
14
+ # @example SSE
15
+ # (prefix
16
+ # ((xsd: <http://www.w3.org/2001/XMLSchema#>) (: <http://example.org/things#>))
17
+ # (project (?x) (filter (<= ?v 1) (bgp (triple ?x :p ?v)))))
8
18
  #
9
19
  # @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
10
20
  # @see https://www.w3.org/TR/xpath-functions/#func-compare