sparql 3.0.0 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +184 -70
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/bin/sparql +28 -17
- data/lib/rack/sparql.rb +1 -1
- data/lib/rack/sparql/conneg.rb +3 -3
- data/lib/sinatra/sparql.rb +5 -5
- data/lib/sparql.rb +14 -10
- data/lib/sparql/algebra.rb +15 -23
- data/lib/sparql/algebra/aggregate.rb +4 -4
- data/lib/sparql/algebra/evaluatable.rb +2 -2
- data/lib/sparql/algebra/expression.rb +28 -21
- data/lib/sparql/algebra/extensions.rb +142 -16
- data/lib/sparql/algebra/operator.rb +37 -16
- data/lib/sparql/algebra/operator/abs.rb +2 -2
- data/lib/sparql/algebra/operator/add.rb +3 -3
- data/lib/sparql/algebra/operator/alt.rb +4 -4
- data/lib/sparql/algebra/operator/and.rb +7 -7
- data/lib/sparql/algebra/operator/asc.rb +3 -3
- data/lib/sparql/algebra/operator/ask.rb +4 -14
- data/lib/sparql/algebra/operator/avg.rb +6 -4
- data/lib/sparql/algebra/operator/base.rb +10 -10
- data/lib/sparql/algebra/operator/bgp.rb +1 -1
- data/lib/sparql/algebra/operator/bnode.rb +5 -5
- data/lib/sparql/algebra/operator/bound.rb +3 -3
- data/lib/sparql/algebra/operator/ceil.rb +2 -2
- data/lib/sparql/algebra/operator/clear.rb +3 -3
- data/lib/sparql/algebra/operator/coalesce.rb +3 -13
- data/lib/sparql/algebra/operator/compare.rb +8 -8
- data/lib/sparql/algebra/operator/concat.rb +4 -4
- data/lib/sparql/algebra/operator/construct.rb +4 -14
- data/lib/sparql/algebra/operator/contains.rb +2 -2
- data/lib/sparql/algebra/operator/copy.rb +3 -3
- data/lib/sparql/algebra/operator/count.rb +3 -3
- data/lib/sparql/algebra/operator/create.rb +3 -3
- data/lib/sparql/algebra/operator/dataset.rb +5 -16
- 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 +7 -5
- data/lib/sparql/algebra/operator/delete_data.rb +3 -3
- data/lib/sparql/algebra/operator/delete_where.rb +5 -5
- data/lib/sparql/algebra/operator/desc.rb +1 -1
- data/lib/sparql/algebra/operator/describe.rb +3 -13
- data/lib/sparql/algebra/operator/distinct.rb +4 -14
- data/lib/sparql/algebra/operator/divide.rb +1 -1
- data/lib/sparql/algebra/operator/drop.rb +3 -3
- data/lib/sparql/algebra/operator/encode_for_uri.rb +3 -3
- data/lib/sparql/algebra/operator/equal.rb +3 -3
- data/lib/sparql/algebra/operator/exists.rb +5 -5
- data/lib/sparql/algebra/operator/exprlist.rb +3 -13
- data/lib/sparql/algebra/operator/extend.rb +21 -20
- data/lib/sparql/algebra/operator/filter.rb +6 -16
- data/lib/sparql/algebra/operator/floor.rb +2 -2
- data/lib/sparql/algebra/operator/graph.rb +5 -16
- 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 +25 -25
- data/lib/sparql/algebra/operator/group_concat.rb +6 -6
- data/lib/sparql/algebra/operator/hours.rb +1 -1
- data/lib/sparql/algebra/operator/if.rb +5 -15
- data/lib/sparql/algebra/operator/in.rb +4 -14
- data/lib/sparql/algebra/operator/insert.rb +6 -4
- data/lib/sparql/algebra/operator/insert_data.rb +3 -3
- 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 +12 -10
- 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 +15 -12
- 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 +3 -3
- data/lib/sparql/algebra/operator/max.rb +6 -4
- data/lib/sparql/algebra/operator/md5.rb +1 -1
- data/lib/sparql/algebra/operator/min.rb +6 -4
- data/lib/sparql/algebra/operator/minus.rb +12 -11
- data/lib/sparql/algebra/operator/minutes.rb +1 -1
- data/lib/sparql/algebra/operator/modify.rb +4 -4
- data/lib/sparql/algebra/operator/month.rb +1 -1
- data/lib/sparql/algebra/operator/move.rb +3 -3
- 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 +4 -4
- data/lib/sparql/algebra/operator/notin.rb +4 -14
- data/lib/sparql/algebra/operator/notoneof.rb +5 -6
- data/lib/sparql/algebra/operator/now.rb +1 -1
- data/lib/sparql/algebra/operator/or.rb +7 -7
- data/lib/sparql/algebra/operator/order.rb +6 -16
- data/lib/sparql/algebra/operator/path.rb +6 -5
- data/lib/sparql/algebra/operator/path_opt.rb +16 -16
- data/lib/sparql/algebra/operator/path_plus.rb +8 -8
- data/lib/sparql/algebra/operator/path_star.rb +4 -4
- data/lib/sparql/algebra/operator/plus.rb +3 -3
- data/lib/sparql/algebra/operator/prefix.rb +10 -10
- data/lib/sparql/algebra/operator/project.rb +4 -14
- data/lib/sparql/algebra/operator/rand.rb +1 -1
- data/lib/sparql/algebra/operator/reduced.rb +4 -14
- data/lib/sparql/algebra/operator/regex.rb +6 -6
- data/lib/sparql/algebra/operator/replace.rb +4 -4
- data/lib/sparql/algebra/operator/reverse.rb +4 -4
- 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 +3 -3
- data/lib/sparql/algebra/operator/seconds.rb +1 -1
- data/lib/sparql/algebra/operator/seq.rb +5 -6
- data/lib/sparql/algebra/operator/sequence.rb +4 -4
- 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 +4 -14
- 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 +4 -4
- data/lib/sparql/algebra/operator/subtract.rb +1 -1
- data/lib/sparql/algebra/operator/sum.rb +6 -4
- data/lib/sparql/algebra/operator/table.rb +6 -4
- 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 +10 -9
- data/lib/sparql/algebra/operator/update.rb +4 -4
- data/lib/sparql/algebra/operator/using.rb +4 -4
- data/lib/sparql/algebra/operator/uuid.rb +1 -1
- data/lib/sparql/algebra/operator/with.rb +6 -6
- data/lib/sparql/algebra/operator/year.rb +1 -1
- data/lib/sparql/algebra/query.rb +2 -2
- data/lib/sparql/algebra/update.rb +2 -2
- data/lib/sparql/algebra/version.rb +1 -1
- data/lib/sparql/extensions.rb +5 -5
- data/lib/sparql/grammar.rb +111 -11
- data/lib/sparql/grammar/meta.rb +1372 -333
- data/lib/sparql/grammar/parser11.rb +56 -42
- data/lib/sparql/grammar/terminals11.rb +1 -0
- data/lib/sparql/results.rb +63 -44
- data/lib/sparql/version.rb +1 -1
- metadata +40 -47
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (path+ :p)
|
8
8
|
#
|
9
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_OneOrMorePath
|
10
10
|
class PathPlus < Operator::Unary
|
11
11
|
include Query
|
12
12
|
|
@@ -25,8 +25,8 @@ module SPARQL; module Algebra
|
|
25
25
|
# each matching solution
|
26
26
|
# @yieldparam [RDF::Query::Solution] solution
|
27
27
|
# @yieldreturn [void] ignored
|
28
|
-
# @see
|
29
|
-
def execute(queryable, options
|
28
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
29
|
+
def execute(queryable, **options, &block)
|
30
30
|
subject, object = options[:subject], options[:object]
|
31
31
|
debug(options) {"Path+ #{[subject, operands, object].to_sse}"}
|
32
32
|
|
@@ -53,7 +53,7 @@ module SPARQL; module Algebra
|
|
53
53
|
# Keep track of solutions
|
54
54
|
# Recurse into query
|
55
55
|
immediate_solutions = []
|
56
|
-
queryable.query(query,
|
56
|
+
queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
|
57
57
|
immediate_solutions << solution
|
58
58
|
end
|
59
59
|
|
@@ -66,23 +66,23 @@ module SPARQL; module Algebra
|
|
66
66
|
case
|
67
67
|
when subject.variable? && object.variable?
|
68
68
|
# Query starting with bound object as subject, but replace result with subject
|
69
|
-
rs = queryable.query(self, options.merge(
|
69
|
+
rs = queryable.query(self, **options.merge(
|
70
70
|
subject: solution[object],
|
71
71
|
accumulator: (cumulative_solutions + immediate_solutions),
|
72
72
|
depth: options[:depth].to_i + 1)).map {|s| s.merge(subject.to_sym => solution[subject])}
|
73
73
|
# Query starting with bound subject as object, but replace result with subject
|
74
|
-
ro = queryable.query(self, options.merge(
|
74
|
+
ro = queryable.query(self, **options.merge(
|
75
75
|
object: solution[subject],
|
76
76
|
accumulator: (cumulative_solutions + immediate_solutions),
|
77
77
|
depth: options[:depth].to_i + 1)).map {|s| s.merge(object.to_sym => solution[object])}
|
78
78
|
recursive_solutions += (rs + ro).uniq
|
79
79
|
when subject.variable?
|
80
|
-
recursive_solutions += queryable.query(self, options.merge(
|
80
|
+
recursive_solutions += queryable.query(self, **options.merge(
|
81
81
|
object: solution[subject],
|
82
82
|
accumulator: (cumulative_solutions + immediate_solutions),
|
83
83
|
depth: options[:depth].to_i + 1)).uniq
|
84
84
|
when object.variable?
|
85
|
-
recursive_solutions += queryable.query(self, options.merge(
|
85
|
+
recursive_solutions += queryable.query(self, **options.merge(
|
86
86
|
subject: solution[object],
|
87
87
|
accumulator: (cumulative_solutions + immediate_solutions),
|
88
88
|
depth: options[:depth].to_i + 1)).uniq
|
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (path* :p)
|
8
8
|
#
|
9
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_ZeroOrMorePath
|
10
10
|
class PathStar < Operator::Unary
|
11
11
|
include Query
|
12
12
|
|
@@ -28,14 +28,14 @@ module SPARQL; module Algebra
|
|
28
28
|
# each matching solution
|
29
29
|
# @yieldparam [RDF::Query::Solution] solution
|
30
30
|
# @yieldreturn [void] ignored
|
31
|
-
# @see
|
32
|
-
def execute(queryable, options
|
31
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
32
|
+
def execute(queryable, **options, &block)
|
33
33
|
subject, object = options[:subject], options[:object]
|
34
34
|
debug(options) {"Path* #{[subject, operands, object].to_sse}"}
|
35
35
|
|
36
36
|
# (:x :p* :y) => (:x (:p+)? :y)
|
37
37
|
query = PathOpt.new(PathPlus.new(*operands))
|
38
|
-
query.execute(queryable,
|
38
|
+
query.execute(queryable, depth: options[:depth].to_i + 1, **options, &block)
|
39
39
|
end
|
40
40
|
end # PathStar
|
41
41
|
end # Operator
|
@@ -7,9 +7,9 @@ module SPARQL; module Algebra
|
|
7
7
|
# (+ ?x ?y)
|
8
8
|
# (plus ?x ?y)
|
9
9
|
#
|
10
|
-
# @see
|
11
|
-
# @see
|
12
|
-
class Plus < Operator
|
10
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-numeric-unary-plus
|
11
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-numeric-add
|
12
|
+
class Plus < Operator
|
13
13
|
include Evaluatable
|
14
14
|
|
15
15
|
NAME = [:+, :plus]
|
@@ -8,7 +8,7 @@ module SPARQL; module Algebra
|
|
8
8
|
# (graph ?g
|
9
9
|
# (bgp (triple ?s ?p ?o))))
|
10
10
|
#
|
11
|
-
# @see
|
11
|
+
# @see https://www.w3.org/TR/sparql11-query/#QSynIRI
|
12
12
|
class Prefix < Binary
|
13
13
|
include Query
|
14
14
|
|
@@ -29,21 +29,21 @@ module SPARQL; module Algebra
|
|
29
29
|
# @yieldreturn [void] ignored
|
30
30
|
# @return [RDF::Query::Solutions]
|
31
31
|
# the resulting solution sequence
|
32
|
-
# @see
|
33
|
-
def execute(queryable, options
|
32
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
33
|
+
def execute(queryable, **options, &block)
|
34
34
|
debug(options) {"Prefix"}
|
35
|
-
@solutions = queryable.query(operands.last,
|
35
|
+
@solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options, &block)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
##
|
39
39
|
# Returns an optimized version of this query.
|
40
40
|
#
|
41
|
-
#
|
42
|
-
# with the unique sum of the query elements
|
41
|
+
# Replace with the query with URIs having their lexical shortcut removed
|
43
42
|
#
|
44
|
-
# @return [
|
45
|
-
|
46
|
-
|
43
|
+
# @return [Prefix] a copy of `self`
|
44
|
+
# @see SPARQL::Algebra::Expression#optimize
|
45
|
+
def optimize(**options)
|
46
|
+
operands.last.optimize(**options)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Combine two prefix definitions, merging their definitions
|
@@ -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/#modProjection
|
13
13
|
class Project < Operator::Binary
|
14
14
|
include Query
|
15
15
|
|
@@ -29,23 +29,13 @@ module SPARQL; module Algebra
|
|
29
29
|
# @yieldreturn [void] ignored
|
30
30
|
# @return [RDF::Query::Solutions]
|
31
31
|
# the resulting solution sequence
|
32
|
-
# @see
|
33
|
-
def execute(queryable, options
|
34
|
-
@solutions = queryable.query(operands.last,
|
32
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
33
|
+
def execute(queryable, **options, &block)
|
34
|
+
@solutions = queryable.query(operands.last, depth: options[:depth].to_i + 1, **options)
|
35
35
|
@solutions = @solutions.project(*(operands.first))
|
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 # Project
|
50
40
|
end # Operator
|
51
41
|
end; end # SPARQL::Algebra
|
@@ -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/#sparqlAlgebra
|
14
14
|
class Reduced < Operator::Unary
|
15
15
|
include Query
|
16
16
|
|
@@ -30,23 +30,13 @@ module SPARQL; module Algebra
|
|
30
30
|
# @yieldreturn [void] ignored
|
31
31
|
# @return [RDF::Query::Solutions]
|
32
32
|
# the resulting solution sequence
|
33
|
-
# @see
|
34
|
-
def execute(queryable, options
|
33
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
34
|
+
def execute(queryable, **options, &block)
|
35
35
|
@solutions = operands.last.
|
36
|
-
execute(queryable,
|
36
|
+
execute(queryable, depth: options[:depth].to_i + 1, **options).reduced
|
37
37
|
@solutions.each(&block) if block_given?
|
38
38
|
@solutions
|
39
39
|
end
|
40
|
-
|
41
|
-
##
|
42
|
-
# Returns an optimized version of this query.
|
43
|
-
#
|
44
|
-
# Return optimized query
|
45
|
-
#
|
46
|
-
# @return [Union, RDF::Query] `self`
|
47
|
-
def optimize
|
48
|
-
operands = operands.map(&:optimize)
|
49
|
-
end
|
50
40
|
end # Reduced
|
51
41
|
end # Operator
|
52
42
|
end; end # SPARQL::Algebra
|
@@ -10,8 +10,8 @@ module SPARQL; module Algebra
|
|
10
10
|
# (filter (regex ?val "GHI")
|
11
11
|
# (bgp (triple ex:foo rdf:value ?val)))))
|
12
12
|
#
|
13
|
-
# @see
|
14
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#funcex-regex
|
14
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-matches
|
15
15
|
class Regex < Operator::Ternary
|
16
16
|
include Evaluatable
|
17
17
|
|
@@ -26,7 +26,7 @@ module SPARQL; module Algebra
|
|
26
26
|
# @param [Hash{Symbol => Object}] options
|
27
27
|
# any additional options (see {Operator#initialize})
|
28
28
|
# @raise [TypeError] if any operand is invalid
|
29
|
-
def initialize(text, pattern, flags = RDF::Literal(''), options
|
29
|
+
def initialize(text, pattern, flags = RDF::Literal(''), **options)
|
30
30
|
super
|
31
31
|
end
|
32
32
|
|
@@ -43,17 +43,17 @@ module SPARQL; module Algebra
|
|
43
43
|
# @raise [TypeError] if any operand is unbound
|
44
44
|
# @raise [TypeError] if any operand is not a simple literal
|
45
45
|
def apply(text, pattern, flags = RDF::Literal(''))
|
46
|
-
# @see
|
46
|
+
# @see https://www.w3.org/TR/xpath-functions/#regex-syntax
|
47
47
|
raise TypeError, "expected a plain RDF::Literal, but got #{text.inspect}" unless text.is_a?(RDF::Literal) && text.plain?
|
48
48
|
text = text.to_s
|
49
49
|
# TODO: validate text syntax
|
50
50
|
|
51
|
-
# @see
|
51
|
+
# @see https://www.w3.org/TR/xpath-functions/#regex-syntax
|
52
52
|
raise TypeError, "expected a plain RDF::Literal, but got #{pattern.inspect}" unless pattern.is_a?(RDF::Literal) && pattern.plain?
|
53
53
|
pattern = pattern.to_s
|
54
54
|
# TODO: validate pattern syntax
|
55
55
|
|
56
|
-
# @see
|
56
|
+
# @see https://www.w3.org/TR/xpath-functions/#flags
|
57
57
|
raise TypeError, "expected a plain RDF::Literal, but got #{flags.inspect}" unless flags.is_a?(RDF::Literal) && flags.plain?
|
58
58
|
flags = flags.to_s
|
59
59
|
# TODO: validate flag syntax
|
@@ -10,8 +10,8 @@ module SPARQL; module Algebra
|
|
10
10
|
# (extend ((?new (replace ?str "[^a-z0-9]" "-")))
|
11
11
|
# (bgp (triple ?s :str ?str)))))
|
12
12
|
#
|
13
|
-
# @see
|
14
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#funcex-replace
|
14
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-replace
|
15
15
|
class Replace < Operator::Quaternary
|
16
16
|
include Evaluatable
|
17
17
|
|
@@ -27,7 +27,7 @@ module SPARQL; module Algebra
|
|
27
27
|
# @param [Hash{Symbol => Object}] options
|
28
28
|
# any additional options (see {Operator#initialize})
|
29
29
|
# @raise [TypeError] if any operand is invalid
|
30
|
-
def initialize(text, pattern, replacement, flags = RDF::Literal(''), options
|
30
|
+
def initialize(text, pattern, replacement, flags = RDF::Literal(''), **options)
|
31
31
|
super
|
32
32
|
end
|
33
33
|
|
@@ -72,7 +72,7 @@ module SPARQL; module Algebra
|
|
72
72
|
# Remove the optional argument.
|
73
73
|
#
|
74
74
|
# @return [Array] `self`
|
75
|
-
# @see
|
75
|
+
# @see https://openjena.org/wiki/SSE
|
76
76
|
def to_sxp_bin
|
77
77
|
[NAME] + operands.reject {|o| o.to_s == ""}
|
78
78
|
end
|
@@ -6,7 +6,7 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (reverse :p)
|
8
8
|
#
|
9
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_inverse
|
10
10
|
class Reverse < Operator::Unary
|
11
11
|
include Query
|
12
12
|
|
@@ -29,8 +29,8 @@ module SPARQL; module Algebra
|
|
29
29
|
# each matching solution
|
30
30
|
# @yieldparam [RDF::Query::Solution] solution
|
31
31
|
# @yieldreturn [void] ignored
|
32
|
-
# @see
|
33
|
-
def execute(queryable, options
|
32
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
33
|
+
def execute(queryable, **options, &block)
|
34
34
|
debug(options) {"Reverse #{operands.to_sse}"}
|
35
35
|
subject, object = options[:subject], options[:object]
|
36
36
|
|
@@ -42,7 +42,7 @@ module SPARQL; module Algebra
|
|
42
42
|
else
|
43
43
|
operand(0)
|
44
44
|
end
|
45
|
-
queryable.query(query, options.merge(
|
45
|
+
queryable.query(query, **options.merge(
|
46
46
|
subject: object,
|
47
47
|
object: subject,
|
48
48
|
depth: options[:depth].to_i + 1
|
@@ -8,8 +8,8 @@ module SPARQL; module Algebra
|
|
8
8
|
# @example
|
9
9
|
# (round ?x)
|
10
10
|
#
|
11
|
-
# @see
|
12
|
-
# @see
|
11
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-round
|
12
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-round
|
13
13
|
class Round < Operator::Unary
|
14
14
|
include Evaluatable
|
15
15
|
|
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
|
|
10
10
|
# (filter (sameTerm ?v)
|
11
11
|
# (bgp (triple ?x :p ?v)))))
|
12
12
|
#
|
13
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-sameTerm
|
14
14
|
class SameTerm < Operator::Binary
|
15
15
|
include Evaluatable
|
16
16
|
|
@@ -33,12 +33,15 @@ module SPARQL; module Algebra
|
|
33
33
|
##
|
34
34
|
# Returns an optimized version of this expression.
|
35
35
|
#
|
36
|
-
#
|
37
|
-
|
38
|
-
|
36
|
+
# Return true if variable operand1 is a bound variable and equals operand2
|
37
|
+
#
|
38
|
+
# @return [SameTerm] a copy of `self`
|
39
|
+
# @see SPARQL::Algebra::Expression#optimize
|
40
|
+
def optimize(**options)
|
41
|
+
if operand(0).is_a?(Variable) && operand(0).bound? && operand(0).eql?(operand(1))
|
39
42
|
RDF::Literal::TRUE
|
40
43
|
else
|
41
|
-
super # @see Operator#optimize
|
44
|
+
super # @see Operator#optimize!
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end # SameTerm
|
@@ -7,11 +7,11 @@ module SPARQL; module Algebra
|
|
7
7
|
# (prefix ((: <http://www.example.org/>))
|
8
8
|
# (filter (|| (|| (= ?sample 1.0) (= ?sample 2.2)) (= ?sample 3.5))
|
9
9
|
# (project (?sample)
|
10
|
-
# (extend ((?sample
|
11
|
-
# (group () ((
|
10
|
+
# (extend ((?sample ??.0))
|
11
|
+
# (group () ((??.0 (sample ?o)))
|
12
12
|
# (bgp (triple ?s :dec ?o)))))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/#defn_aggSample
|
15
15
|
class Sample < Operator::Unary
|
16
16
|
include Aggregate
|
17
17
|
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# (extend ((?x (seconds ?date)))
|
12
12
|
# (bgp (triple ?s :date ?date)))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-seconds
|
15
15
|
class Seconds < Operator::Unary
|
16
16
|
include Evaluatable
|
17
17
|
|
@@ -28,13 +28,12 @@ module SPARQL; module Algebra
|
|
28
28
|
# each matching solution
|
29
29
|
# @yieldparam [RDF::Query::Solution] solution
|
30
30
|
# @yieldreturn [void] ignored
|
31
|
-
# @see
|
32
|
-
def execute(queryable, options
|
31
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
32
|
+
def execute(queryable, **options, &block)
|
33
33
|
subject, object = options[:subject], options[:object]
|
34
34
|
debug(options) {"Seq #{[subject, operands, object].to_sse}"}
|
35
35
|
|
36
|
-
v = RDF::Query::Variable.new
|
37
|
-
v.distinguished = false
|
36
|
+
v = RDF::Query::Variable.new(distinguished: false)
|
38
37
|
q1 = if operand(0).is_a?(RDF::Term)
|
39
38
|
RDF::Query.new do |q|
|
40
39
|
q.pattern [subject, operand(0), v]
|
@@ -50,10 +49,10 @@ module SPARQL; module Algebra
|
|
50
49
|
operand(1)
|
51
50
|
end
|
52
51
|
|
53
|
-
left = queryable.query(q1, options.merge(object: v, depth: options[:depth].to_i + 1))
|
52
|
+
left = queryable.query(q1, **options.merge(object: v, depth: options[:depth].to_i + 1))
|
54
53
|
debug(options) {"(seq)=>(left) #{left.map(&:to_h).to_sse}"}
|
55
54
|
|
56
|
-
right = queryable.query(q2, options.merge(subject: v, depth: options[:depth].to_i + 1))
|
55
|
+
right = queryable.query(q2, **options.merge(subject: v, depth: options[:depth].to_i + 1))
|
57
56
|
debug(options) {"(seq)=>(right) #{right.map(&:to_h).to_sse}"}
|
58
57
|
|
59
58
|
@solutions = RDF::Query::Solutions(left.map do |s1|
|
@@ -34,15 +34,15 @@ module SPARQL; module Algebra
|
|
34
34
|
# each matching solution
|
35
35
|
# @yieldparam [RDF::Query::Solution] solution
|
36
36
|
# @yieldreturn [void] ignored
|
37
|
-
# @see
|
38
|
-
def execute(queryable, options
|
37
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
38
|
+
def execute(queryable, **options)
|
39
39
|
debug(options) {"Sequence #{operands.to_sse}"}
|
40
40
|
|
41
|
-
last = queryable.query(operands.shift,
|
41
|
+
last = queryable.query(operands.shift, depth: options[:depth].to_i + 1, **options)
|
42
42
|
debug(options) {"(sequence)=>(last) #{last.map(&:to_h).to_sse}"}
|
43
43
|
|
44
44
|
operands.each do |op|
|
45
|
-
this = queryable.query(op,
|
45
|
+
this = queryable.query(op, depth: options[:depth].to_i + 1, **options)
|
46
46
|
debug(options) {"(sequence)=>(this) #{this.map(&:to_h).to_sse}"}
|
47
47
|
|
48
48
|
last = last.map do |s1|
|
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
|
|
13
13
|
# (extend ((?hash (sha1 ?l)))
|
14
14
|
# (bgp (triple :s1 :str ?l)))))
|
15
15
|
#
|
16
|
-
# @see
|
16
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-sha1
|
17
17
|
class SHA1 < Operator::Unary
|
18
18
|
include Evaluatable
|
19
19
|
|
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
|
|
13
13
|
# (extend ((?hash (sha256 ?l)))
|
14
14
|
# (bgp (triple :s1 :str ?l)))))
|
15
15
|
#
|
16
|
-
# @see
|
16
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-sha256
|
17
17
|
class SHA256 < Operator::Unary
|
18
18
|
include Evaluatable
|
19
19
|
|