sparql 1.1.9.1 → 1.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/sinatra/sparql.rb +5 -5
- data/lib/sparql/algebra/expression.rb +1 -1
- data/lib/sparql/algebra/extensions.rb +10 -43
- data/lib/sparql/algebra/operator/add.rb +1 -1
- data/lib/sparql/algebra/operator/bgp.rb +3 -3
- data/lib/sparql/algebra/operator/clear.rb +3 -3
- data/lib/sparql/algebra/operator/copy.rb +2 -2
- data/lib/sparql/algebra/operator/create.rb +1 -1
- data/lib/sparql/algebra/operator/dataset.rb +4 -4
- data/lib/sparql/algebra/operator/drop.rb +3 -3
- data/lib/sparql/algebra/operator/filter.rb +1 -1
- data/lib/sparql/algebra/operator/graph.rb +7 -8
- data/lib/sparql/algebra/operator/load.rb +1 -1
- data/lib/sparql/algebra/operator/move.rb +2 -2
- data/lib/sparql/algebra/operator/path.rb +1 -1
- data/lib/sparql/algebra/operator/with.rb +6 -6
- data/lib/sparql/algebra/operator.rb +2 -2
- data/lib/sparql/algebra/query.rb +4 -4
- data/lib/sparql/algebra/update.rb +3 -3
- data/lib/sparql/grammar/parser11.rb +46 -14
- data/lib/sparql.rb +4 -4
- metadata +2 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e189418bc1c955e9fe52f7f43c5ae7cbb6f4ece
|
4
|
+
data.tar.gz: 24ea48aaf680166acce769a030f83313bd6c9bc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3490effdaf0bb46eb1f85b2971b92dd3b94167073f962abc430dde19dfe0e25bca03f05d9fcb9cacc08bc00a0752cd4ed32d3678f61f816b2fcd6fc4f453bb22
|
7
|
+
data.tar.gz: f28f4674050da2bb575f5134e479eaf86472153dac106d1908c281e9df72e94144916b4bde0aeafa10ba29c93a712ae166ae0e316a1972bcbe50c5416a5a0feb
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.99.0
|
data/lib/sinatra/sparql.rb
CHANGED
@@ -60,16 +60,16 @@ module Sinatra
|
|
60
60
|
|
61
61
|
# Contexts
|
62
62
|
if repository.is_a?(RDF::Enumerable)
|
63
|
-
|
63
|
+
graph_names = {}
|
64
64
|
repository.each do |statement|
|
65
|
-
|
66
|
-
|
65
|
+
graph_names[statement.graph_name] ||= 0
|
66
|
+
graph_names[statement.graph_name] += 1
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
graph_names.each do |name, count|
|
70
70
|
bn = RDF::Node.new
|
71
71
|
if name
|
72
|
-
# Add named
|
72
|
+
# Add named graphs as namedGraphs
|
73
73
|
g << [ds, sd.join("#namedGraph"), bn]
|
74
74
|
g << [bn, RDF.type, sd.join("#NamedGraph")]
|
75
75
|
g << [bn, sd.join("#name"), name]
|
@@ -86,8 +86,8 @@ class Array
|
|
86
86
|
# Does this contain any nodes?
|
87
87
|
#
|
88
88
|
# @return [Boolean]
|
89
|
-
def
|
90
|
-
any?(&:
|
89
|
+
def node?
|
90
|
+
any?(&:node?)
|
91
91
|
end
|
92
92
|
def evaluatable?; true; end
|
93
93
|
def executable?; false; end
|
@@ -197,40 +197,6 @@ module RDF::Term
|
|
197
197
|
|
198
198
|
def aggregate?; false; end
|
199
199
|
|
200
|
-
# Term compatibility according to SPARQL
|
201
|
-
#
|
202
|
-
# Compatibility of two arguments is defined as:
|
203
|
-
# * The arguments are simple literals or literals typed as xsd:string
|
204
|
-
# * The arguments are plain literals with identical language tags
|
205
|
-
# * The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
|
206
|
-
#
|
207
|
-
# @example
|
208
|
-
# compatible?("abc" "b") #=> true
|
209
|
-
# compatible?("abc" "b"^^xsd:string) #=> true
|
210
|
-
# compatible?("abc"^^xsd:string "b") #=> true
|
211
|
-
# compatible?("abc"^^xsd:string "b"^^xsd:string) #=> true
|
212
|
-
# compatible?("abc"@en "b") #=> true
|
213
|
-
# compatible?("abc"@en "b"^^xsd:string) #=> true
|
214
|
-
# compatible?("abc"@en "b"@en) #=> true
|
215
|
-
# compatible?("abc"@fr "b"@ja) #=> false
|
216
|
-
# compatible?("abc" "b"@ja) #=> false
|
217
|
-
# compatible?("abc" "b"@en) #=> false
|
218
|
-
# compatible?("abc"^^xsd:string "b"@en) #=> false
|
219
|
-
#
|
220
|
-
# @see http://www.w3.org/TR/sparql11-query/#func-arg-compatibility
|
221
|
-
def compatible?(other)
|
222
|
-
return false unless literal? && other.literal? && plain? && other.plain?
|
223
|
-
|
224
|
-
dtr = other.datatype
|
225
|
-
|
226
|
-
# * The arguments are simple literals or literals typed as xsd:string
|
227
|
-
# * The arguments are plain literals with identical language tags
|
228
|
-
# * The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
|
229
|
-
has_language? ?
|
230
|
-
(language == other.language || dtr == RDF::XSD.string) :
|
231
|
-
dtr == RDF::XSD.string
|
232
|
-
end
|
233
|
-
|
234
200
|
##
|
235
201
|
# Return the non-destinguished variables contained within this operator
|
236
202
|
# @return [Array<RDF::Query::Variable>]
|
@@ -299,8 +265,8 @@ class RDF::Statement
|
|
299
265
|
# Transform Statement Pattern into an SXP
|
300
266
|
# @return [Array]
|
301
267
|
def to_sxp_bin
|
302
|
-
if
|
303
|
-
[:quad, subject, predicate, object,
|
268
|
+
if has_graph?
|
269
|
+
[:quad, subject, predicate, object, graph_name]
|
304
270
|
else
|
305
271
|
[:triple, subject, predicate, object]
|
306
272
|
end
|
@@ -313,7 +279,8 @@ class RDF::Query
|
|
313
279
|
# Same Context
|
314
280
|
# @return [Boolean]
|
315
281
|
def ==(other)
|
316
|
-
|
282
|
+
# FIXME: this should be graph_name == other.graph_name
|
283
|
+
other.is_a?(RDF::Query) && patterns == other.patterns && graph_name == graph_name
|
317
284
|
end
|
318
285
|
|
319
286
|
##
|
@@ -332,10 +299,10 @@ class RDF::Query
|
|
332
299
|
# @return [Array]
|
333
300
|
def to_sxp_bin
|
334
301
|
if options[:as_container]
|
335
|
-
[:graph,
|
302
|
+
[:graph, graph_name] + [patterns.map(&:to_sxp_bin)]
|
336
303
|
else
|
337
304
|
res = [:bgp] + patterns.map(&:to_sxp_bin)
|
338
|
-
(
|
305
|
+
(graph_name ? [:graph, graph_name, res] : res)
|
339
306
|
end
|
340
307
|
end
|
341
308
|
|
@@ -376,8 +343,8 @@ class RDF::Query::Pattern
|
|
376
343
|
# Transform Query Pattern into an SXP
|
377
344
|
# @return [Array]
|
378
345
|
def to_sxp_bin
|
379
|
-
if
|
380
|
-
[:quad, subject, predicate, object,
|
346
|
+
if has_graph?
|
347
|
+
[:quad, subject, predicate, object, graph_name]
|
381
348
|
else
|
382
349
|
[:triple, subject, predicate, object]
|
383
350
|
end
|
@@ -45,7 +45,7 @@ module SPARQL; module Algebra
|
|
45
45
|
else
|
46
46
|
src.each do |statement|
|
47
47
|
statement = statement.dup
|
48
|
-
statement.
|
48
|
+
statement.graph_name = (dest_name unless dest_name == :default)
|
49
49
|
queryable << statement
|
50
50
|
end
|
51
51
|
end
|
@@ -3,7 +3,7 @@ module SPARQL; module Algebra
|
|
3
3
|
##
|
4
4
|
# The SPARQL GraphPattern `bgp` operator.
|
5
5
|
#
|
6
|
-
# Query with `
|
6
|
+
# Query with `graph_name` set to false.
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
# (prefix ((: <http://example/>))
|
@@ -13,7 +13,7 @@ module SPARQL; module Algebra
|
|
13
13
|
class BGP < Operator
|
14
14
|
NAME = [:bgp]
|
15
15
|
##
|
16
|
-
# A `graph` is an RDF::Query with a
|
16
|
+
# A `graph` is an RDF::Query with a graph_name.
|
17
17
|
#
|
18
18
|
# @overload self.new(*patterns)
|
19
19
|
# @param [Array<RDF::Query::Pattern>] patterns
|
@@ -23,7 +23,7 @@ module SPARQL; module Algebra
|
|
23
23
|
# @yieldreturn [void] ignored
|
24
24
|
# @return [RDF::Query]
|
25
25
|
def self.new(*patterns, &block)
|
26
|
-
RDF::Query.new(*(patterns + [{
|
26
|
+
RDF::Query.new(*(patterns + [{graph_name: false}]), &block)
|
27
27
|
end
|
28
28
|
end # BGP
|
29
29
|
end # Operator
|
@@ -38,16 +38,16 @@ module SPARQL; module Algebra
|
|
38
38
|
case operands.last
|
39
39
|
when :default
|
40
40
|
queryable.each_graph do |g|
|
41
|
-
g.clear! unless g.
|
41
|
+
g.clear! unless g.graph_name
|
42
42
|
end
|
43
43
|
when :named
|
44
44
|
queryable.each_graph do |g|
|
45
|
-
g.clear! if g.
|
45
|
+
g.clear! if g.graph_name
|
46
46
|
end
|
47
47
|
when :all
|
48
48
|
queryable.clear!
|
49
49
|
when RDF::URI
|
50
|
-
if g = queryable.each_graph.detect {|c| c.
|
50
|
+
if g = queryable.each_graph.detect {|c| c.graph_name == operands.last}
|
51
51
|
g.clear!
|
52
52
|
else
|
53
53
|
raise IOError, "clear operation graph does not exist" unless silent
|
@@ -50,10 +50,10 @@ module SPARQL; module Algebra
|
|
50
50
|
# Clear destination first
|
51
51
|
dest.clear! if dest
|
52
52
|
|
53
|
-
# Copy statements using destination
|
53
|
+
# Copy statements using destination graph_name
|
54
54
|
src.each do |statement|
|
55
55
|
statement = statement.dup
|
56
|
-
statement.
|
56
|
+
statement.graph_name = (dest_name unless dest_name == :default)
|
57
57
|
queryable << statement
|
58
58
|
end
|
59
59
|
end
|
@@ -38,7 +38,7 @@ module SPARQL; module Algebra
|
|
38
38
|
|
39
39
|
iri = operands.first
|
40
40
|
raise ArgumentError, "clear expected a single IRI" if operands.length != 1 || !iri.is_a?(RDF::URI)
|
41
|
-
if queryable.
|
41
|
+
if queryable.has_graph?(iri)
|
42
42
|
raise IOError, "create operation graph #{iri.to_ntriples} exists" unless silent
|
43
43
|
end
|
44
44
|
queryable
|
@@ -141,8 +141,8 @@ module SPARQL; module Algebra
|
|
141
141
|
debug(options) {"=> default data source #{uri}"}
|
142
142
|
default_datasets << uri
|
143
143
|
end
|
144
|
-
load_opts = {debug: options.fetch(:debug, nil),
|
145
|
-
unless queryable.
|
144
|
+
load_opts = {debug: options.fetch(:debug, nil), graph_name: uri, base_uri: uri}
|
145
|
+
unless queryable.has_graph?(uri)
|
146
146
|
debug(options) {"=> load #{uri}"}
|
147
147
|
queryable.load(uri.to_s, load_opts)
|
148
148
|
end
|
@@ -154,8 +154,8 @@ module SPARQL; module Algebra
|
|
154
154
|
|
155
155
|
# Create an aggregate based on queryable having just the bits we want
|
156
156
|
aggregate = RDF::AggregateRepo.new(queryable)
|
157
|
-
named_datasets.each {|name| aggregate.named(name) if queryable.
|
158
|
-
aggregate.default(*default_datasets.select {|name| queryable.
|
157
|
+
named_datasets.each {|name| aggregate.named(name) if queryable.has_graph?(name)}
|
158
|
+
aggregate.default(*default_datasets.select {|name| queryable.has_graph?(name)})
|
159
159
|
aggregate.query(operands.last, options.merge(depth: options[:depth].to_i + 1), &base)
|
160
160
|
end
|
161
161
|
|
@@ -41,16 +41,16 @@ module SPARQL; module Algebra
|
|
41
41
|
case operands.last
|
42
42
|
when :default
|
43
43
|
queryable.each_graph do |g|
|
44
|
-
g.clear! unless g.
|
44
|
+
g.clear! unless g.graph_name
|
45
45
|
end
|
46
46
|
when :named
|
47
47
|
queryable.each_graph do |g|
|
48
|
-
g.clear! if g.
|
48
|
+
g.clear! if g.graph_name
|
49
49
|
end
|
50
50
|
when :all
|
51
51
|
queryable.clear!
|
52
52
|
when RDF::URI
|
53
|
-
if g = queryable.each_graph.detect {|c| c.
|
53
|
+
if g = queryable.each_graph.detect {|c| c.graph_name == operands.last}
|
54
54
|
g.clear!
|
55
55
|
else
|
56
56
|
raise IOError, "drop operation graph does not exist" unless silent
|
@@ -64,7 +64,7 @@ module SPARQL; module Algebra
|
|
64
64
|
def validate!
|
65
65
|
unless (join = operands.last).is_a?(Join) &&
|
66
66
|
join.operands.all? {|op| op.is_a?(RDF::Query)} &&
|
67
|
-
join.operands.map(&:
|
67
|
+
join.operands.map(&:graph_name).uniq.length == 1
|
68
68
|
operands.last.validate!
|
69
69
|
end
|
70
70
|
self
|
@@ -1,10 +1,9 @@
|
|
1
|
-
# FIXME: This depends on an update to RDF::Query#execute to be able to pass the context as an option.
|
2
1
|
module SPARQL; module Algebra
|
3
2
|
class Operator
|
4
3
|
##
|
5
4
|
# The SPARQL GraphPattern `graph` operator.
|
6
5
|
#
|
7
|
-
# This is a wrapper to add a `
|
6
|
+
# This is a wrapper to add a `graph_name` to the query, or an array of statements.
|
8
7
|
#
|
9
8
|
# @example of a query
|
10
9
|
# (prefix ((: <http://example/>))
|
@@ -22,7 +21,7 @@ module SPARQL; module Algebra
|
|
22
21
|
|
23
22
|
NAME = [:graph]
|
24
23
|
##
|
25
|
-
# A `graph` is an RDF::Query with a
|
24
|
+
# A `graph` is an RDF::Query with a graph_name. It can also be used as a container of statements or patterns, or other queryable operators (see GraphGraphPattern)
|
26
25
|
#
|
27
26
|
# @overload self.new(name, bgp)
|
28
27
|
# @param [RDF::Resource] name
|
@@ -41,18 +40,18 @@ module SPARQL; module Algebra
|
|
41
40
|
case patterns
|
42
41
|
when RDF::Query
|
43
42
|
# Record that the argument as a (bgp) for re-serialization back to SSE
|
44
|
-
RDF::Query.new(*(patterns.patterns + [{
|
43
|
+
RDF::Query.new(*(patterns.patterns + [{graph_name: name,}]), &block)
|
45
44
|
when Operator
|
46
45
|
super
|
47
46
|
else
|
48
|
-
RDF::Query.new(*(patterns + [{
|
47
|
+
RDF::Query.new(*(patterns + [{graph_name: name, as_container: true}]), &block)
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
51
|
##
|
53
52
|
# If the second operand is a Query operator:
|
54
53
|
# Executes this query on the given `queryable` graph or repository.
|
55
|
-
# Applies the given `
|
54
|
+
# Applies the given `graph_name` to the query, limiting the scope of the query to the specified `graph`, which may be an `RDF::URI` or `RDF::Query::Variable`.
|
56
55
|
#
|
57
56
|
# @param [RDF::Queryable] queryable
|
58
57
|
# the graph or repository to query
|
@@ -67,8 +66,8 @@ module SPARQL; module Algebra
|
|
67
66
|
# @see http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
|
68
67
|
def execute(queryable, options = {}, &block)
|
69
68
|
debug(options) {"Graph #{operands.first}"}
|
70
|
-
|
71
|
-
@solutions = queryable.query(query, options.merge(
|
69
|
+
graph_name, query = operands.first, operands.last
|
70
|
+
@solutions = queryable.query(query, options.merge(graph_name: graph_name), &block)
|
72
71
|
end
|
73
72
|
|
74
73
|
##
|
@@ -37,7 +37,7 @@ module SPARQL; module Algebra
|
|
37
37
|
raise ArgumentError, "load expected one or two operands, got #{operands.length}" unless [1,2].include?(operands.length)
|
38
38
|
|
39
39
|
location, name = operands
|
40
|
-
queryable.load(location,
|
40
|
+
queryable.load(location, graph_name: name)
|
41
41
|
rescue IOError, Errno::ENOENT
|
42
42
|
raise unless silent
|
43
43
|
ensure
|
@@ -50,10 +50,10 @@ module SPARQL; module Algebra
|
|
50
50
|
# Clear destination first
|
51
51
|
dest.clear! if dest
|
52
52
|
|
53
|
-
# Copy statements using destination
|
53
|
+
# Copy statements using destination graph
|
54
54
|
src.each do |statement|
|
55
55
|
statement = statement.dup
|
56
|
-
statement.
|
56
|
+
statement.graph_name = (dest_name unless dest_name == :default)
|
57
57
|
queryable << statement
|
58
58
|
end
|
59
59
|
|
@@ -34,7 +34,7 @@ module SPARQL; module Algebra
|
|
34
34
|
path_op.execute(queryable, options.merge(
|
35
35
|
subject: subject,
|
36
36
|
object: object,
|
37
|
-
|
37
|
+
graph_name: options.fetch(:graph_name, false),
|
38
38
|
depth: options[:depth].to_i + 1)
|
39
39
|
) do |solution|
|
40
40
|
@solutions << solution
|
@@ -20,7 +20,7 @@ module SPARQL; module Algebra
|
|
20
20
|
##
|
21
21
|
# Executes this upate on the given `writable` graph or repository.
|
22
22
|
#
|
23
|
-
# Effectively filters results by setting a default `
|
23
|
+
# Effectively filters results by setting a default `__graph_name__` variable so that it is used when binding to perform update operations on the appropriate triples.
|
24
24
|
#
|
25
25
|
# @param [RDF::Queryable] queryable
|
26
26
|
# the graph or repository to write
|
@@ -38,20 +38,20 @@ module SPARQL; module Algebra
|
|
38
38
|
# Bound variable
|
39
39
|
name = operands.shift
|
40
40
|
|
41
|
-
unless queryable.
|
41
|
+
unless queryable.has_graph?(name)
|
42
42
|
debug(options) {"=> default data source #{name}"}
|
43
43
|
load_opts = {debug: options.fetch(:debug, nil), base_uri: name}
|
44
44
|
debug(options) {"=> load #{name}"}
|
45
45
|
queryable.load(name.to_s, load_opts)
|
46
46
|
end
|
47
47
|
|
48
|
-
# Set name for RDF::Graph descendants having no
|
48
|
+
# Set name for RDF::Graph descendants having no graph_name to the name variable
|
49
49
|
each_descendant do |op|
|
50
50
|
case op
|
51
51
|
when RDF::Query, RDF::Query::Pattern
|
52
|
-
unless op.
|
53
|
-
debug(options) {"set
|
54
|
-
op.
|
52
|
+
unless op.graph_name
|
53
|
+
debug(options) {"set graph_name on #{op.to_sse}"}
|
54
|
+
op.graph_name = RDF::Query::Variable.new(:__graph_name__, name)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -442,9 +442,9 @@ module SPARQL; module Algebra
|
|
442
442
|
# otherwise.
|
443
443
|
#
|
444
444
|
# @return [Boolean]
|
445
|
-
def
|
445
|
+
def node?
|
446
446
|
operands.any? do |operand|
|
447
|
-
operand.respond_to?(:
|
447
|
+
operand.respond_to?(:node?) ? operand.node? : operand.node?
|
448
448
|
end
|
449
449
|
end
|
450
450
|
|
data/lib/sparql/algebra/query.rb
CHANGED
@@ -40,7 +40,7 @@ module SPARQL; module Algebra
|
|
40
40
|
# any additional keyword options
|
41
41
|
# @option options [Boolean] debug
|
42
42
|
# Query execution debugging
|
43
|
-
# @option options [RDF::Term, RDF::Query::Variable] :
|
43
|
+
# @option options [RDF::Term, RDF::Query::Variable] :graph_name
|
44
44
|
# @yield [solution]
|
45
45
|
# each matching solution, statement or boolean
|
46
46
|
# @yieldparam [RDF::Statement, RDF::Query::Solution, Boolean] solution
|
@@ -54,12 +54,12 @@ module SPARQL; module Algebra
|
|
54
54
|
raise NotImplementedError, "#{self.class}#execute(#{queryable})"
|
55
55
|
end
|
56
56
|
|
57
|
-
# Add
|
57
|
+
# Add graph_name to sub-items, unless they already have a graph_name
|
58
58
|
# @param [RDF::URI, RDF::Query::Variable] value
|
59
59
|
# @return [RDF::URI, RDF::Query::Variable]
|
60
|
-
def
|
60
|
+
def graph_name=(value)
|
61
61
|
operands.each do |operand|
|
62
|
-
operand.
|
62
|
+
operand.graph_name = value if operand.respond_to?(:graph_name) && operand.graph_name != false
|
63
63
|
end
|
64
64
|
value
|
65
65
|
end
|
@@ -43,12 +43,12 @@ module SPARQL; module Algebra
|
|
43
43
|
raise NotImplementedError, "#{self.class}#execute(#{queryable})"
|
44
44
|
end
|
45
45
|
|
46
|
-
# Add
|
46
|
+
# Add graph_name to sub-items, unless they already have a graph_name
|
47
47
|
# @param [RDF::URI, RDF::Query::Variable] value
|
48
48
|
# @return [RDF::URI, RDF::Query::Variable]
|
49
|
-
def
|
49
|
+
def graph_name=(value)
|
50
50
|
operands.each do |operand|
|
51
|
-
operand.
|
51
|
+
operand.graph_name = value if operand.respond_to?(:graph_name) && operand.graph_name != false
|
52
52
|
end
|
53
53
|
value
|
54
54
|
end
|
@@ -476,28 +476,39 @@ module SPARQL::Grammar
|
|
476
476
|
end
|
477
477
|
|
478
478
|
# [38] InsertData ::= "INSERT DATA" QuadData
|
479
|
+
start_production(:InsertData) do |input, data, callback|
|
480
|
+
# Freeze existing bnodes, so that if an attempt is made to re-use such a node, and error is raised
|
481
|
+
self.freeze_bnodes
|
482
|
+
end
|
479
483
|
production(:InsertData) do |input, data, callback|
|
480
484
|
input[:update_op] = SPARQL::Algebra::Expression(:insertData, data[:pattern])
|
481
485
|
end
|
482
486
|
|
483
487
|
# [39] DeleteData ::= "DELETE DATA" QuadData
|
488
|
+
start_production(:DeleteData) do |input, data, callback|
|
489
|
+
# Generate BNodes instead of non-distinguished variables. BNodes are not legal, but this will generate them rather than non-distinguished variables so they can be detected.
|
490
|
+
self.gen_bnodes
|
491
|
+
end
|
484
492
|
production(:DeleteData) do |input, data, callback|
|
485
|
-
raise Error, "DeleteData contains BNode operands: #{data[:pattern].to_sse}" if data[:pattern].first.
|
493
|
+
raise Error, "DeleteData contains BNode operands: #{data[:pattern].to_sse}" if data[:pattern].first.node?
|
486
494
|
input[:update_op] = SPARQL::Algebra::Expression(:deleteData, data[:pattern])
|
487
495
|
end
|
488
496
|
|
489
497
|
# [40] DeleteWhere ::= "DELETE WHERE" QuadPattern
|
490
498
|
start_production(:DeleteWhere) do |input, data, callback|
|
491
499
|
# Generate BNodes instead of non-distinguished variables. BNodes are not legal, but this will generate them rather than non-distinguished variables so they can be detected.
|
492
|
-
self.
|
500
|
+
self.gen_bnodes
|
493
501
|
end
|
494
502
|
production(:DeleteWhere) do |input, data, callback|
|
495
|
-
raise Error, "DeleteWhere contains BNode operands: #{data[:pattern].to_sse}" if data[:pattern].first.
|
496
|
-
self.
|
503
|
+
raise Error, "DeleteWhere contains BNode operands: #{data[:pattern].to_sse}" if data[:pattern].first.node?
|
504
|
+
self.gen_bnodes(false)
|
497
505
|
input[:update_op] = SPARQL::Algebra::Expression(:deleteWhere, data[:pattern])
|
498
506
|
end
|
499
507
|
|
500
508
|
# [41] Modify ::= ("WITH" iri)? ( DeleteClause InsertClause? | InsertClause) UsingClause* "WHERE" GroupGraphPattern
|
509
|
+
start_production(:Modify) do |input, data, callback|
|
510
|
+
self.clear_bnode_cache
|
511
|
+
end
|
501
512
|
production(:Modify) do |input, data, callback|
|
502
513
|
query = data[:query].first if data[:query]
|
503
514
|
query = SPARQL::Algebra::Expression.for(:using, data[:using], query) if data[:using]
|
@@ -509,16 +520,21 @@ module SPARQL::Grammar
|
|
509
520
|
# [42] DeleteClause ::= "DELETE" QuadPattern
|
510
521
|
start_production(:DeleteClause) do |input, data, callback|
|
511
522
|
# Generate BNodes instead of non-distinguished variables. BNodes are not legal, but this will generate them rather than non-distinguished variables so they can be detected.
|
512
|
-
self.
|
523
|
+
self.gen_bnodes
|
513
524
|
end
|
514
525
|
production(:DeleteClause) do |input, data, callback|
|
515
|
-
raise Error, "DeleteClause contains BNode operands: #{data[:pattern].to_sse}" if data[:pattern].first.
|
516
|
-
self.
|
526
|
+
raise Error, "DeleteClause contains BNode operands: #{data[:pattern].to_sse}" if data[:pattern].first.node?
|
527
|
+
self.gen_bnodes(false)
|
517
528
|
input[:delete] = SPARQL::Algebra::Expression(:delete, data[:pattern])
|
518
529
|
end
|
519
530
|
|
520
531
|
# [43] InsertClause ::= "INSERT" QuadPattern
|
532
|
+
start_production(:InsertClause) do |input, data, callback|
|
533
|
+
# Generate BNodes instead of non-distinguished variables.
|
534
|
+
self.gen_bnodes
|
535
|
+
end
|
521
536
|
production(:InsertClause) do |input, data, callback|
|
537
|
+
self.gen_bnodes(false)
|
522
538
|
input[:insert] = SPARQL::Algebra::Expression(:insert, data[:pattern])
|
523
539
|
end
|
524
540
|
|
@@ -548,13 +564,13 @@ module SPARQL::Grammar
|
|
548
564
|
# QuadData is like QuadPattern, except without BNodes
|
549
565
|
start_production(:QuadData) do |input, data, callback|
|
550
566
|
# Generate BNodes instead of non-distinguished variables
|
551
|
-
self.
|
567
|
+
self.gen_bnodes
|
552
568
|
end
|
553
569
|
production(:QuadData) do |input, data, callback|
|
554
570
|
# Transform using statements instead of patterns, and verify there are no variables
|
555
571
|
raise Error, "QuadData empty" unless data[:pattern]
|
556
572
|
raise Error, "QuadData contains variable operands: #{data[:pattern].to_sse}" if data[:pattern].first.variable?
|
557
|
-
self.
|
573
|
+
self.gen_bnodes(false)
|
558
574
|
input[:pattern] = data[:pattern]
|
559
575
|
end
|
560
576
|
|
@@ -783,11 +799,11 @@ module SPARQL::Grammar
|
|
783
799
|
# [73] ConstructTemplate ::= '{' ConstructTriples? '}'
|
784
800
|
start_production(:ConstructTemplate) do |input, data, callback|
|
785
801
|
# Generate BNodes instead of non-distinguished variables
|
786
|
-
self.
|
802
|
+
self.gen_bnodes
|
787
803
|
end
|
788
804
|
production(:ConstructTemplate) do |input, data, callback|
|
789
805
|
# Generate BNodes instead of non-distinguished variables
|
790
|
-
self.
|
806
|
+
self.gen_bnodes(false)
|
791
807
|
add_prod_datum(:ConstructTemplate, data[:pattern])
|
792
808
|
add_prod_datum(:ConstructTemplate, data[:ConstructTemplate])
|
793
809
|
end
|
@@ -1637,12 +1653,26 @@ module SPARQL::Grammar
|
|
1637
1653
|
# Used for generating BNode labels
|
1638
1654
|
attr_accessor :nd_var_gen
|
1639
1655
|
|
1640
|
-
#
|
1656
|
+
# Generate BNodes, not non-distinguished variables
|
1657
|
+
# @param [Boolean] value
|
1658
|
+
# @return [void]
|
1659
|
+
def gen_bnodes(value = true)
|
1660
|
+
@nd_var_gen = value ? false : "0"
|
1661
|
+
end
|
1662
|
+
|
1663
|
+
# Clear cached BNodes
|
1664
|
+
# @return [void]
|
1641
1665
|
def clear_bnode_cache
|
1642
|
-
@nd_var_gen = false
|
1643
1666
|
@bnode_cache = {}
|
1644
1667
|
end
|
1645
1668
|
|
1669
|
+
# Freeze BNodes, which allows us to detect if they're re-used
|
1670
|
+
# @return [void]
|
1671
|
+
def freeze_bnodes
|
1672
|
+
@bnode_cache ||= {}
|
1673
|
+
@bnode_cache.each_value(&:freeze)
|
1674
|
+
end
|
1675
|
+
|
1646
1676
|
# Generate a BNode identifier
|
1647
1677
|
def bnode(id = nil)
|
1648
1678
|
if @nd_var_gen
|
@@ -1653,7 +1683,9 @@ module SPARQL::Grammar
|
|
1653
1683
|
id = @options[:anon_base]
|
1654
1684
|
@options[:anon_base] = @options[:anon_base].succ
|
1655
1685
|
end
|
1656
|
-
|
1686
|
+
@bnode_cache ||= {}
|
1687
|
+
raise Error, "Illegal attempt to reuse a BNode" if @bnode_cache[id] && @bnode_cache[id].frozen?
|
1688
|
+
@bnode_cache[id] ||= RDF::Node.new(id)
|
1657
1689
|
end
|
1658
1690
|
end
|
1659
1691
|
|
data/lib/sparql.rb
CHANGED
@@ -55,11 +55,11 @@ module SPARQL
|
|
55
55
|
# @param [Hash{Symbol => Object}] options
|
56
56
|
# @option options [RDF::Queryable] :queryable
|
57
57
|
# @option options [RDF::URI, String, Array<RDF::URI, String>] :load_datasets
|
58
|
-
# One or more URIs used to initialize a new instance of `queryable` in the default
|
58
|
+
# One or more URIs used to initialize a new instance of `queryable` in the default graph.
|
59
59
|
# @option options [RDF::URI, String, Array<RDF::URI, String>] :default_graph_uri
|
60
|
-
# One or more URIs used to initialize a new instance of `queryable` in the default
|
60
|
+
# One or more URIs used to initialize a new instance of `queryable` in the default graph.
|
61
61
|
# @option options [RDF::URI, String, Array<RDF::URI, String>] :named_graph_uri
|
62
|
-
# One or more URIs used to initialize the `queryable` as a named
|
62
|
+
# One or more URIs used to initialize the `queryable` as a named graph.
|
63
63
|
# @yield [solution]
|
64
64
|
# each matching solution, statement or boolean
|
65
65
|
# @yieldparam [RDF::Statement, RDF::Query::Solution, Boolean] solution
|
@@ -84,7 +84,7 @@ module SPARQL
|
|
84
84
|
queryable.load(uri)
|
85
85
|
end
|
86
86
|
[options[:named_graph_uri]].flatten.each do |uri|
|
87
|
-
queryable.load(uri,
|
87
|
+
queryable.load(uri, graph_name: uri)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
query.execute(queryable, &block)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.99.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
@@ -9,19 +9,13 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdf
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.1'
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.1.13
|
24
|
-
- - "<"
|
25
19
|
- !ruby/object:Gem::Version
|
26
20
|
version: '1.99'
|
27
21
|
type: :runtime
|
@@ -29,12 +23,6 @@ dependencies:
|
|
29
23
|
version_requirements: !ruby/object:Gem::Requirement
|
30
24
|
requirements:
|
31
25
|
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.1'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 1.1.13
|
37
|
-
- - "<"
|
38
26
|
- !ruby/object:Gem::Version
|
39
27
|
version: '1.99'
|
40
28
|
- !ruby/object:Gem::Dependency
|
@@ -42,12 +30,6 @@ dependencies:
|
|
42
30
|
requirement: !ruby/object:Gem::Requirement
|
43
31
|
requirements:
|
44
32
|
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '1.1'
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 1.1.0
|
50
|
-
- - "<"
|
51
33
|
- !ruby/object:Gem::Version
|
52
34
|
version: '1.99'
|
53
35
|
type: :runtime
|
@@ -55,12 +37,6 @@ dependencies:
|
|
55
37
|
version_requirements: !ruby/object:Gem::Requirement
|
56
38
|
requirements:
|
57
39
|
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '1.1'
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 1.1.0
|
63
|
-
- - "<"
|
64
40
|
- !ruby/object:Gem::Version
|
65
41
|
version: '1.99'
|
66
42
|
- !ruby/object:Gem::Dependency
|
@@ -112,9 +88,6 @@ dependencies:
|
|
112
88
|
- - "~>"
|
113
89
|
- !ruby/object:Gem::Version
|
114
90
|
version: '1.1'
|
115
|
-
- - "<"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '1.99'
|
118
91
|
type: :runtime
|
119
92
|
prerelease: false
|
120
93
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,9 +95,6 @@ dependencies:
|
|
122
95
|
- - "~>"
|
123
96
|
- !ruby/object:Gem::Version
|
124
97
|
version: '1.1'
|
125
|
-
- - "<"
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: '1.99'
|
128
98
|
- !ruby/object:Gem::Dependency
|
129
99
|
name: rdf-xsd
|
130
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,9 +102,6 @@ dependencies:
|
|
132
102
|
- - "~>"
|
133
103
|
- !ruby/object:Gem::Version
|
134
104
|
version: '1.1'
|
135
|
-
- - "<"
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '1.99'
|
138
105
|
type: :runtime
|
139
106
|
prerelease: false
|
140
107
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -142,9 +109,6 @@ dependencies:
|
|
142
109
|
- - "~>"
|
143
110
|
- !ruby/object:Gem::Version
|
144
111
|
version: '1.1'
|
145
|
-
- - "<"
|
146
|
-
- !ruby/object:Gem::Version
|
147
|
-
version: '1.99'
|
148
112
|
- !ruby/object:Gem::Dependency
|
149
113
|
name: sinatra
|
150
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,9 +164,6 @@ dependencies:
|
|
200
164
|
- - "~>"
|
201
165
|
- !ruby/object:Gem::Version
|
202
166
|
version: '1.1'
|
203
|
-
- - "<"
|
204
|
-
- !ruby/object:Gem::Version
|
205
|
-
version: '1.99'
|
206
167
|
type: :development
|
207
168
|
prerelease: false
|
208
169
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -210,17 +171,11 @@ dependencies:
|
|
210
171
|
- - "~>"
|
211
172
|
- !ruby/object:Gem::Version
|
212
173
|
version: '1.1'
|
213
|
-
- - "<"
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
version: '1.99'
|
216
174
|
- !ruby/object:Gem::Dependency
|
217
175
|
name: rdf-spec
|
218
176
|
requirement: !ruby/object:Gem::Requirement
|
219
177
|
requirements:
|
220
178
|
- - "~>"
|
221
|
-
- !ruby/object:Gem::Version
|
222
|
-
version: '1.1'
|
223
|
-
- - "<"
|
224
179
|
- !ruby/object:Gem::Version
|
225
180
|
version: '1.99'
|
226
181
|
type: :development
|
@@ -228,9 +183,6 @@ dependencies:
|
|
228
183
|
version_requirements: !ruby/object:Gem::Requirement
|
229
184
|
requirements:
|
230
185
|
- - "~>"
|
231
|
-
- !ruby/object:Gem::Version
|
232
|
-
version: '1.1'
|
233
|
-
- - "<"
|
234
186
|
- !ruby/object:Gem::Version
|
235
187
|
version: '1.99'
|
236
188
|
- !ruby/object:Gem::Dependency
|