dpla-sparql-client 1.1.3.2.pre.dpla.1
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 +7 -0
- data/AUTHORS +3 -0
- data/CREDITS +12 -0
- data/README +166 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/lib/sparql/client.rb +730 -0
- data/lib/sparql/client/query.rb +412 -0
- data/lib/sparql/client/repository.rb +302 -0
- data/lib/sparql/client/update.rb +293 -0
- data/lib/sparql/client/version.rb +19 -0
- metadata +172 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
class SPARQL::Client
|
|
2
|
+
##
|
|
3
|
+
# SPARQL 1.1 Update operation builders.
|
|
4
|
+
module Update
|
|
5
|
+
def self.insert_data(*arguments)
|
|
6
|
+
InsertData.new(*arguments)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.delete_data(*arguments)
|
|
10
|
+
DeleteData.new(*arguments)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.load(*arguments)
|
|
14
|
+
Load.new(*arguments)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.clear(*arguments)
|
|
18
|
+
Clear.new(*arguments)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.create(*arguments)
|
|
22
|
+
Create.new(*arguments)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.drop(*arguments)
|
|
26
|
+
Drop.new(*arguments)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Operation
|
|
30
|
+
attr_reader :options
|
|
31
|
+
|
|
32
|
+
def initialize(*arguments)
|
|
33
|
+
@options = arguments.last.is_a?(Hash) ? arguments.pop.dup : {}
|
|
34
|
+
unless arguments.empty?
|
|
35
|
+
send(arguments.shift, *arguments)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# Generic Update always returns statements
|
|
41
|
+
#
|
|
42
|
+
# @return expects_statements?
|
|
43
|
+
def expects_statements?
|
|
44
|
+
true
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def silent
|
|
48
|
+
self.options[:silent] = true
|
|
49
|
+
self
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
##
|
|
54
|
+
# @see http://www.w3.org/TR/sparql11-update/#insertData
|
|
55
|
+
class InsertData < Operation
|
|
56
|
+
attr_reader :data
|
|
57
|
+
|
|
58
|
+
def initialize(data, options = {})
|
|
59
|
+
@data = data
|
|
60
|
+
super(options)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def graph(uri)
|
|
64
|
+
self.options[:graph] = uri
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# InsertData always returns result set
|
|
70
|
+
#
|
|
71
|
+
# @return expects_statements?
|
|
72
|
+
def expects_statements?
|
|
73
|
+
false
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def to_s
|
|
77
|
+
query_text = 'INSERT DATA {'
|
|
78
|
+
query_text += ' GRAPH ' + SPARQL::Client.serialize_uri(self.options[:graph]) + ' {' if self.options[:graph]
|
|
79
|
+
query_text += "\n"
|
|
80
|
+
query_text += RDF::NTriples::Writer.buffer { |writer| @data.each { |d| writer << d } }
|
|
81
|
+
query_text += '}' if self.options[:graph]
|
|
82
|
+
query_text += "}\n"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
##
|
|
87
|
+
# @see http://www.w3.org/TR/sparql11-update/#deleteData
|
|
88
|
+
class DeleteData < Operation
|
|
89
|
+
attr_reader :data
|
|
90
|
+
|
|
91
|
+
def initialize(data, options = {})
|
|
92
|
+
@data = data
|
|
93
|
+
super(options)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def graph(uri)
|
|
97
|
+
self.options[:graph] = uri
|
|
98
|
+
self
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def to_s
|
|
102
|
+
query_text = 'DELETE DATA {'
|
|
103
|
+
query_text += ' GRAPH ' + SPARQL::Client.serialize_uri(self.options[:graph]) + ' {' if self.options[:graph]
|
|
104
|
+
query_text += "\n"
|
|
105
|
+
query_text += RDF::NTriples::Writer.buffer { |writer| @data.each { |d| writer << d } }
|
|
106
|
+
query_text += '}' if self.options[:graph]
|
|
107
|
+
query_text += "}\n"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
##
|
|
112
|
+
# @see http://www.w3.org/TR/sparql11-update/#deleteInsert
|
|
113
|
+
class DeleteInsert < Operation
|
|
114
|
+
attr_reader :insert_graph
|
|
115
|
+
attr_reader :delete_graph
|
|
116
|
+
attr_reader :where_graph
|
|
117
|
+
|
|
118
|
+
def initialize(_delete_graph, _insert_graph = nil, _where_graph = nil, options = {})
|
|
119
|
+
@delete_graph = _delete_graph
|
|
120
|
+
@insert_graph = _insert_graph
|
|
121
|
+
@where_graph = _where_graph
|
|
122
|
+
super(options)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def graph(uri)
|
|
126
|
+
self.options[:graph] = uri
|
|
127
|
+
self
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def to_s
|
|
131
|
+
buffer = []
|
|
132
|
+
|
|
133
|
+
if self.options[:graph]
|
|
134
|
+
buffer << "WITH"
|
|
135
|
+
buffer << SPARQL::Client.serialize_uri(self.options[:graph])
|
|
136
|
+
end
|
|
137
|
+
if delete_graph and !delete_graph.empty?
|
|
138
|
+
serialized_delete = SPARQL::Client.serialize_patterns delete_graph, true
|
|
139
|
+
buffer << "DELETE {\n"
|
|
140
|
+
buffer += serialized_delete
|
|
141
|
+
buffer << "}\n"
|
|
142
|
+
end
|
|
143
|
+
if insert_graph and !insert_graph.empty?
|
|
144
|
+
buffer << "INSERT {\n"
|
|
145
|
+
buffer += SPARQL::Client.serialize_patterns insert_graph, true
|
|
146
|
+
buffer << "}\n"
|
|
147
|
+
end
|
|
148
|
+
buffer << "WHERE {\n"
|
|
149
|
+
if where_graph
|
|
150
|
+
buffer += SPARQL::Client.serialize_patterns where_graph, true
|
|
151
|
+
elsif serialized_delete
|
|
152
|
+
buffer += serialized_delete
|
|
153
|
+
end
|
|
154
|
+
buffer << "}\n"
|
|
155
|
+
buffer.join(' ')
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
##
|
|
161
|
+
# @see http://www.w3.org/TR/sparql11-update/#load
|
|
162
|
+
class Load < Operation
|
|
163
|
+
attr_reader :from
|
|
164
|
+
attr_reader :into
|
|
165
|
+
|
|
166
|
+
def initialize(from, options = {})
|
|
167
|
+
options = options.dup
|
|
168
|
+
@from = RDF::URI(from)
|
|
169
|
+
@into = RDF::URI(options.delete(:into)) if options[:into]
|
|
170
|
+
super(options)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def into(url)
|
|
174
|
+
@into = RDF::URI(url)
|
|
175
|
+
self
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def to_s
|
|
179
|
+
query_text = 'LOAD '
|
|
180
|
+
query_text += 'SILENT ' if self.options[:silent]
|
|
181
|
+
query_text += SPARQL::Client.serialize_uri(@from)
|
|
182
|
+
query_text += ' INTO GRAPH ' + SPARQL::Client.serialize_uri(@into) if @into
|
|
183
|
+
query_text
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
##
|
|
188
|
+
# @see http://www.w3.org/TR/sparql11-update/#clear
|
|
189
|
+
class Clear < Operation
|
|
190
|
+
attr_reader :uri
|
|
191
|
+
|
|
192
|
+
def graph(uri)
|
|
193
|
+
@what, @uri = :graph, uri
|
|
194
|
+
self
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def default
|
|
198
|
+
@what = :default
|
|
199
|
+
self
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def named
|
|
203
|
+
@what = :named
|
|
204
|
+
self
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def all
|
|
208
|
+
@what = :all
|
|
209
|
+
self
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
##
|
|
213
|
+
# Clear always returns statements
|
|
214
|
+
#
|
|
215
|
+
# @return expects_statements?
|
|
216
|
+
def expects_statements?
|
|
217
|
+
false
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def to_s
|
|
221
|
+
query_text = 'CLEAR '
|
|
222
|
+
query_text += 'SILENT ' if self.options[:silent]
|
|
223
|
+
case @what.to_sym
|
|
224
|
+
when :graph then query_text += 'GRAPH ' + SPARQL::Client.serialize_uri(@uri)
|
|
225
|
+
when :default then query_text += 'DEFAULT'
|
|
226
|
+
when :named then query_text += 'NAMED'
|
|
227
|
+
when :all then query_text += 'ALL'
|
|
228
|
+
else raise ArgumentError, "invalid CLEAR operation: #{@what.inspect}"
|
|
229
|
+
end
|
|
230
|
+
query_text
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
##
|
|
235
|
+
# @see http://www.w3.org/TR/sparql11-update/#create
|
|
236
|
+
class Create < Operation
|
|
237
|
+
attr_reader :uri
|
|
238
|
+
|
|
239
|
+
def initialize(uri, options = {})
|
|
240
|
+
@uri = RDF::URI(uri)
|
|
241
|
+
super(options)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def to_s
|
|
245
|
+
query_text = 'CREATE '
|
|
246
|
+
query_text += 'SILENT ' if self.options[:silent]
|
|
247
|
+
query_text += 'GRAPH ' + SPARQL::Client.serialize_uri(@uri)
|
|
248
|
+
query_text
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
##
|
|
253
|
+
# @see http://www.w3.org/TR/sparql11-update/#drop
|
|
254
|
+
class Drop < Clear
|
|
255
|
+
def to_s
|
|
256
|
+
query_text = 'DROP '
|
|
257
|
+
query_text += 'SILENT ' if self.options[:silent]
|
|
258
|
+
case @what.to_sym
|
|
259
|
+
when :graph then query_text += 'GRAPH ' + SPARQL::Client.serialize_uri(@uri)
|
|
260
|
+
when :default then query_text += 'DEFAULT'
|
|
261
|
+
when :named then query_text += 'NAMED'
|
|
262
|
+
when :all then query_text += 'ALL'
|
|
263
|
+
else raise ArgumentError, "invalid DROP operation: #{@what.inspect}"
|
|
264
|
+
end
|
|
265
|
+
query_text
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
##
|
|
270
|
+
# @see http://www.w3.org/TR/sparql11-update/#copy
|
|
271
|
+
class Copy < Operation
|
|
272
|
+
def to_s
|
|
273
|
+
# TODO
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
##
|
|
278
|
+
# @see http://www.w3.org/TR/sparql11-update/#move
|
|
279
|
+
class Move < Operation
|
|
280
|
+
def to_s
|
|
281
|
+
# TODO
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
##
|
|
286
|
+
# @see http://www.w3.org/TR/sparql11-update/#add
|
|
287
|
+
class Add < Operation
|
|
288
|
+
def to_s
|
|
289
|
+
# TODO
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end # Update
|
|
293
|
+
end # SPARQL::Client
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module SPARQL; class Client
|
|
2
|
+
module VERSION
|
|
3
|
+
FILE = File.expand_path('../../../../VERSION', __FILE__)
|
|
4
|
+
MAJOR, MINOR, TINY, EXTRA = File.read(FILE).chomp.split('.')
|
|
5
|
+
STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.').freeze
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# @return [String]
|
|
9
|
+
def self.to_s() STRING end
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# @return [String]
|
|
13
|
+
def self.to_str() STRING end
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# @return [Array(Integer, Integer, Integer)]
|
|
17
|
+
def self.to_a() [MAJOR, MINOR, TINY] end
|
|
18
|
+
end
|
|
19
|
+
end; end
|
metadata
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dpla-sparql-client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.3.2.pre.dpla.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Arto Bendiken
|
|
8
|
+
- Ben Lavender
|
|
9
|
+
- Gregg Kellogg
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: rdf
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
requirements:
|
|
19
|
+
- - "~>"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.1'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '1.1'
|
|
29
|
+
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: net-http-persistent
|
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - "~>"
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '2.9'
|
|
36
|
+
type: :runtime
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - "~>"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '2.9'
|
|
43
|
+
- !ruby/object:Gem::Dependency
|
|
44
|
+
name: sparql
|
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - "~>"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '1.1'
|
|
50
|
+
type: :development
|
|
51
|
+
prerelease: false
|
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - "~>"
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '1.1'
|
|
57
|
+
- !ruby/object:Gem::Dependency
|
|
58
|
+
name: rdf-spec
|
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - "~>"
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '1.1'
|
|
64
|
+
type: :development
|
|
65
|
+
prerelease: false
|
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - "~>"
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '1.1'
|
|
71
|
+
- !ruby/object:Gem::Dependency
|
|
72
|
+
name: rspec
|
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - "~>"
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '3.0'
|
|
78
|
+
type: :development
|
|
79
|
+
prerelease: false
|
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - "~>"
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '3.0'
|
|
85
|
+
- !ruby/object:Gem::Dependency
|
|
86
|
+
name: rspec-its
|
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - "~>"
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '1.0'
|
|
92
|
+
type: :development
|
|
93
|
+
prerelease: false
|
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
95
|
+
requirements:
|
|
96
|
+
- - "~>"
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: '1.0'
|
|
99
|
+
- !ruby/object:Gem::Dependency
|
|
100
|
+
name: webmock
|
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
|
102
|
+
requirements:
|
|
103
|
+
- - "~>"
|
|
104
|
+
- !ruby/object:Gem::Version
|
|
105
|
+
version: '1.15'
|
|
106
|
+
type: :development
|
|
107
|
+
prerelease: false
|
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - "~>"
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '1.15'
|
|
113
|
+
- !ruby/object:Gem::Dependency
|
|
114
|
+
name: yard
|
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - "~>"
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0.8'
|
|
120
|
+
type: :development
|
|
121
|
+
prerelease: false
|
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - "~>"
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0.8'
|
|
127
|
+
description: |-
|
|
128
|
+
Executes SPARQL queries and updates against a remote SPARQL 1.0 or 1.1 endpoint,
|
|
129
|
+
or against a local repository. Generates SPARQL queries using a simple DSL.
|
|
130
|
+
Includes SPARQL::Client::Repository, which allows any endpoint supporting
|
|
131
|
+
SPARQL Update to be used as an RDF.rb repository.
|
|
132
|
+
email: public-rdf-ruby@w3.org
|
|
133
|
+
executables: []
|
|
134
|
+
extensions: []
|
|
135
|
+
extra_rdoc_files: []
|
|
136
|
+
files:
|
|
137
|
+
- AUTHORS
|
|
138
|
+
- CREDITS
|
|
139
|
+
- README
|
|
140
|
+
- UNLICENSE
|
|
141
|
+
- VERSION
|
|
142
|
+
- lib/sparql/client.rb
|
|
143
|
+
- lib/sparql/client/query.rb
|
|
144
|
+
- lib/sparql/client/repository.rb
|
|
145
|
+
- lib/sparql/client/update.rb
|
|
146
|
+
- lib/sparql/client/version.rb
|
|
147
|
+
homepage: http://ruby-rdf.github.com/sparql-client/
|
|
148
|
+
licenses:
|
|
149
|
+
- Public Domain
|
|
150
|
+
metadata: {}
|
|
151
|
+
post_install_message:
|
|
152
|
+
rdoc_options: []
|
|
153
|
+
require_paths:
|
|
154
|
+
- lib
|
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: 1.9.3
|
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
|
+
requirements:
|
|
162
|
+
- - ">"
|
|
163
|
+
- !ruby/object:Gem::Version
|
|
164
|
+
version: 1.3.1
|
|
165
|
+
requirements: []
|
|
166
|
+
rubyforge_project: sparql-client
|
|
167
|
+
rubygems_version: 2.2.1
|
|
168
|
+
signing_key:
|
|
169
|
+
specification_version: 4
|
|
170
|
+
summary: SPARQL client for RDF.rb.
|
|
171
|
+
test_files: []
|
|
172
|
+
has_rdoc: false
|