sparql 3.0.1 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +188 -73
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/bin/sparql +44 -24
- 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 +17 -16
- 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 +63 -40
- data/lib/sparql/algebra/extensions.rb +180 -33
- 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 +6 -17
- 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 +9 -7
- data/lib/sparql/algebra/operator/delete_data.rb +3 -3
- data/lib/sparql/algebra/operator/delete_where.rb +6 -6
- 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 +2 -2
- 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 +19 -18
- 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 +6 -17
- 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 +7 -5
- 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 +3 -3
- 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 +9 -8
- 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 +7 -7
- 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 +2340 -907
- data/lib/sparql/grammar/parser11.rb +69 -69
- data/lib/sparql/grammar/terminals11.rb +2 -0
- data/lib/sparql/results.rb +73 -46
- data/lib/sparql/version.rb +1 -1
- metadata +38 -65
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (contains ?x ?y)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-contains
|
10
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-contains
|
11
11
|
class Contains < Operator::Binary
|
12
12
|
include Evaluatable
|
13
13
|
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# @example
|
10
10
|
# (copy silent <iri> to default)
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-update/#copy
|
13
13
|
class Copy < Operator
|
14
14
|
include SPARQL::Algebra::Update
|
15
15
|
|
@@ -28,8 +28,8 @@ 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
|
32
|
-
def execute(queryable, options
|
31
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
32
|
+
def execute(queryable, **options)
|
33
33
|
debug(options) {"Copy"}
|
34
34
|
silent = operands.first == :silent
|
35
35
|
operands.shift if silent
|
@@ -6,11 +6,11 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (prefix ((: <http://www.example.org>))
|
8
8
|
# (project (?C)
|
9
|
-
# (extend ((?C
|
10
|
-
# (group () ((
|
9
|
+
# (extend ((?C ??.0))
|
10
|
+
# (group () ((??.0 (count ?O)))
|
11
11
|
# (bgp (triple ?S ?P ?O))))))
|
12
12
|
#
|
13
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#defn_aggCount
|
14
14
|
class Count < Operator
|
15
15
|
include Aggregate
|
16
16
|
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# @example
|
12
12
|
# (create silent <graph>)
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-update/#create
|
15
15
|
class Create < Operator
|
16
16
|
include SPARQL::Algebra::Update
|
17
17
|
|
@@ -30,8 +30,8 @@ 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
|
34
|
-
def execute(queryable, options
|
33
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
34
|
+
def execute(queryable, **options)
|
35
35
|
debug(options) {"Create"}
|
36
36
|
silent = operands.first == :silent
|
37
37
|
operands.shift if silent
|
@@ -102,7 +102,7 @@ module SPARQL; module Algebra
|
|
102
102
|
# (graph ?g (bgp (triple ?s ?p ?o))))))
|
103
103
|
#
|
104
104
|
# @example Dataset with multiple named graphs
|
105
|
-
# @see
|
105
|
+
# @see https://www.w3.org/TR/sparql11-query/#specifyingDataset
|
106
106
|
class Dataset < Binary
|
107
107
|
include Query
|
108
108
|
|
@@ -125,8 +125,8 @@ module SPARQL; module Algebra
|
|
125
125
|
# @yieldreturn [void] ignored
|
126
126
|
# @return [RDF::Query::Solutions]
|
127
127
|
# the resulting solution sequence
|
128
|
-
# @see
|
129
|
-
def execute(queryable, options
|
128
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
129
|
+
def execute(queryable, **options, &base)
|
130
130
|
debug(options) {"Dataset"}
|
131
131
|
default_datasets = []
|
132
132
|
named_datasets = []
|
@@ -141,10 +141,10 @@ module SPARQL; module Algebra
|
|
141
141
|
debug(options) {"=> default data source #{uri}"}
|
142
142
|
default_datasets << uri
|
143
143
|
end
|
144
|
-
load_opts = {
|
144
|
+
load_opts = {logger: options.fetch(:logger, false), graph_name: uri, base_uri: uri}
|
145
145
|
unless queryable.has_graph?(uri)
|
146
146
|
debug(options) {"=> load #{uri}"}
|
147
|
-
queryable.load(uri.to_s, load_opts)
|
147
|
+
queryable.load(uri.to_s, **load_opts)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
debug(options) {
|
@@ -156,18 +156,7 @@ module SPARQL; module Algebra
|
|
156
156
|
aggregate = RDF::AggregateRepo.new(queryable)
|
157
157
|
named_datasets.each {|name| aggregate.named(name) if queryable.has_graph?(name)}
|
158
158
|
aggregate.default(*default_datasets.select {|name| queryable.has_graph?(name)})
|
159
|
-
aggregate.query(operands.last,
|
160
|
-
end
|
161
|
-
|
162
|
-
##
|
163
|
-
# Returns an optimized version of this query.
|
164
|
-
#
|
165
|
-
# If optimize operands, and if the first two operands are both Queries, replace
|
166
|
-
# with the unique sum of the query elements
|
167
|
-
#
|
168
|
-
# @return [Union, RDF::Query] `self`
|
169
|
-
def optimize
|
170
|
-
operands.last.optimize
|
159
|
+
aggregate.query(operands.last, depth: options[:depth].to_i + 1, **options, &base)
|
171
160
|
end
|
172
161
|
end # Dataset
|
173
162
|
end # Operator
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# (filter (= (datatype (xsd:double ?v)) xsd:double)
|
12
12
|
# (bgp (triple ?s :p ?v)))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-datatype
|
15
15
|
class Datatype < Operator::Unary
|
16
16
|
include Evaluatable
|
17
17
|
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# (extend ((?x (day ?date)))
|
10
10
|
# (bgp (triple ?s :date ?date)))))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-day
|
13
13
|
class Day < Operator::Unary
|
14
14
|
include Evaluatable
|
15
15
|
|
@@ -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,9 +30,11 @@ 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
|
34
|
-
def execute(queryable,
|
35
|
-
debug(options) {"Delete: #{
|
33
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
34
|
+
def execute(queryable, solutions: nil, **options)
|
35
|
+
debug(options) {"Delete: #{solutions} against #{operands.to_sse}"}
|
36
|
+
# Only binds the first solution
|
37
|
+
solution = solutions.is_a?(RDF::Query::Solutions) ? solutions.first : solutions
|
36
38
|
# Operands are an array of patterns and Queries (when named).
|
37
39
|
# Create a new query made up all patterns
|
38
40
|
patterns = operand.inject([]) do |memo, op|
|
@@ -45,7 +47,7 @@ module SPARQL; module Algebra
|
|
45
47
|
end
|
46
48
|
patterns.each do |pattern|
|
47
49
|
pattern = pattern.dup.bind(solution)
|
48
|
-
debug(options) {"Delete
|
50
|
+
debug(options) {"Delete pattern #{pattern.to_sse}"}
|
49
51
|
queryable.delete(RDF::Statement.from(pattern)) if pattern.bound? || pattern.constant?
|
50
52
|
end
|
51
53
|
queryable
|
@@ -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,8 +28,8 @@ 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
|
32
|
-
def execute(queryable, options
|
31
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
32
|
+
def execute(queryable, **options)
|
33
33
|
operand.each do |op|
|
34
34
|
debug(options) {"DeleteData #{op.to_sxp}"}
|
35
35
|
queryable.delete(op)
|
@@ -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,8 +28,8 @@ 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
|
32
|
-
def execute(queryable, options
|
31
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
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
|
35
35
|
patterns = operand.inject([]) do |memo, op|
|
@@ -40,13 +40,13 @@ module SPARQL; module Algebra
|
|
40
40
|
end
|
41
41
|
memo
|
42
42
|
end
|
43
|
-
query = RDF::Query.new(*patterns, {}) # FIXME: added hash argument needed until Statement#to_hash removed.
|
43
|
+
query = RDF::Query.new(*patterns, **{}) # FIXME: added hash argument needed until Statement#to_hash removed.
|
44
44
|
debug(options) {"DeleteWhere query #{query.to_sse}"}
|
45
|
-
query.execute(queryable,
|
45
|
+
query.execute(queryable, depth: options[:depth].to_i + 1, **options) do |solution|
|
46
46
|
debug(options) {"DeleteWhere solution #{solution.to_sse}"}
|
47
47
|
query.each_statement do |pattern|
|
48
48
|
pattern = pattern.dup.bind(solution)
|
49
|
-
debug(options) {"DeleteWhere
|
49
|
+
debug(options) {"DeleteWhere pattern #{pattern.to_sse}"}
|
50
50
|
queryable.delete(RDF::Statement.from(pattern)) if pattern.bound? || pattern.constant?
|
51
51
|
end
|
52
52
|
end
|
@@ -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,8 +39,8 @@ module SPARQL; module Algebra
|
|
39
39
|
# @yieldreturn [void] ignored
|
40
40
|
# @return [RDF::Graph]
|
41
41
|
# containing the constructed triples
|
42
|
-
# @see
|
43
|
-
def execute(queryable, options
|
42
|
+
# @see https://www.w3.org/TR/sparql11-query/#describe
|
43
|
+
def execute(queryable, **options, &block)
|
44
44
|
debug(options) {"Describe #{operands.first}, #{options.inspect}"}
|
45
45
|
|
46
46
|
# Describe any constand URIs
|
@@ -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
|
34
|
-
def execute(queryable, options
|
35
|
-
@solutions = queryable.query(operands.last,
|
33
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
34
|
+
def execute(queryable, **options, &block)
|
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,8 +30,8 @@ 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
|
34
|
-
def execute(queryable, options
|
33
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
34
|
+
def execute(queryable, **options)
|
35
35
|
debug(options) {"Drop"}
|
36
36
|
silent = operands.first == :silent
|
37
37
|
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
|
|
@@ -29,7 +29,7 @@ module SPARQL; module Algebra
|
|
29
29
|
# @raise [TypeError] if the operand is not a literal value
|
30
30
|
def apply(operand)
|
31
31
|
case operand
|
32
|
-
when RDF::Literal then RDF::Literal(
|
32
|
+
when RDF::Literal then RDF::Literal(CGI.escape(operand.to_s))
|
33
33
|
else raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}"
|
34
34
|
end
|
35
35
|
end
|
@@ -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
|
|
@@ -26,11 +26,11 @@ module SPARQL; module Algebra
|
|
26
26
|
# @option options[RDF::Queryable] queryable
|
27
27
|
# queryable to execute, using bindings as an initial solution.
|
28
28
|
# @return [RDF::Literal::Boolean] `true` or `false`
|
29
|
-
def evaluate(bindings, options
|
29
|
+
def evaluate(bindings, **options)
|
30
30
|
queryable = options[:queryable]
|
31
|
-
!operand(0).execute(queryable,
|
32
|
-
|
33
|
-
|
31
|
+
!operand(0).execute(queryable, solutions: RDF::Query::Solutions(bindings),
|
32
|
+
depth: options[:depth].to_i + 1,
|
33
|
+
**options).empty?
|
34
34
|
end
|
35
35
|
end # Exists
|
36
36
|
end # Operator
|
@@ -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
|
|
@@ -36,20 +36,10 @@ module SPARQL; module Algebra
|
|
36
36
|
# options passed from query
|
37
37
|
# @return [RDF::Literal::Boolean] `true` or `false`
|
38
38
|
# @raise [TypeError] if the operands could not be coerced to a boolean literal
|
39
|
-
def evaluate(bindings, options
|
40
|
-
res = operands.all? {|op| boolean(op.evaluate(bindings,
|
39
|
+
def evaluate(bindings, **options)
|
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,19 +44,24 @@ module SPARQL; module Algebra
|
|
38
44
|
# @yieldreturn [void] ignored
|
39
45
|
# @return [RDF::Query::Solutions]
|
40
46
|
# the resulting solution sequence
|
41
|
-
# @see
|
42
|
-
def execute(queryable, options
|
47
|
+
# @see https://www.w3.org/TR/sparql11-query/#evaluation
|
48
|
+
def execute(queryable, **options, &block)
|
43
49
|
debug(options) {"Extend"}
|
44
|
-
@solutions = operand(1).execute(queryable,
|
50
|
+
@solutions = operand(1).execute(queryable, depth: options[:depth].to_i + 1, **options)
|
45
51
|
@solutions.each do |solution|
|
46
52
|
debug(options) {"===> soln #{solution.to_h.inspect}"}
|
47
53
|
operand(0).each do |(var, expr)|
|
48
54
|
begin
|
49
|
-
val = expr.evaluate(solution,
|
50
|
-
|
51
|
-
|
55
|
+
val = expr.evaluate(solution, queryable: queryable,
|
56
|
+
depth: options[:depth].to_i + 1,
|
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
|