sparql 3.0.2 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +189 -74
- 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 +70 -44
- data/lib/sparql/algebra/extensions.rb +181 -34
- data/lib/sparql/algebra/operator.rb +44 -23
- 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 +13 -4
- data/lib/sparql/algebra/operator/base.rb +10 -10
- data/lib/sparql/algebra/operator/bgp.rb +2 -2
- 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 +19 -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 +13 -4
- data/lib/sparql/algebra/operator/md5.rb +1 -1
- data/lib/sparql/algebra/operator/min.rb +13 -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 +11 -4
- 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 +11 -17
- data/lib/sparql/grammar.rb +113 -13
- data/lib/sparql/grammar/meta.rb +2340 -907
- data/lib/sparql/grammar/parser11.rb +57 -52
- data/lib/sparql/grammar/terminals11.rb +2 -0
- data/lib/sparql/results.rb +73 -46
- data/lib/sparql/version.rb +1 -1
- metadata +46 -63
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (strbefore ?x ?y)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strbefore
|
10
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-substring-before
|
11
11
|
class StrBefore < Operator::Binary
|
12
12
|
include Evaluatable
|
13
13
|
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# (filter (langMatches (lang ?str) "en")
|
10
10
|
# (bgp (triple ?s :str ?str))))))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strdt
|
13
13
|
class StrDT < Operator::Binary
|
14
14
|
include Evaluatable
|
15
15
|
|
@@ -23,7 +23,7 @@ module SPARQL; module Algebra
|
|
23
23
|
# @param [RDF::URI] datatypeIRI
|
24
24
|
# datatype
|
25
25
|
# @return [RDF::Literal] a datatyped literal
|
26
|
-
# @see
|
26
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strdt
|
27
27
|
def apply(value, datatypeIRI)
|
28
28
|
raise TypeError, "Literal #{value.inspect} is not simple" unless value.simple?
|
29
29
|
RDF::Literal.new(value.to_s, datatype: datatypeIRI)
|
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (strends ?x ?y)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strends
|
10
|
+
# @see https://wwww.w3.org/TR/xpath-functions/#func-ends-with
|
11
11
|
class StrEnds < Operator::Binary
|
12
12
|
include Evaluatable
|
13
13
|
|
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
|
|
10
10
|
# (filter (langMatches (lang ?str) "en")
|
11
11
|
# (bgp (triple ?s :str ?str))))))
|
12
12
|
#
|
13
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strlang
|
14
14
|
class StrLang < Operator::Binary
|
15
15
|
include Evaluatable
|
16
16
|
|
@@ -24,7 +24,7 @@ module SPARQL; module Algebra
|
|
24
24
|
# @param [RDF::Literal] langTag
|
25
25
|
# datatype
|
26
26
|
# @return [RDF::Literal] a datatyped literal
|
27
|
-
# @see
|
27
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strlang
|
28
28
|
def apply(value, langTag)
|
29
29
|
raise TypeError, "Literal #{value.inspect} is not simple" unless value.simple?
|
30
30
|
RDF::Literal.new(value.to_s, language: langTag.to_s)
|
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (strlen ?x)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strlen
|
10
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-string-length
|
11
11
|
class StrLen < Operator::Unary
|
12
12
|
include Evaluatable
|
13
13
|
|
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (strstarts ?x ?y)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-strstarts
|
10
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-starts-with
|
11
11
|
class StrStarts < Operator::Binary
|
12
12
|
include Evaluatable
|
13
13
|
|
@@ -14,7 +14,7 @@ module SPARQL; module Algebra
|
|
14
14
|
# (extend ((?uuid (struuid)))
|
15
15
|
# (bgp))))))
|
16
16
|
#
|
17
|
-
# @see
|
17
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-struuid
|
18
18
|
class StrUUID < Operator::Nullary
|
19
19
|
include Evaluatable
|
20
20
|
|
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (substr ?x ?y)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-substr
|
10
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-substring
|
11
11
|
class SubStr < Operator::Ternary
|
12
12
|
include Evaluatable
|
13
13
|
|
@@ -22,7 +22,7 @@ module SPARQL; module Algebra
|
|
22
22
|
# @param [Hash{Symbol => Object}] options
|
23
23
|
# any additional options (see {Operator#initialize})
|
24
24
|
# @raise [TypeError] if any operand is invalid
|
25
|
-
def initialize(source, startingLoc, length = RDF::Literal(""), options
|
25
|
+
def initialize(source, startingLoc, length = RDF::Literal(""), **options)
|
26
26
|
super
|
27
27
|
end
|
28
28
|
|
@@ -71,7 +71,7 @@ module SPARQL; module Algebra
|
|
71
71
|
# Remove the optional argument.
|
72
72
|
#
|
73
73
|
# @return [Array] `self`
|
74
|
-
# @see
|
74
|
+
# @see https://openjena.org/wiki/SSE
|
75
75
|
def to_sxp_bin
|
76
76
|
[NAME] + operands.reject {|o| o.to_s == ""}
|
77
77
|
end
|
@@ -5,7 +5,7 @@ module SPARQL; module Algebra
|
|
5
5
|
# (- ?x ?y)
|
6
6
|
# (subtract ?x ?y)
|
7
7
|
#
|
8
|
-
# @see
|
8
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-numeric-subtract
|
9
9
|
class Subtract < Operator::Binary
|
10
10
|
include Evaluatable
|
11
11
|
|
@@ -6,12 +6,12 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (prefix ((: <http://www.example.org/>))
|
8
8
|
# (project (?sum)
|
9
|
-
# (extend ((?sum
|
10
|
-
# (group () ((
|
9
|
+
# (extend ((?sum ??.0))
|
10
|
+
# (group () ((??.0 (sum ?o)))
|
11
11
|
# (bgp (triple ?s :dec ?o))))))
|
12
12
|
#
|
13
|
-
# @see
|
14
|
-
class Sum < Operator
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#defn_aggSum
|
14
|
+
class Sum < Operator
|
15
15
|
include Aggregate
|
16
16
|
|
17
17
|
NAME = :sum
|
@@ -23,6 +23,8 @@ module SPARQL; module Algebra
|
|
23
23
|
# enum of evaluated operand
|
24
24
|
# @return [RDF::Literal::Numeric] The sum of the terms
|
25
25
|
def apply(enum)
|
26
|
+
# FIXME: we don't actually do anything with distinct
|
27
|
+
operands.shift if distinct = (operands.first == :distinct)
|
26
28
|
if enum.empty?
|
27
29
|
RDF::Literal(0)
|
28
30
|
elsif enum.flatten.all? {|n| n.is_a?(RDF::Literal::Numeric)}
|
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
|
|
13
13
|
#
|
14
14
|
# @example empty table
|
15
15
|
# (table unit)
|
16
|
-
# @see
|
16
|
+
# @see https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data
|
17
17
|
class Table < Operator
|
18
18
|
include Query
|
19
19
|
|
@@ -32,8 +32,8 @@ module SPARQL; module Algebra
|
|
32
32
|
# @yieldreturn [void] ignored
|
33
33
|
# @return [RDF::Query::Solutions]
|
34
34
|
# the resulting solution sequence
|
35
|
-
# @see
|
36
|
-
def execute(queryable, options
|
35
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
36
|
+
def execute(queryable, **options, &block)
|
37
37
|
@solutions = RDF::Query::Solutions()
|
38
38
|
Array(operands[1..-1]).each do |row|
|
39
39
|
next unless row.is_a?(Array)
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# (extend ((?x (timezone ?date)))
|
12
12
|
# (bgp (triple ?s :date ?date)))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-timezone
|
15
15
|
class Timezone < Operator::Unary
|
16
16
|
include Evaluatable
|
17
17
|
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# (extend ((?x (tz ?date)))
|
12
12
|
# (bgp (triple ?s :date ?date)))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-tz
|
15
15
|
class TZ < Operator::Unary
|
16
16
|
include Evaluatable
|
17
17
|
|
@@ -6,8 +6,8 @@ module SPARQL; module Algebra
|
|
6
6
|
# @example
|
7
7
|
# (ucase ?x)
|
8
8
|
#
|
9
|
-
# @see
|
10
|
-
# @see
|
9
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-ucase
|
10
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-ucase
|
11
11
|
class UCase < Operator::Unary
|
12
12
|
include Evaluatable
|
13
13
|
|
@@ -10,7 +10,7 @@ module SPARQL; module Algebra
|
|
10
10
|
# (graph ?g
|
11
11
|
# (bgp (triple ?s ?p ?o)))))
|
12
12
|
#
|
13
|
-
# @see
|
13
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
14
14
|
class Union < Operator::Binary
|
15
15
|
include Query
|
16
16
|
|
@@ -30,11 +30,11 @@ 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
|
debug(options) {"Union"}
|
36
36
|
@solutions = RDF::Query::Solutions(operands.inject([]) do |memo, op|
|
37
|
-
solns = op.execute(queryable,
|
37
|
+
solns = op.execute(queryable, depth: options[:depth].to_i + 1, **options)
|
38
38
|
debug(options) {"=> (op) #{solns.inspect}"}
|
39
39
|
memo + solns
|
40
40
|
end)
|
@@ -55,13 +55,14 @@ module SPARQL; module Algebra
|
|
55
55
|
end
|
56
56
|
|
57
57
|
##
|
58
|
-
#
|
58
|
+
# Optimizes this query.
|
59
59
|
#
|
60
60
|
# Optimize operands and remove any which are empty.
|
61
61
|
#
|
62
|
-
# @return [
|
63
|
-
|
64
|
-
|
62
|
+
# @return [self]
|
63
|
+
# @see SPARQL::Algebra::Expression#optimize!
|
64
|
+
def optimize!(**options)
|
65
|
+
ops = operands.map {|o| o.optimize(**options) }.select {|o| o.respond_to?(:empty?) && !o.empty?}
|
65
66
|
@operands = ops
|
66
67
|
self
|
67
68
|
end
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# (bgp (triple ?s ?p ?o))
|
10
10
|
# (insert ((triple ?s ?p "q")))))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-update/#graphUpdate
|
13
13
|
class Update < Operator
|
14
14
|
include SPARQL::Algebra::Update
|
15
15
|
|
@@ -30,12 +30,12 @@ module SPARQL; module Algebra
|
|
30
30
|
# If an attempt is made to perform an unsupported operation
|
31
31
|
# @raise [IOError]
|
32
32
|
# If `queryable` is immutable
|
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) {"Update"}
|
36
36
|
raise IOError, "queryable is not mutable" unless queryable.mutable?
|
37
37
|
operands.each do |op|
|
38
|
-
op.execute(queryable,
|
38
|
+
op.execute(queryable, depth: options[:depth].to_i + 1, **options)
|
39
39
|
end
|
40
40
|
queryable
|
41
41
|
end
|
@@ -9,7 +9,7 @@ module SPARQL; module Algebra
|
|
9
9
|
# @example
|
10
10
|
# (using (:g1) (bgp (triple ?s ?p ?o)))
|
11
11
|
#
|
12
|
-
# @see
|
12
|
+
# @see https://www.w3.org/TR/sparql11-update/#add
|
13
13
|
class Using < Operator
|
14
14
|
include SPARQL::Algebra::Query
|
15
15
|
|
@@ -30,10 +30,10 @@ 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, &block)
|
35
35
|
debug(options) {"Using"}
|
36
|
-
Dataset.new(*operands).execute(queryable,
|
36
|
+
Dataset.new(*operands).execute(queryable, depth: options[:depth].to_i + 1, **options, &block)
|
37
37
|
end
|
38
38
|
end # Using
|
39
39
|
end # Operator
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# (bgp (triple ?s ?p ?o))
|
12
12
|
# (insert ((triple ?s ?p "z"))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-update/#deleteInsert
|
15
15
|
class With < Operator
|
16
16
|
include SPARQL::Algebra::Update
|
17
17
|
|
@@ -32,17 +32,17 @@ module SPARQL; module Algebra
|
|
32
32
|
# Returns queryable.
|
33
33
|
# @raise [IOError]
|
34
34
|
# If `from` does not exist, unless the `silent` operator is present
|
35
|
-
# @see
|
36
|
-
def execute(queryable, options
|
35
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
36
|
+
def execute(queryable, **options)
|
37
37
|
debug(options) {"With: #{operand.to_sse}"}
|
38
38
|
# Bound variable
|
39
39
|
name = operands.shift
|
40
40
|
|
41
41
|
unless queryable.has_graph?(name)
|
42
42
|
debug(options) {"=> default data source #{name}"}
|
43
|
-
load_opts = {
|
43
|
+
load_opts = {logger: options.fetch(:logger, false), base_uri: name}
|
44
44
|
debug(options) {"=> load #{name}"}
|
45
|
-
queryable.load(name.to_s, load_opts)
|
45
|
+
queryable.load(name.to_s, **load_opts)
|
46
46
|
end
|
47
47
|
|
48
48
|
# Set name for RDF::Graph descendants having no graph_name to the name variable
|
@@ -58,12 +58,12 @@ module SPARQL; module Algebra
|
|
58
58
|
query = operands.shift
|
59
59
|
|
60
60
|
# Restrict query portion to this graph
|
61
|
-
queryable.query(query,
|
61
|
+
queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
|
62
62
|
debug(options) {"(solution)=>#{solution.inspect}"}
|
63
63
|
|
64
64
|
# Execute each operand with queryable and solution
|
65
65
|
operands.each do |op|
|
66
|
-
op.execute(queryable, solution,
|
66
|
+
op.execute(queryable, solutions: solution, depth: options[:depth].to_i + 1, **options)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -11,7 +11,7 @@ module SPARQL; module Algebra
|
|
11
11
|
# (extend ((?x (year ?date)))
|
12
12
|
# (bgp (triple ?s :date ?date)))))
|
13
13
|
#
|
14
|
-
# @see
|
14
|
+
# @see https://www.w3.org/TR/sparql11-query/#func-year
|
15
15
|
class Year < Operator::Unary
|
16
16
|
include Evaluatable
|
17
17
|
|
data/lib/sparql/algebra/query.rb
CHANGED
@@ -49,8 +49,8 @@ module SPARQL; module Algebra
|
|
49
49
|
# Note, results may be used with {SPARQL.serialize_results} to obtain appropriate output encoding.
|
50
50
|
# @raise [NotImplementedError]
|
51
51
|
# If an attempt is made to perform an unsupported operation
|
52
|
-
# @see
|
53
|
-
def execute(queryable, options
|
52
|
+
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
|
53
|
+
def execute(queryable, **options, &block)
|
54
54
|
raise NotImplementedError, "#{self.class}#execute(#{queryable})"
|
55
55
|
end
|
56
56
|
|
@@ -38,8 +38,8 @@ module SPARQL; module Algebra
|
|
38
38
|
# Returns the dataset.
|
39
39
|
# @raise [NotImplementedError]
|
40
40
|
# If an attempt is made to perform an unsupported operation
|
41
|
-
# @see
|
42
|
-
def execute(queryable, options
|
41
|
+
# @see https://www.w3.org/TR/sparql11-update/
|
42
|
+
def execute(queryable, **options, &block)
|
43
43
|
raise NotImplementedError, "#{self.class}#execute(#{queryable})"
|
44
44
|
end
|
45
45
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SPARQL; module Algebra
|
2
2
|
module VERSION
|
3
|
-
VERSION_FILE = File.
|
3
|
+
VERSION_FILE = File.expand_path("../../../../VERSION", __FILE__)
|
4
4
|
MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chop.split(".")
|
5
5
|
|
6
6
|
STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
|
data/lib/sparql/extensions.rb
CHANGED
@@ -25,11 +25,7 @@ module RDF::Queryable
|
|
25
25
|
#
|
26
26
|
# Used to implement the SPARQL `DESCRIBE` operator.
|
27
27
|
#
|
28
|
-
# @overload concise_bounded_description(*terms, &block)
|
29
|
-
# @param [Array<RDF::Term>] terms
|
30
|
-
# List of terms to include in the results.
|
31
|
-
#
|
32
|
-
# @overload concise_bounded_description(*terms, options, &block)
|
28
|
+
# @overload concise_bounded_description(*terms, **options, &block)
|
33
29
|
# @param [Array<RDF::Term>] terms
|
34
30
|
# List of terms to include in the results.
|
35
31
|
# @param [Hash{Symbol => Object}] options
|
@@ -43,22 +39,20 @@ module RDF::Queryable
|
|
43
39
|
# @yieldreturn [void] ignored
|
44
40
|
# @return [RDF::Graph]
|
45
41
|
#
|
46
|
-
# @see
|
47
|
-
def concise_bounded_description(*terms, &block)
|
48
|
-
options = terms.last.is_a?(Hash) ? terms.pop.dup : {}
|
49
|
-
|
42
|
+
# @see https://www.w3.org/Submission/CBD/
|
43
|
+
def concise_bounded_description(*terms, **options, &block)
|
50
44
|
graph = options[:graph] || RDF::Graph.new
|
51
45
|
|
52
46
|
if options[:non_subjects]
|
53
47
|
query_terms = terms.dup
|
54
48
|
|
55
49
|
# Find terms not in self as a subject and recurse with their subjects
|
56
|
-
terms.reject {|term| self.first(subject: term)}.each do |term|
|
57
|
-
self.query(predicate: term) do |statement|
|
50
|
+
terms.reject {|term| self.first({subject: term})}.each do |term|
|
51
|
+
self.query({predicate: term}) do |statement|
|
58
52
|
query_terms << statement.subject
|
59
53
|
end
|
60
54
|
|
61
|
-
self.query(object: term) do |statement|
|
55
|
+
self.query({object: term}) do |statement|
|
62
56
|
query_terms << statement.subject
|
63
57
|
end
|
64
58
|
end
|
@@ -67,9 +61,9 @@ module RDF::Queryable
|
|
67
61
|
end
|
68
62
|
|
69
63
|
# Don't consider term if already in graph
|
70
|
-
terms.reject {|term| graph.first(subject: term)}.each do |term|
|
64
|
+
terms.reject {|term| graph.first({subject: term})}.each do |term|
|
71
65
|
# Find statements from queryiable with term as a subject
|
72
|
-
self.query(subject: term) do |statement|
|
66
|
+
self.query({subject: term}) do |statement|
|
73
67
|
yield(statement) if block_given?
|
74
68
|
graph << statement
|
75
69
|
|
@@ -81,16 +75,16 @@ module RDF::Queryable
|
|
81
75
|
RDF.predicate => statement.predicate,
|
82
76
|
RDF.object => statement.object,
|
83
77
|
}
|
84
|
-
}).execute(self).each do |solution|
|
78
|
+
}, **{}).execute(self).each do |solution|
|
85
79
|
# Recurse to include this subject
|
86
80
|
recurse_opts = options.merge(non_subjects: false, graph: graph)
|
87
|
-
self.concise_bounded_description(solution[:s], recurse_opts, &block)
|
81
|
+
self.concise_bounded_description(solution[:s], **recurse_opts, &block)
|
88
82
|
end
|
89
83
|
|
90
84
|
# Recurse if object is a BNode and it is not already in subjects
|
91
85
|
if statement.object.node?
|
92
86
|
recurse_opts = options.merge(non_subjects: false, graph: graph)
|
93
|
-
self.concise_bounded_description(statement.object, recurse_opts, &block)
|
87
|
+
self.concise_bounded_description(statement.object, **recurse_opts, &block)
|
94
88
|
end
|
95
89
|
end
|
96
90
|
end
|