sparql 3.1.0 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +183 -69
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/bin/sparql +20 -9
- data/lib/rack/sparql/conneg.rb +2 -2
- data/lib/sinatra/sparql.rb +3 -3
- data/lib/sparql.rb +8 -6
- data/lib/sparql/algebra.rb +7 -15
- data/lib/sparql/algebra/aggregate.rb +2 -2
- data/lib/sparql/algebra/expression.rb +22 -8
- data/lib/sparql/algebra/extensions.rb +135 -3
- data/lib/sparql/algebra/operator.rb +37 -9
- data/lib/sparql/algebra/operator/abs.rb +2 -2
- data/lib/sparql/algebra/operator/add.rb +2 -2
- data/lib/sparql/algebra/operator/alt.rb +2 -2
- data/lib/sparql/algebra/operator/and.rb +3 -3
- data/lib/sparql/algebra/operator/asc.rb +1 -1
- data/lib/sparql/algebra/operator/ask.rb +2 -12
- data/lib/sparql/algebra/operator/avg.rb +1 -1
- data/lib/sparql/algebra/operator/base.rb +8 -8
- data/lib/sparql/algebra/operator/bgp.rb +1 -1
- data/lib/sparql/algebra/operator/bnode.rb +2 -2
- data/lib/sparql/algebra/operator/bound.rb +1 -1
- data/lib/sparql/algebra/operator/ceil.rb +2 -2
- data/lib/sparql/algebra/operator/clear.rb +2 -2
- data/lib/sparql/algebra/operator/coalesce.rb +1 -11
- data/lib/sparql/algebra/operator/compare.rb +8 -8
- data/lib/sparql/algebra/operator/concat.rb +2 -2
- data/lib/sparql/algebra/operator/construct.rb +2 -12
- data/lib/sparql/algebra/operator/contains.rb +2 -2
- data/lib/sparql/algebra/operator/copy.rb +2 -2
- data/lib/sparql/algebra/operator/count.rb +1 -1
- data/lib/sparql/algebra/operator/create.rb +2 -2
- data/lib/sparql/algebra/operator/dataset.rb +2 -13
- data/lib/sparql/algebra/operator/datatype.rb +1 -1
- data/lib/sparql/algebra/operator/day.rb +1 -1
- data/lib/sparql/algebra/operator/delete.rb +4 -4
- data/lib/sparql/algebra/operator/delete_data.rb +2 -2
- data/lib/sparql/algebra/operator/delete_where.rb +2 -2
- data/lib/sparql/algebra/operator/desc.rb +1 -1
- data/lib/sparql/algebra/operator/describe.rb +2 -12
- data/lib/sparql/algebra/operator/distinct.rb +2 -12
- data/lib/sparql/algebra/operator/divide.rb +1 -1
- data/lib/sparql/algebra/operator/drop.rb +2 -2
- data/lib/sparql/algebra/operator/encode_for_uri.rb +2 -2
- data/lib/sparql/algebra/operator/equal.rb +2 -2
- data/lib/sparql/algebra/operator/exists.rb +1 -1
- data/lib/sparql/algebra/operator/exprlist.rb +1 -11
- data/lib/sparql/algebra/operator/extend.rb +14 -13
- data/lib/sparql/algebra/operator/filter.rb +3 -13
- data/lib/sparql/algebra/operator/floor.rb +2 -2
- data/lib/sparql/algebra/operator/graph.rb +3 -14
- data/lib/sparql/algebra/operator/greater_than.rb +5 -5
- data/lib/sparql/algebra/operator/greater_than_or_equal.rb +5 -5
- data/lib/sparql/algebra/operator/group.rb +14 -14
- data/lib/sparql/algebra/operator/group_concat.rb +1 -1
- data/lib/sparql/algebra/operator/hours.rb +1 -1
- data/lib/sparql/algebra/operator/if.rb +1 -11
- data/lib/sparql/algebra/operator/in.rb +1 -11
- data/lib/sparql/algebra/operator/insert.rb +3 -3
- data/lib/sparql/algebra/operator/insert_data.rb +2 -2
- data/lib/sparql/algebra/operator/iri.rb +1 -1
- data/lib/sparql/algebra/operator/is_blank.rb +1 -1
- data/lib/sparql/algebra/operator/is_iri.rb +1 -1
- data/lib/sparql/algebra/operator/is_literal.rb +1 -1
- data/lib/sparql/algebra/operator/is_numeric.rb +1 -1
- data/lib/sparql/algebra/operator/join.rb +9 -7
- data/lib/sparql/algebra/operator/lang.rb +1 -1
- data/lib/sparql/algebra/operator/lang_matches.rb +3 -3
- data/lib/sparql/algebra/operator/lcase.rb +2 -2
- data/lib/sparql/algebra/operator/left_join.rb +12 -9
- data/lib/sparql/algebra/operator/less_than.rb +5 -5
- data/lib/sparql/algebra/operator/less_than_or_equal.rb +5 -5
- data/lib/sparql/algebra/operator/load.rb +2 -2
- data/lib/sparql/algebra/operator/max.rb +1 -1
- data/lib/sparql/algebra/operator/md5.rb +1 -1
- data/lib/sparql/algebra/operator/min.rb +1 -1
- data/lib/sparql/algebra/operator/minus.rb +9 -8
- data/lib/sparql/algebra/operator/minutes.rb +1 -1
- data/lib/sparql/algebra/operator/modify.rb +1 -1
- data/lib/sparql/algebra/operator/month.rb +1 -1
- data/lib/sparql/algebra/operator/move.rb +2 -2
- data/lib/sparql/algebra/operator/multiply.rb +1 -1
- data/lib/sparql/algebra/operator/negate.rb +1 -1
- data/lib/sparql/algebra/operator/not.rb +1 -1
- data/lib/sparql/algebra/operator/not_equal.rb +2 -2
- data/lib/sparql/algebra/operator/notexists.rb +2 -2
- data/lib/sparql/algebra/operator/notin.rb +1 -11
- data/lib/sparql/algebra/operator/notoneof.rb +2 -2
- data/lib/sparql/algebra/operator/now.rb +1 -1
- data/lib/sparql/algebra/operator/or.rb +3 -3
- data/lib/sparql/algebra/operator/order.rb +2 -12
- data/lib/sparql/algebra/operator/path.rb +2 -2
- data/lib/sparql/algebra/operator/path_opt.rb +2 -2
- data/lib/sparql/algebra/operator/path_plus.rb +2 -2
- data/lib/sparql/algebra/operator/path_star.rb +2 -2
- data/lib/sparql/algebra/operator/plus.rb +2 -2
- data/lib/sparql/algebra/operator/prefix.rb +8 -8
- data/lib/sparql/algebra/operator/project.rb +2 -12
- data/lib/sparql/algebra/operator/rand.rb +1 -1
- data/lib/sparql/algebra/operator/reduced.rb +2 -12
- data/lib/sparql/algebra/operator/regex.rb +5 -5
- data/lib/sparql/algebra/operator/replace.rb +3 -3
- data/lib/sparql/algebra/operator/reverse.rb +2 -2
- data/lib/sparql/algebra/operator/round.rb +2 -2
- data/lib/sparql/algebra/operator/same_term.rb +8 -5
- data/lib/sparql/algebra/operator/sample.rb +1 -1
- data/lib/sparql/algebra/operator/seconds.rb +1 -1
- data/lib/sparql/algebra/operator/seq.rb +1 -1
- data/lib/sparql/algebra/operator/sequence.rb +1 -1
- data/lib/sparql/algebra/operator/sha1.rb +1 -1
- data/lib/sparql/algebra/operator/sha256.rb +1 -1
- data/lib/sparql/algebra/operator/sha384.rb +1 -1
- data/lib/sparql/algebra/operator/sha512.rb +1 -1
- data/lib/sparql/algebra/operator/slice.rb +2 -12
- data/lib/sparql/algebra/operator/str.rb +1 -1
- data/lib/sparql/algebra/operator/strafter.rb +2 -2
- data/lib/sparql/algebra/operator/strbefore.rb +2 -2
- data/lib/sparql/algebra/operator/strdt.rb +2 -2
- data/lib/sparql/algebra/operator/strends.rb +2 -2
- data/lib/sparql/algebra/operator/strlang.rb +2 -2
- data/lib/sparql/algebra/operator/strlen.rb +2 -2
- data/lib/sparql/algebra/operator/strstarts.rb +2 -2
- data/lib/sparql/algebra/operator/struuid.rb +1 -1
- data/lib/sparql/algebra/operator/substr.rb +3 -3
- data/lib/sparql/algebra/operator/subtract.rb +1 -1
- data/lib/sparql/algebra/operator/sum.rb +1 -1
- data/lib/sparql/algebra/operator/table.rb +2 -2
- data/lib/sparql/algebra/operator/timezone.rb +1 -1
- data/lib/sparql/algebra/operator/tz.rb +1 -1
- data/lib/sparql/algebra/operator/ucase.rb +2 -2
- data/lib/sparql/algebra/operator/union.rb +7 -6
- data/lib/sparql/algebra/operator/update.rb +2 -2
- data/lib/sparql/algebra/operator/using.rb +2 -2
- data/lib/sparql/algebra/operator/uuid.rb +1 -1
- data/lib/sparql/algebra/operator/with.rb +2 -2
- data/lib/sparql/algebra/operator/year.rb +1 -1
- data/lib/sparql/algebra/query.rb +1 -1
- data/lib/sparql/algebra/update.rb +1 -1
- data/lib/sparql/algebra/version.rb +1 -1
- data/lib/sparql/extensions.rb +1 -1
- data/lib/sparql/grammar.rb +104 -3
- data/lib/sparql/grammar/meta.rb +1372 -333
- data/lib/sparql/grammar/parser11.rb +27 -6
- data/lib/sparql/grammar/terminals11.rb +1 -0
- data/lib/sparql/results.rb +60 -41
- data/lib/sparql/version.rb +1 -1
- metadata +14 -8
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# @example
|
10
10
|
# (delete ((triple ?s ?p ?o))))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-update/#delete
|
13
13
|
class Delete < Operator::Unary
|
14
14
|
include SPARQL::Algebra::Update
|
15
15
|
|
@@ -20,8 +20,8 @@ module SPARQL; module Algebra
|
|
20
20
|
#
|
21
21
|
# @param [RDF::Queryable] queryable
|
22
22
|
# the graph or repository to write
|
23
|
-
# @param [RDF::Query::
|
24
|
-
#
|
23
|
+
# @param [RDF::Query::Solutions] solutions
|
24
|
+
# Solutions to map to patterns for this operation
|
25
25
|
# @param [Hash{Symbol => Object}] options
|
26
26
|
# any additional keyword options
|
27
27
|
# @option options [Boolean] debug
|
@@ -30,7 +30,7 @@ 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
|
33
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
34
34
|
def execute(queryable, solutions: nil, **options)
|
35
35
|
debug(options) {"Delete: #{solution} against #{operands.to_sse}"}
|
36
36
|
# Only binds the first solution
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# @example
|
10
10
|
# (deleteData ((triple :a foaf:knows :c)))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-update/#deleteData
|
13
13
|
class DeleteData < Operator::Unary
|
14
14
|
include SPARQL::Algebra::Update
|
15
15
|
|
@@ -28,7 +28,7 @@ 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
|
31
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
32
32
|
def execute(queryable, **options)
|
33
33
|
operand.each do |op|
|
34
34
|
debug(options) {"DeleteData #{op.to_sxp}"}
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# @example
|
10
10
|
# (deleteWhere ((triple :a foaf:knows ?b))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-update/#deleteWhere
|
13
13
|
class DeleteWhere < Operator::Unary
|
14
14
|
include SPARQL::Algebra::Update
|
15
15
|
|
@@ -28,7 +28,7 @@ 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
|
31
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
32
32
|
def execute(queryable, **options)
|
33
33
|
# Operands are an array of patterns and Queries (when named).
|
34
34
|
# Create a new query made up all patterns
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# (order ((desc ?name))
|
10
10
|
# (bgp (triple ?x foaf:name ?name)))))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-query/#modOrderBy
|
13
13
|
class Desc < Operator::Asc
|
14
14
|
NAME = :desc
|
15
15
|
end # Desc
|
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
|
|
10
10
|
# (describe (?x)
|
11
11
|
# (bgp (triple ?x exOrg:employeeId "1234"))))
|
12
12
|
#
|
13
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#describe
|
14
14
|
class Describe < Operator::Binary
|
15
15
|
include Query
|
16
16
|
|
@@ -39,7 +39,7 @@ module SPARQL; module Algebra
|
|
39
39
|
# @yieldreturn [void] ignored
|
40
40
|
# @return [RDF::Graph]
|
41
41
|
# containing the constructed triples
|
42
|
-
# @see
|
42
|
+
# @see https://www.w3.org/TR/sparql11-query/#describe
|
43
43
|
def execute(queryable, **options, &block)
|
44
44
|
debug(options) {"Describe #{operands.first}, #{options.inspect}"}
|
45
45
|
|
@@ -60,16 +60,6 @@ module SPARQL; module Algebra
|
|
60
60
|
# Return Concise Bounded Description
|
61
61
|
queryable.concise_bounded_description(*to_describe.uniq, &block)
|
62
62
|
end
|
63
|
-
|
64
|
-
##
|
65
|
-
# Returns an optimized version of this query.
|
66
|
-
#
|
67
|
-
# Return optimized query
|
68
|
-
#
|
69
|
-
# @return [Union, RDF::Query] `self`
|
70
|
-
def optimize
|
71
|
-
operands = operands.map(&:optimize)
|
72
|
-
end
|
73
63
|
|
74
64
|
# Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE)
|
75
65
|
# @return [Boolean]
|
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
|
|
10
10
|
# (project (?v)
|
11
11
|
# (bgp (triple ?x ?p ?v)))))
|
12
12
|
#
|
13
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlDistinct
|
14
14
|
class Distinct < Operator::Unary
|
15
15
|
include Query
|
16
16
|
|
@@ -30,22 +30,12 @@ module SPARQL; module Algebra
|
|
30
30
|
# @yieldreturn [void] ignored
|
31
31
|
# @return [RDF::Query::Solutions]
|
32
32
|
# the resulting solution sequence
|
33
|
-
# @see
|
33
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
34
34
|
def execute(queryable, **options, &block)
|
35
35
|
@solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options).distinct
|
36
36
|
@solutions.each(&block) if block_given?
|
37
37
|
@solutions
|
38
38
|
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# Returns an optimized version of this query.
|
42
|
-
#
|
43
|
-
# Return optimized query
|
44
|
-
#
|
45
|
-
# @return [Union, RDF::Query] `self`
|
46
|
-
def optimize
|
47
|
-
operands = operands.map(&:optimize)
|
48
|
-
end
|
49
39
|
end # Distinct
|
50
40
|
end # Operator
|
51
41
|
end; end # SPARQL::Algebra
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# @example
|
12
12
|
# (drop default)
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-update/#drop
|
15
15
|
class Drop < Operator
|
16
16
|
include SPARQL::Algebra::Update
|
17
17
|
|
@@ -30,7 +30,7 @@ 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
|
33
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
34
34
|
def execute(queryable, **options)
|
35
35
|
debug(options) {"Drop"}
|
36
36
|
silent = operands.first == :silent
|
@@ -8,8 +8,8 @@ module SPARQL; module Algebra
|
|
8
8
|
# @example
|
9
9
|
# (encode_for_uri ?x)
|
10
10
|
#
|
11
|
-
# @see
|
12
|
-
# @see
|
11
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-encode
|
12
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-abs
|
13
13
|
class EncodeForURI < Operator::Unary
|
14
14
|
include Evaluatable
|
15
15
|
|
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (= ?x ?y)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#OperatorMapping
|
10
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-RDFterm-equal
|
11
11
|
class Equal < Compare
|
12
12
|
NAME = :'='
|
13
13
|
|
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
|
|
10
10
|
# (filter (exists (bgp (triple ?s ?p ex:o)))
|
11
11
|
# (bgp (triple ?s ?p ?o))))
|
12
12
|
#
|
13
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-filter-exists
|
14
14
|
class Exists < Operator::Unary
|
15
15
|
include Evaluatable
|
16
16
|
|
@@ -14,7 +14,7 @@ module SPARQL; module Algebra
|
|
14
14
|
# (triple ?s :q ?w)
|
15
15
|
# ))))
|
16
16
|
#
|
17
|
-
# @see
|
17
|
+
# @see https://www.w3.org/TR/sparql11-query/#evaluation
|
18
18
|
class Exprlist < Operator
|
19
19
|
include Evaluatable
|
20
20
|
|
@@ -40,16 +40,6 @@ module SPARQL; module Algebra
|
|
40
40
|
res = operands.all? {|op| boolean(op.evaluate(bindings, depth: options[:depth].to_i + 1, **options)).true? }
|
41
41
|
RDF::Literal(res) # FIXME: error handling
|
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 # Exprlist
|
54
44
|
end # Operator
|
55
45
|
end; end # SPARQL::Algebra
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# (extend ((?z (+ ?o 10)))
|
12
12
|
# (bgp (triple ?s <http://example/p> ?o)))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/#evaluation
|
15
15
|
class Extend < Operator::Binary
|
16
16
|
include Query
|
17
17
|
|
@@ -28,6 +28,12 @@ module SPARQL; module Algebra
|
|
28
28
|
#
|
29
29
|
# Extend(Ω, var, expr) = { Extend(μ, var, expr) | μ in Ω }
|
30
30
|
#
|
31
|
+
# For SPARQL*, expr may be an embedded tiple pattern
|
32
|
+
#
|
33
|
+
# (extend
|
34
|
+
# ((?t (triple ?bob foaf:age ?age)))
|
35
|
+
# (bgp (triple ?t dct:source ?src)))
|
36
|
+
#
|
31
37
|
# @param [RDF::Queryable] queryable
|
32
38
|
# the graph or repository to query
|
33
39
|
# @param [Hash{Symbol => Object}] options
|
@@ -38,7 +44,7 @@ module SPARQL; module Algebra
|
|
38
44
|
# @yieldreturn [void] ignored
|
39
45
|
# @return [RDF::Query::Solutions]
|
40
46
|
# the resulting solution sequence
|
41
|
-
# @see
|
47
|
+
# @see https://www.w3.org/TR/sparql11-query/#evaluation
|
42
48
|
def execute(queryable, **options, &block)
|
43
49
|
debug(options) {"Extend"}
|
44
50
|
@solutions = operand(1).execute(queryable, depth: options[:depth].to_i + 1, **options)
|
@@ -50,7 +56,12 @@ module SPARQL; module Algebra
|
|
50
56
|
depth: options[:depth].to_i + 1,
|
51
57
|
**options)
|
52
58
|
debug(options) {"===> + #{var} => #{val.inspect}"}
|
53
|
-
solution.bindings[var.to_sym] = val
|
59
|
+
solution.bindings[var.to_sym] = if val.is_a?(RDF::Query::Pattern)
|
60
|
+
# Variable is bound to the solution
|
61
|
+
val.bind(solution)
|
62
|
+
else
|
63
|
+
val
|
64
|
+
end
|
54
65
|
rescue TypeError => e
|
55
66
|
# Evaluates to error, ignore
|
56
67
|
debug(options) {"===> #{var} error: #{e.message}"}
|
@@ -72,16 +83,6 @@ module SPARQL; module Algebra
|
|
72
83
|
end
|
73
84
|
super
|
74
85
|
end
|
75
|
-
|
76
|
-
##
|
77
|
-
# Returns an optimized version of this query.
|
78
|
-
#
|
79
|
-
# Return optimized query
|
80
|
-
#
|
81
|
-
# @return FIXME
|
82
|
-
def optimize
|
83
|
-
operands = operands.map(&:optimize)
|
84
|
-
end
|
85
86
|
end # Filter
|
86
87
|
end # Operator
|
87
88
|
end; end # SPARQL::Algebra
|
@@ -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
|
12
|
+
# @see https://www.w3.org/TR/sparql11-query/#evaluation
|
13
13
|
class Filter < Operator::Binary
|
14
14
|
include Query
|
15
15
|
|
@@ -34,8 +34,8 @@ module SPARQL; module Algebra
|
|
34
34
|
# @yieldreturn [void] ignored
|
35
35
|
# @return [RDF::Query::Solutions]
|
36
36
|
# the resulting solution sequence
|
37
|
-
# @see
|
38
|
-
# @see
|
37
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
38
|
+
# @see https://www.w3.org/TR/sparql11-query/#ebv
|
39
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)
|
@@ -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
|
10
|
-
# @see
|
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
|
18
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
19
19
|
class Graph < Operator::Binary
|
20
20
|
include Query
|
21
21
|
|
@@ -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
|
66
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
67
67
|
def execute(queryable, **options, &block)
|
68
68
|
debug(options) {"Graph #{operands.first}"}
|
69
69
|
graph_name, query = operands.first, operands.last
|
70
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
|
10
|
-
# @see
|
11
|
-
# @see
|
12
|
-
# @see
|
13
|
-
# @see
|
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
|
11
|
-
# @see
|
12
|
-
# @see
|
13
|
-
# @see
|
14
|
-
# @see
|
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
|
|
@@ -17,7 +17,7 @@ module SPARQL; module Algebra
|
|
17
17
|
# (bgp (triple ?s :p ?v))
|
18
18
|
# (bgp (triple ?s :q ?w)))))))
|
19
19
|
#
|
20
|
-
# @see
|
20
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
21
21
|
class Group < Operator
|
22
22
|
include Query
|
23
23
|
|
@@ -37,7 +37,7 @@ module SPARQL; module Algebra
|
|
37
37
|
# @yieldreturn [void] ignored
|
38
38
|
# @return [RDF::Query::Solutions]
|
39
39
|
# the resulting solution sequence
|
40
|
-
# @see
|
40
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlGroupAggregate
|
41
41
|
def execute(queryable, **options, &block)
|
42
42
|
debug(options) {"Group"}
|
43
43
|
exprlist = operands.first
|
@@ -84,8 +84,18 @@ module SPARQL; module Algebra
|
|
84
84
|
group_soln
|
85
85
|
end)
|
86
86
|
|
87
|
-
#
|
88
|
-
@solutions
|
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
|