sparql-client 2.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +85 -55
- data/VERSION +1 -1
- data/lib/sparql/client.rb +132 -52
- data/lib/sparql/client/query.rb +373 -68
- data/lib/sparql/client/repository.rb +39 -15
- data/lib/sparql/client/update.rb +28 -29
- data/lib/sparql/client/version.rb +2 -2
- metadata +21 -50
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
class SPARQL::Client
|
2
2
|
##
|
3
3
|
# A read-only repository view of a SPARQL endpoint.
|
4
4
|
#
|
@@ -10,14 +10,13 @@ module SPARQL; class Client
|
|
10
10
|
##
|
11
11
|
# @param [URI, #to_s] uri
|
12
12
|
# Endpoint of this repository
|
13
|
-
# @param [String, #to_s] title (nil)
|
14
13
|
# @param [Hash{Symbol => Object}] options passed to RDF::Repository
|
15
14
|
def initialize(uri: nil, **options, &block)
|
16
15
|
raise ArgumentError, "uri is a required parameter" unless uri
|
17
16
|
@options = options.merge(uri: uri)
|
18
|
-
@update_client = SPARQL::Client.new(options.delete(:update_endpoint), options) if options[:update_endpoint]
|
19
|
-
@client = SPARQL::Client.new(uri, options)
|
20
|
-
super(
|
17
|
+
@update_client = SPARQL::Client.new(options.delete(:update_endpoint), **options) if options[:update_endpoint]
|
18
|
+
@client = SPARQL::Client.new(uri, **options)
|
19
|
+
super(**@options, &block)
|
21
20
|
end
|
22
21
|
|
23
22
|
##
|
@@ -38,6 +37,30 @@ module SPARQL; class Client
|
|
38
37
|
client.construct([:s, :p, :o]).where([:s, :p, :o]).each_statement(&block)
|
39
38
|
end
|
40
39
|
|
40
|
+
##
|
41
|
+
# Iterates the given block for each RDF statement.
|
42
|
+
#
|
43
|
+
# If no block was given, returns an enumerator.
|
44
|
+
#
|
45
|
+
# The order in which statements are yielded is undefined.
|
46
|
+
#
|
47
|
+
# @overload each_statement
|
48
|
+
# @yield [statement]
|
49
|
+
# each statement
|
50
|
+
# @yieldparam [RDF::Statement] statement
|
51
|
+
# @yieldreturn [void] ignored
|
52
|
+
# @return [void]
|
53
|
+
#
|
54
|
+
# @overload each_statement
|
55
|
+
# @return [Enumerator<RDF::Statement>]
|
56
|
+
def each_statement(&block)
|
57
|
+
if block_given?
|
58
|
+
# Invoke {#each} in the containing class:
|
59
|
+
each(&block)
|
60
|
+
end
|
61
|
+
enum_statement
|
62
|
+
end
|
63
|
+
|
41
64
|
##
|
42
65
|
# @private
|
43
66
|
# @see RDF::Enumerable#supports?
|
@@ -48,6 +71,7 @@ module SPARQL; class Client
|
|
48
71
|
when :graph_name then false
|
49
72
|
when :inference then false # forward-chaining inference
|
50
73
|
when :validity then false
|
74
|
+
when :literal_equality then true
|
51
75
|
else false
|
52
76
|
end
|
53
77
|
end
|
@@ -91,7 +115,7 @@ module SPARQL; class Client
|
|
91
115
|
# @see RDF::Repository#each_subject?
|
92
116
|
def each_subject(&block)
|
93
117
|
if block_given?
|
94
|
-
client.select(:s, :
|
118
|
+
client.select(:s, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:s]) }
|
95
119
|
end
|
96
120
|
enum_subject
|
97
121
|
end
|
@@ -105,7 +129,7 @@ module SPARQL; class Client
|
|
105
129
|
# @see RDF::Repository#each_predicate?
|
106
130
|
def each_predicate(&block)
|
107
131
|
if block_given?
|
108
|
-
client.select(:p, :
|
132
|
+
client.select(:p, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:p]) }
|
109
133
|
end
|
110
134
|
enum_predicate
|
111
135
|
end
|
@@ -119,7 +143,7 @@ module SPARQL; class Client
|
|
119
143
|
# @see RDF::Repository#each_object?
|
120
144
|
def each_object(&block)
|
121
145
|
if block_given?
|
122
|
-
client.select(:o, :
|
146
|
+
client.select(:o, distinct: true).where([:s, :p, :o]).each_solution { |solution| block.call(solution[:o]) }
|
123
147
|
end
|
124
148
|
enum_object
|
125
149
|
end
|
@@ -151,7 +175,7 @@ module SPARQL; class Client
|
|
151
175
|
# @see RDF::Repository#count?
|
152
176
|
def count
|
153
177
|
begin
|
154
|
-
binding = client.query("SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }").first.
|
178
|
+
binding = client.query("SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }").first.to_h
|
155
179
|
binding[:count].value.to_i rescue 0
|
156
180
|
rescue SPARQL::Client::MalformedQuery => e
|
157
181
|
# SPARQL 1.0 does not include support for aggregate functions:
|
@@ -238,10 +262,10 @@ module SPARQL; class Client
|
|
238
262
|
# @return [void] ignored
|
239
263
|
# @see RDF::Queryable#query
|
240
264
|
# @see RDF::Query#execute
|
241
|
-
def query_execute(query, options
|
265
|
+
def query_execute(query, **options, &block)
|
242
266
|
return nil unless block_given?
|
243
|
-
q = SPARQL::Client::Query.select(query.variables).where(*query.patterns)
|
244
|
-
client.query(q, options).each do |solution|
|
267
|
+
q = SPARQL::Client::Query.select(query.variables, **{}).where(*query.patterns)
|
268
|
+
client.query(q, **options).each do |solution|
|
245
269
|
yield solution
|
246
270
|
end
|
247
271
|
end
|
@@ -251,7 +275,7 @@ module SPARQL; class Client
|
|
251
275
|
#
|
252
276
|
# @example
|
253
277
|
# repository.query([nil, RDF::DOAP.developer, nil])
|
254
|
-
# repository.query(:
|
278
|
+
# repository.query({predicate: RDF::DOAP.developer})
|
255
279
|
#
|
256
280
|
# @todo This should use basic SPARQL query mechanism.
|
257
281
|
#
|
@@ -260,7 +284,7 @@ module SPARQL; class Client
|
|
260
284
|
# @yield [statement]
|
261
285
|
# @yieldparam [Statement]
|
262
286
|
# @return [Enumerable<Statement>]
|
263
|
-
def query_pattern(pattern, options
|
287
|
+
def query_pattern(pattern, **options, &block)
|
264
288
|
pattern = pattern.dup
|
265
289
|
pattern.subject ||= RDF::Query::Variable.new
|
266
290
|
pattern.predicate ||= RDF::Query::Variable.new
|
@@ -321,4 +345,4 @@ module SPARQL; class Client
|
|
321
345
|
end
|
322
346
|
|
323
347
|
end
|
324
|
-
end
|
348
|
+
end
|
data/lib/sparql/client/update.rb
CHANGED
@@ -12,12 +12,12 @@ class SPARQL::Client
|
|
12
12
|
# insert_data(data)
|
13
13
|
#
|
14
14
|
# @example INSERT DATA \{ GRAPH <http://example.org/> \{\}\}
|
15
|
-
# insert_data(RDF::Graph.new, :
|
15
|
+
# insert_data(RDF::Graph.new, graph: 'http://example.org/')
|
16
16
|
# insert_data(RDF::Graph.new).graph('http://example.org/')
|
17
17
|
#
|
18
18
|
# @param (see InsertData#initialize)
|
19
|
-
def self.insert_data(*arguments)
|
20
|
-
InsertData.new(*arguments)
|
19
|
+
def self.insert_data(*arguments, **options)
|
20
|
+
InsertData.new(*arguments, **options)
|
21
21
|
end
|
22
22
|
|
23
23
|
##
|
@@ -30,12 +30,12 @@ class SPARQL::Client
|
|
30
30
|
# delete_data(data)
|
31
31
|
#
|
32
32
|
# @example DELETE DATA \{ GRAPH <http://example.org/> \{\}\}
|
33
|
-
# delete_data(RDF::Graph.new, :
|
33
|
+
# delete_data(RDF::Graph.new, graph: 'http://example.org/')
|
34
34
|
# delete_data(RDF::Graph.new).graph('http://example.org/')
|
35
35
|
#
|
36
36
|
# @param (see DeleteData#initialize)
|
37
|
-
def self.delete_data(*arguments)
|
38
|
-
DeleteData.new(*arguments)
|
37
|
+
def self.delete_data(*arguments, **options)
|
38
|
+
DeleteData.new(*arguments, **options)
|
39
39
|
end
|
40
40
|
|
41
41
|
##
|
@@ -53,12 +53,12 @@ class SPARQL::Client
|
|
53
53
|
# load(RDF::URI(http://example.org/data.rdf), into: RDF::URI(http://example.org/data.rdf))
|
54
54
|
#
|
55
55
|
# @param (see Load#initialize)
|
56
|
-
def self.load(*arguments)
|
57
|
-
Load.new(*arguments)
|
56
|
+
def self.load(*arguments, **options)
|
57
|
+
Load.new(*arguments, **options)
|
58
58
|
end
|
59
59
|
|
60
60
|
##
|
61
|
-
#
|
61
|
+
# Clear the graph
|
62
62
|
#
|
63
63
|
# @example CLEAR GRAPH <http://example.org/data.rdf>
|
64
64
|
# clear.graph(RDF::URI(http://example.org/data.rdf))
|
@@ -81,8 +81,8 @@ class SPARQL::Client
|
|
81
81
|
# clear(:all, silent: true)
|
82
82
|
#
|
83
83
|
# @param (see Clear#initialize)
|
84
|
-
def self.clear(*arguments)
|
85
|
-
Clear.new(*arguments)
|
84
|
+
def self.clear(*arguments, **options)
|
85
|
+
Clear.new(*arguments, **options)
|
86
86
|
end
|
87
87
|
|
88
88
|
##
|
@@ -96,8 +96,8 @@ class SPARQL::Client
|
|
96
96
|
# create(RDF::URI(http://example.org/data.rdf), silent: true)
|
97
97
|
#
|
98
98
|
# @param (see Create#initialize)
|
99
|
-
def self.create(*arguments)
|
100
|
-
Create.new(*arguments)
|
99
|
+
def self.create(*arguments, **options)
|
100
|
+
Create.new(*arguments, **options)
|
101
101
|
end
|
102
102
|
|
103
103
|
##
|
@@ -124,15 +124,15 @@ class SPARQL::Client
|
|
124
124
|
# drop(:all, silent: true)
|
125
125
|
#
|
126
126
|
# @param (see Drop#initialize)
|
127
|
-
def self.drop(*arguments)
|
128
|
-
Drop.new(*arguments)
|
127
|
+
def self.drop(*arguments, **options)
|
128
|
+
Drop.new(*arguments, **options)
|
129
129
|
end
|
130
130
|
|
131
131
|
class Operation
|
132
132
|
attr_reader :options
|
133
133
|
|
134
|
-
def initialize(*arguments)
|
135
|
-
@options =
|
134
|
+
def initialize(*arguments, **options)
|
135
|
+
@options = options.dup
|
136
136
|
unless arguments.empty?
|
137
137
|
send(arguments.shift, *arguments)
|
138
138
|
end
|
@@ -171,9 +171,9 @@ class SPARQL::Client
|
|
171
171
|
#
|
172
172
|
# @param [Array<RDF::Statement>, RDF::Enumerable] data
|
173
173
|
# @param [Hash{Symbol => Object}] options
|
174
|
-
def initialize(data, options
|
174
|
+
def initialize(data, **options)
|
175
175
|
@data = data
|
176
|
-
super(options)
|
176
|
+
super(**options)
|
177
177
|
end
|
178
178
|
|
179
179
|
##
|
@@ -221,9 +221,9 @@ class SPARQL::Client
|
|
221
221
|
#
|
222
222
|
# @param [Array<RDF::Statement>, RDF::Enumerable] data
|
223
223
|
# @param [Hash{Symbol => Object}] options
|
224
|
-
def initialize(data, options
|
224
|
+
def initialize(data, **options)
|
225
225
|
@data = data
|
226
|
-
super(options)
|
226
|
+
super(**options)
|
227
227
|
end
|
228
228
|
|
229
229
|
##
|
@@ -253,11 +253,11 @@ class SPARQL::Client
|
|
253
253
|
attr_reader :delete_graph
|
254
254
|
attr_reader :where_graph
|
255
255
|
|
256
|
-
def initialize(_delete_graph, _insert_graph = nil, _where_graph = nil, options
|
256
|
+
def initialize(_delete_graph, _insert_graph = nil, _where_graph = nil, **options)
|
257
257
|
@delete_graph = _delete_graph
|
258
258
|
@insert_graph = _insert_graph
|
259
259
|
@where_graph = _where_graph
|
260
|
-
super(options)
|
260
|
+
super(**options)
|
261
261
|
end
|
262
262
|
|
263
263
|
##
|
@@ -324,11 +324,10 @@ class SPARQL::Client
|
|
324
324
|
# @param [Hash{Symbol => Object}] options
|
325
325
|
# @option [RDF::URI] :into
|
326
326
|
# @option [Boolean] :silent
|
327
|
-
def initialize(from, options
|
328
|
-
options = options.dup
|
327
|
+
def initialize(from, into: nil,**options)
|
329
328
|
@from = RDF::URI(from)
|
330
|
-
@into = RDF::URI(
|
331
|
-
super(options)
|
329
|
+
@into = RDF::URI(into) if into
|
330
|
+
super(**options)
|
332
331
|
end
|
333
332
|
|
334
333
|
##
|
@@ -420,9 +419,9 @@ class SPARQL::Client
|
|
420
419
|
attr_reader :uri
|
421
420
|
|
422
421
|
# @param [Hash{Symbol => Object}] options
|
423
|
-
def initialize(uri, options
|
422
|
+
def initialize(uri, **options)
|
424
423
|
@uri = RDF::URI(uri)
|
425
|
-
super(options)
|
424
|
+
super(**options)
|
426
425
|
end
|
427
426
|
|
428
427
|
def to_s
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
class SPARQL::Client
|
2
2
|
module VERSION
|
3
3
|
FILE = File.expand_path('../../../../VERSION', __FILE__)
|
4
4
|
MAJOR, MINOR, TINY, EXTRA = File.read(FILE).chomp.split('.')
|
@@ -16,4 +16,4 @@ module SPARQL; class Client
|
|
16
16
|
# @return [Array(Integer, Integer, Integer)]
|
17
17
|
def self.to_a() [MAJOR, MINOR, TINY] end
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparql-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-12-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rdf
|
@@ -18,140 +18,112 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: '3.1'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: net-http-persistent
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
35
|
+
version: '3.1'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: sparql
|
45
|
-
requirement: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '2.0'
|
50
|
-
type: :development
|
51
|
-
prerelease: false
|
52
|
-
version_requirements: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - "~>"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '2.0'
|
42
|
+
version: '3.1'
|
57
43
|
- !ruby/object:Gem::Dependency
|
58
44
|
name: rdf-spec
|
59
45
|
requirement: !ruby/object:Gem::Requirement
|
60
46
|
requirements:
|
61
47
|
- - "~>"
|
62
48
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
49
|
+
version: '3.1'
|
64
50
|
type: :development
|
65
51
|
prerelease: false
|
66
52
|
version_requirements: !ruby/object:Gem::Requirement
|
67
53
|
requirements:
|
68
54
|
- - "~>"
|
69
55
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
56
|
+
version: '3.1'
|
71
57
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
73
|
-
requirement: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - "~>"
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '2.0'
|
78
|
-
type: :development
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - "~>"
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '2.0'
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: rack
|
58
|
+
name: sparql
|
87
59
|
requirement: !ruby/object:Gem::Requirement
|
88
60
|
requirements:
|
89
61
|
- - "~>"
|
90
62
|
- !ruby/object:Gem::Version
|
91
|
-
version: '1
|
63
|
+
version: '3.1'
|
92
64
|
type: :development
|
93
65
|
prerelease: false
|
94
66
|
version_requirements: !ruby/object:Gem::Requirement
|
95
67
|
requirements:
|
96
68
|
- - "~>"
|
97
69
|
- !ruby/object:Gem::Version
|
98
|
-
version: '1
|
70
|
+
version: '3.1'
|
99
71
|
- !ruby/object:Gem::Dependency
|
100
72
|
name: rspec
|
101
73
|
requirement: !ruby/object:Gem::Requirement
|
102
74
|
requirements:
|
103
75
|
- - "~>"
|
104
76
|
- !ruby/object:Gem::Version
|
105
|
-
version: '3.
|
77
|
+
version: '3.9'
|
106
78
|
type: :development
|
107
79
|
prerelease: false
|
108
80
|
version_requirements: !ruby/object:Gem::Requirement
|
109
81
|
requirements:
|
110
82
|
- - "~>"
|
111
83
|
- !ruby/object:Gem::Version
|
112
|
-
version: '3.
|
84
|
+
version: '3.9'
|
113
85
|
- !ruby/object:Gem::Dependency
|
114
86
|
name: rspec-its
|
115
87
|
requirement: !ruby/object:Gem::Requirement
|
116
88
|
requirements:
|
117
89
|
- - "~>"
|
118
90
|
- !ruby/object:Gem::Version
|
119
|
-
version: '1.
|
91
|
+
version: '1.3'
|
120
92
|
type: :development
|
121
93
|
prerelease: false
|
122
94
|
version_requirements: !ruby/object:Gem::Requirement
|
123
95
|
requirements:
|
124
96
|
- - "~>"
|
125
97
|
- !ruby/object:Gem::Version
|
126
|
-
version: '1.
|
98
|
+
version: '1.3'
|
127
99
|
- !ruby/object:Gem::Dependency
|
128
100
|
name: webmock
|
129
101
|
requirement: !ruby/object:Gem::Requirement
|
130
102
|
requirements:
|
131
103
|
- - "~>"
|
132
104
|
- !ruby/object:Gem::Version
|
133
|
-
version: '
|
105
|
+
version: '3.7'
|
134
106
|
type: :development
|
135
107
|
prerelease: false
|
136
108
|
version_requirements: !ruby/object:Gem::Requirement
|
137
109
|
requirements:
|
138
110
|
- - "~>"
|
139
111
|
- !ruby/object:Gem::Version
|
140
|
-
version: '
|
112
|
+
version: '3.7'
|
141
113
|
- !ruby/object:Gem::Dependency
|
142
114
|
name: yard
|
143
115
|
requirement: !ruby/object:Gem::Requirement
|
144
116
|
requirements:
|
145
117
|
- - "~>"
|
146
118
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
119
|
+
version: 0.9.20
|
148
120
|
type: :development
|
149
121
|
prerelease: false
|
150
122
|
version_requirements: !ruby/object:Gem::Requirement
|
151
123
|
requirements:
|
152
124
|
- - "~>"
|
153
125
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
126
|
+
version: 0.9.20
|
155
127
|
description: |-
|
156
128
|
Executes SPARQL queries and updates against a remote SPARQL 1.0 or 1.1 endpoint,
|
157
129
|
or against a local repository. Generates SPARQL queries using a simple DSL.
|
@@ -184,15 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
156
|
requirements:
|
185
157
|
- - ">="
|
186
158
|
- !ruby/object:Gem::Version
|
187
|
-
version: '2.
|
159
|
+
version: '2.4'
|
188
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
161
|
requirements:
|
190
162
|
- - ">="
|
191
163
|
- !ruby/object:Gem::Version
|
192
164
|
version: '0'
|
193
165
|
requirements: []
|
194
|
-
|
195
|
-
rubygems_version: 2.5.1
|
166
|
+
rubygems_version: 3.0.6
|
196
167
|
signing_key:
|
197
168
|
specification_version: 4
|
198
169
|
summary: SPARQL client for RDF.rb.
|