sparql-client 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38ac883367777a453e1af010eb241ee4c14ee3dc
4
- data.tar.gz: 2b251fa756f8adb385e95394bb1497d917021340
3
+ metadata.gz: 9cbfcd66988f16d017ebcabef5ab454d3d06ca46
4
+ data.tar.gz: a11a2a6ec4df3ad78cf190250e5992d0ac9f4279
5
5
  SHA512:
6
- metadata.gz: 7a3044448b1e7e7bb252de265834bf76bedae8deafa28a1861a49d1b08e6ec9fd62d54e3c19b70a39cd76cd595e8e8d8524287aeb6ad751eff080e1ddeac5ec6
7
- data.tar.gz: f4839f05b1441be9bde48f8e411d85ecd86c433b670da202c8a0ca0a3f62f6c931470438ca7f213cf6aacc144581806058f03380db418d875934208df7956693
6
+ metadata.gz: fa4d22153b5828a56da4d7b0bc648987be93ebdc31e3162f44a945f6536436715d2325090a27061997ab894f2e4c352d8620393736483981812a132c426858e5
7
+ data.tar.gz: a953798c28628c65350ca3ce3d6819e4986a6dda587fd4ce1a926c1c1dcaf88cd229762ec1c2956eb89aa32191b98dfdcacfe9b96da9ffb52f8adc4cfc2731bd
data/README CHANGED
@@ -66,11 +66,28 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
66
66
 
67
67
  puts result.inspect #=> true or false
68
68
 
69
+ ### Inserting data into a graph
70
+
71
+ # INSERT DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
72
+ data = RDF::Graph.new do |graph|
73
+ graph << [RDF::URI('http://example.org/jhacker'), RDF::FOAF.name, "J. Random Hacker"]
74
+ end
75
+ insert_data(data)
76
+
77
+ ### Deleting data from a graph
78
+
79
+ # DELETE DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
80
+ data = RDF::Graph.new do |graph|
81
+ graph << [RDF::URI('http://example.org/jhacker'), RDF::FOAF.name, "J. Random Hacker"]
82
+ end
83
+ delete_data(data)
84
+
69
85
  ##Documentation
70
86
 
71
87
  * {SPARQL::Client}
72
88
  * {SPARQL::Client::Query}
73
89
  * {SPARQL::Client::Repository}
90
+ * {SPARQL::Client::Update}
74
91
 
75
92
  ##Dependencies
76
93
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.5
1
+ 1.1.6
@@ -7,7 +7,9 @@ module SPARQL; class Client
7
7
  #
8
8
  class Query < RDF::Query
9
9
  ##
10
- # @return [Symbol]
10
+ # The form of the query.
11
+ #
12
+ # @return [:select, :ask, :construct, :describe]
11
13
  # @see http://www.w3.org/TR/sparql11-query/#QueryForms
12
14
  attr_reader :form
13
15
 
@@ -16,13 +18,18 @@ module SPARQL; class Client
16
18
  attr_reader :options
17
19
 
18
20
  ##
21
+ # Values returned from previous query.
22
+ #
19
23
  # @return [Array<[key, RDF::Value]>]
20
24
  attr_reader :values
21
25
 
22
26
  ##
23
27
  # Creates a boolean `ASK` query.
24
28
  #
25
- # @param [Hash{Symbol => Object}] options
29
+ # @example ASK WHERE { ?s ?p ?o . }
30
+ # Query.ask.where([:s, :p, :o])
31
+ #
32
+ # @param [Hash{Symbol => Object}] options (see {#initialize})
26
33
  # @return [Query]
27
34
  # @see http://www.w3.org/TR/sparql11-query/#ask
28
35
  def self.ask(options = {})
@@ -32,11 +39,15 @@ module SPARQL; class Client
32
39
  ##
33
40
  # Creates a tuple `SELECT` query.
34
41
  #
42
+ # @example SELECT * WHERE { ?s ?p ?o . }
43
+ # Query.select.where([:s, :p, :o])
44
+ #
35
45
  # @param [Array<Symbol>] variables
36
46
  # @return [Query]
37
47
  #
38
48
  # @overload self.select(*variables, options)
39
49
  # @param [Array<Symbol>] variables
50
+ # @param [Hash{Symbol => Object}] options (see {#initialize})
40
51
  # @return [Query]
41
52
  # @see http://www.w3.org/TR/sparql11-query/#select
42
53
  def self.select(*variables)
@@ -47,11 +58,15 @@ module SPARQL; class Client
47
58
  ##
48
59
  # Creates a `DESCRIBE` query.
49
60
  #
61
+ # @example DESCRIBE * WHERE { ?s ?p ?o . }
62
+ # Query.describe.where([:s, :p, :o])
63
+ #
50
64
  # @param [Array<Symbol, RDF::URI>] variables
51
65
  # @return [Query]
52
66
  #
53
67
  # @overload self.describe(*variables, options)
54
68
  # @param [Array<Symbol, RDF::URI>] variables
69
+ # @param [Hash{Symbol => Object}] options (see {#initialize})
55
70
  # @return [Query]
56
71
  # @see http://www.w3.org/TR/sparql11-query/#describe
57
72
  def self.describe(*variables)
@@ -62,12 +77,15 @@ module SPARQL; class Client
62
77
  ##
63
78
  # Creates a graph `CONSTRUCT` query.
64
79
  #
80
+ # @example CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . }
81
+ # Query.construct([:s, :p, :o]).where([:s, :p, :o])
82
+ #
65
83
  # @param [Array<RDF::Query::Pattern, Array>] patterns
66
84
  # @return [Query]
67
85
  #
68
86
  # @overload self.construct(*variables, options)
69
87
  # @param [Array<RDF::Query::Pattern, Array>] patterns
70
- # @param [Hash{Symbol => Object}] options
88
+ # @param [Hash{Symbol => Object}] options (see {#initialize})
71
89
  # @return [Query]
72
90
  # @see http://www.w3.org/TR/sparql11-query/#construct
73
91
  def self.construct(*patterns)
@@ -79,7 +97,7 @@ module SPARQL; class Client
79
97
  # @param [Symbol, #to_s] form
80
98
  # @overload self.construct(*variables, options)
81
99
  # @param [Symbol, #to_s] form
82
- # @param [Hash{Symbol => Object}] options
100
+ # @param [Hash{Symbol => Object}] options (see {Client#initialize})
83
101
  # @yield [query]
84
102
  # @yieldparam [Query]
85
103
  def initialize(form = :ask, options = {}, &block)
@@ -89,6 +107,9 @@ module SPARQL; class Client
89
107
  end
90
108
 
91
109
  ##
110
+ # @example ASK WHERE { ?s ?p ?o . }
111
+ # query.ask.where([:s, :p, :o])
112
+ #
92
113
  # @return [Query]
93
114
  # @see http://www.w3.org/TR/sparql11-query/#ask
94
115
  def ask
@@ -97,6 +118,9 @@ module SPARQL; class Client
97
118
  end
98
119
 
99
120
  ##
121
+ # @example SELECT * WHERE { ?s ?p ?o . }
122
+ # query.select.where([:s, :p, :o])
123
+ #
100
124
  # @param [Array<Symbol>] variables
101
125
  # @return [Query]
102
126
  # @see http://www.w3.org/TR/sparql11-query/#select
@@ -106,6 +130,9 @@ module SPARQL; class Client
106
130
  end
107
131
 
108
132
  ##
133
+ # @example DESCRIBE * WHERE { ?s ?p ?o . }
134
+ # query.describe.where([:s, :p, :o])
135
+ #
109
136
  # @param [Array<Symbol>] variables
110
137
  # @return [Query]
111
138
  # @see http://www.w3.org/TR/sparql11-query/#describe
@@ -117,6 +144,9 @@ module SPARQL; class Client
117
144
  end
118
145
 
119
146
  ##
147
+ # @example CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . }
148
+ # query.construct([:s, :p, :o]).where([:s, :p, :o])
149
+ #
120
150
  # @param [Array<RDF::Query::Pattern, Array>] patterns
121
151
  # @return [Query]
122
152
  # @see http://www.w3.org/TR/sparql11-query/#construct
@@ -125,6 +155,10 @@ module SPARQL; class Client
125
155
  self
126
156
  end
127
157
 
158
+ ##
159
+ # @example SELECT * FROM <a> WHERE \{ ?s ?p ?o . \}
160
+ # query.select.from(RDF::URI.new(a)).where([:s, :p, :o])
161
+ #
128
162
  # @param [RDF::URI] uri
129
163
  # @return [Query]
130
164
  # @see http://www.w3.org/TR/sparql11-query/#specifyingDataset
@@ -134,6 +168,10 @@ module SPARQL; class Client
134
168
  end
135
169
 
136
170
  ##
171
+ # @example SELECT * WHERE { ?s ?p ?o . }
172
+ # query.select.where([:s, :p, :o])
173
+ # query.select.whether([:s, :p, :o])
174
+ #
137
175
  # @param [Array<RDF::Query::Pattern, Array>] patterns_queries
138
176
  # splat of zero or more patterns followed by zero or more queries.
139
177
  # @return [Query]
@@ -148,6 +186,16 @@ module SPARQL; class Client
148
186
  alias_method :whether, :where
149
187
 
150
188
  ##
189
+ # @example SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o
190
+ # query.select.where([:s, :p, :o]).order(:o)
191
+ # query.select.where([:s, :p, :o]).order_by(:o)
192
+ #
193
+ # @example SELECT * WHERE { ?s ?p ?o . } ORDER BY ?o ?p
194
+ # query.select.where([:s, :p, :o]).order_by(:o, :p)
195
+ #
196
+ # @example SELECT * WHERE { ?s ?p ?o . } ORDER BY ASC(?o) DESC(?p)
197
+ # query.select.where([:s, :p, :o]).order_by(:o => :asc, :p => :desc)
198
+ #
151
199
  # @param [Array<Symbol, String>] variables
152
200
  # @return [Query]
153
201
  # @see http://www.w3.org/TR/sparql11-query/#modOrderBy
@@ -159,6 +207,35 @@ module SPARQL; class Client
159
207
  alias_method :order_by, :order
160
208
 
161
209
  ##
210
+ # @example SELECT * WHERE { ?s ?p ?o . } ORDER BY ASC(?o)
211
+ # query.select.where([:s, :p, :o]).order.asc(:o)
212
+ # query.select.where([:s, :p, :o]).asc(:o)
213
+ #
214
+ # @param [Array<Symbol, String>] variables
215
+ # @return [Query]
216
+ # @see http://www.w3.org/TR/sparql11-query/#modOrderBy
217
+ def asc(var)
218
+ (options[:order_by] ||= []) << {var => :asc}
219
+ self
220
+ end
221
+
222
+ ##
223
+ # @example SELECT * WHERE { ?s ?p ?o . } ORDER BY DESC(?o)
224
+ # query.select.where([:s, :p, :o]).order.desc(:o)
225
+ # query.select.where([:s, :p, :o]).desc(:o)
226
+ #
227
+ # @param [Array<Symbol, String>] variables
228
+ # @return [Query]
229
+ # @see http://www.w3.org/TR/sparql11-query/#modOrderBy
230
+ def desc(var)
231
+ (options[:order_by] ||= []) << {var => :desc}
232
+ self
233
+ end
234
+
235
+ ##
236
+ # @example SELECT ?s WHERE { ?s ?p ?o . } GROUP BY ?s
237
+ # query.select(:s).where([:s, :p, :o]).group_by(:s)
238
+ #
162
239
  # @param [Array<Symbol, String>] variables
163
240
  # @return [Query]
164
241
  # @see http://www.w3.org/TR/sparql11-query/#groupby
@@ -170,6 +247,9 @@ module SPARQL; class Client
170
247
  alias_method :group_by, :group
171
248
 
172
249
  ##
250
+ # @example SELECT DISTINCT ?s WHERE { ?s ?p ?o . }
251
+ # query.select(:s).distinct.where([:s, :p, :o])
252
+ #
173
253
  # @return [Query]
174
254
  # @see http://www.w3.org/TR/sparql11-query/#modDuplicates
175
255
  def distinct(state = true)
@@ -178,6 +258,9 @@ module SPARQL; class Client
178
258
  end
179
259
 
180
260
  ##
261
+ # @example SELECT REDUCED ?s WHERE { ?s ?p ?o . }
262
+ # query.select(:s).reduced.where([:s, :p, :o])
263
+ #
181
264
  # @return [Query]
182
265
  # @see http://www.w3.org/TR/sparql11-query/#modDuplicates
183
266
  def reduced(state = true)
@@ -186,6 +269,8 @@ module SPARQL; class Client
186
269
  end
187
270
 
188
271
  ##
272
+ # @example SELECT * WHERE { GRAPH ?g { ?s ?p ?o . } }
273
+ # query.select.graph(:g).where([:s, :p, :o])
189
274
  # @param [RDF::Value] graph_uri_or_var
190
275
  # @return [Query]
191
276
  # @see http://www.w3.org/TR/sparql11-query/#queryDataset
@@ -200,6 +285,9 @@ module SPARQL; class Client
200
285
  end
201
286
 
202
287
  ##
288
+ # @example SELECT * WHERE { ?s ?p ?o . } OFFSET 100
289
+ # query.select.where([:s, :p, :o]).offset(100)
290
+ #
203
291
  # @param [Integer, #to_i] start
204
292
  # @return [Query]
205
293
  # @see http://www.w3.org/TR/sparql11-query/#modOffset
@@ -208,6 +296,9 @@ module SPARQL; class Client
208
296
  end
209
297
 
210
298
  ##
299
+ # @example SELECT * WHERE { ?s ?p ?o . } LIMIT 10
300
+ # query.select.where([:s, :p, :o]).limit(10)
301
+ #
211
302
  # @param [Integer, #to_i] length
212
303
  # @return [Query]
213
304
  # @see http://www.w3.org/TR/sparql11-query/#modResultLimit
@@ -216,6 +307,9 @@ module SPARQL; class Client
216
307
  end
217
308
 
218
309
  ##
310
+ # @example SELECT * WHERE { ?s ?p ?o . } OFFSET 100 LIMIT 10
311
+ # query.select.where([:s, :p, :o]).slice(100, 10)
312
+ #
219
313
  # @param [Integer, #to_i] start
220
314
  # @param [Integer, #to_i] length
221
315
  # @return [Query]
@@ -226,6 +320,12 @@ module SPARQL; class Client
226
320
  end
227
321
 
228
322
  ##
323
+ # @example PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT * WHERE \{ ?s ?p ?o . \}
324
+ # query.select.
325
+ # prefix(dc: RDF::URI("http://purl.org/dc/elements/1.1/")).
326
+ # prefix(foaf: RDF::URI("http://xmlns.com/foaf/0.1/")).
327
+ # where([:s, :p, :o])
328
+ #
229
329
  # @return [Query]
230
330
  # @see http://www.w3.org/TR/sparql11-query/#prefNames
231
331
  def prefix(string)
@@ -234,6 +334,10 @@ module SPARQL; class Client
234
334
  end
235
335
 
236
336
  ##
337
+ # @example SELECT * WHERE \{ ?s ?p ?o . OPTIONAL \{ ?s a ?o . ?s \<http://purl.org/dc/terms/abstract\> ?o . \} \}
338
+ # query.select.where([:s, :p, :o]).
339
+ # optional([:s, RDF.type, :o], [:s, RDF::DC.abstract, :o])
340
+ #
237
341
  # @return [Query]
238
342
  # @see http://www.w3.org/TR/sparql11-query/#optionals
239
343
  def optional(*patterns)
@@ -382,7 +486,40 @@ module SPARQL; class Client
382
486
 
383
487
  if options[:order_by]
384
488
  buffer << 'ORDER BY'
385
- buffer += options[:order_by].map { |var| var.is_a?(String) ? var : "?#{var}" }
489
+ options[:order_by].map { |elem|
490
+ case elem
491
+ # .order_by({ :var1 => :asc, :var2 => :desc})
492
+ when Hash
493
+ elem.each { |key, val|
494
+ # check provided values
495
+ if !key.is_a?(Symbol)
496
+ raise ArgumentError, 'keys of hash argument must be a Symbol'
497
+ elsif !val.is_a?(Symbol) || (val != :asc && val != :desc)
498
+ raise ArgumentError, 'values of hash argument must either be `:asc` or `:desc`'
499
+ end
500
+ buffer << "#{val == :asc ? 'ASC' : 'DESC'}(?#{key})"
501
+ }
502
+ # .order_by([:var1, :asc], [:var2, :desc])
503
+ when Array
504
+ # check provided values
505
+ if elem.length != 2
506
+ raise ArgumentError, 'array argument must specify two elements'
507
+ elsif !elem[0].is_a?(Symbol)
508
+ raise ArgumentError, '1st element of array argument must contain a Symbol'
509
+ elsif !elem[1].is_a?(Symbol) || (elem[1] != :asc && elem[1] != :desc)
510
+ raise ArgumentError, '2nd element of array argument must either be `:asc` or `:desc`'
511
+ end
512
+ buffer << "#{elem[1] == :asc ? 'ASC' : 'DESC'}(?#{elem[0]})"
513
+ # .order_by(:var1, :var2)
514
+ when Symbol
515
+ buffer << "?#{elem}"
516
+ # .order_by('ASC(?var1) DESC(?var2)')
517
+ when String
518
+ buffer << elem
519
+ else
520
+ raise ArgumentError, 'argument provided to `order()` must either be an Array, Symbol or String'
521
+ end
522
+ }
386
523
  end
387
524
 
388
525
  buffer << "OFFSET #{options[:offset]}" if options[:offset]
@@ -2,7 +2,7 @@ module SPARQL; class Client
2
2
  ##
3
3
  # A read-only repository view of a SPARQL endpoint.
4
4
  #
5
- # @see RDF::Repository
5
+ # @see `RDF::Repository`
6
6
  class Repository < RDF::Repository
7
7
  # @return [SPARQL::Client]
8
8
  attr_reader :client
@@ -18,7 +18,7 @@ module SPARQL; class Client
18
18
 
19
19
  ##
20
20
  # Returns the client for the update_endpoint if specified, otherwise the
21
- # {client}.
21
+ # {#client}.
22
22
  #
23
23
  # @return [SPARQL::Client]
24
24
  def update_client
@@ -186,7 +186,7 @@ module SPARQL; class Client
186
186
 
187
187
  ##
188
188
  # Deletes RDF statements from `self`.
189
- # If any statement contains a {Query::Variable}, it is
189
+ # If any statement contains an `RDF::Query::Variable`, it is
190
190
  # considered to be a pattern, and used to query
191
191
  # self to find matching statements to delete.
192
192
  #
@@ -231,7 +231,7 @@ module SPARQL; class Client
231
231
  # repository.query([nil, RDF::DOAP.developer, nil])
232
232
  # repository.query(:predicate => RDF::DOAP.developer)
233
233
  #
234
- # @fixme This should use basic SPARQL query mechanism.
234
+ # @todo This should use basic SPARQL query mechanism.
235
235
  #
236
236
  # @param [Pattern] pattern
237
237
  # @see RDF::Queryable#query_pattern
@@ -2,26 +2,128 @@ class SPARQL::Client
2
2
  ##
3
3
  # SPARQL 1.1 Update operation builders.
4
4
  module Update
5
+ ##
6
+ # Insert statements into the graph
7
+ #
8
+ # @example INSERT DATA \{ <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> \"J. Random Hacker\" .\}
9
+ # data = RDF::Graph.new do |graph|
10
+ # graph << [RDF::URI('http://example.org/jhacker'), RDF::FOAF.name, "J. Random Hacker"]
11
+ # end
12
+ # insert_data(data)
13
+ #
14
+ # @example INSERT DATA \{ GRAPH <http://example.org/> \{\}\}
15
+ # insert_data(RDF::Graph.new, :graph => 'http://example.org/')
16
+ # insert_data(RDF::Graph.new).graph('http://example.org/')
17
+ #
18
+ # @param (see InsertData#initialize)
5
19
  def self.insert_data(*arguments)
6
20
  InsertData.new(*arguments)
7
21
  end
8
22
 
23
+ ##
24
+ # Delete statements from the graph
25
+ #
26
+ # @example DELETE DATA \{ <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> \"J. Random Hacker\" .\}
27
+ # data = RDF::Graph.new do |graph|
28
+ # graph << [RDF::URI('http://example.org/jhacker'), RDF::FOAF.name, "J. Random Hacker"]
29
+ # end
30
+ # delete_data(data)
31
+ #
32
+ # @example DELETE DATA \{ GRAPH <http://example.org/> \{\}\}
33
+ # delete_data(RDF::Graph.new, :graph => 'http://example.org/')
34
+ # delete_data(RDF::Graph.new).graph('http://example.org/')
35
+ #
36
+ # @param (see DeleteData#initialize)
9
37
  def self.delete_data(*arguments)
10
38
  DeleteData.new(*arguments)
11
39
  end
12
40
 
41
+ ##
42
+ # Load statements into the graph
43
+ #
44
+ # @example LOAD <http://example.org/data.rdf>
45
+ # load(RDF::URI(http://example.org/data.rdf))
46
+ #
47
+ # @example LOAD SILENT <http://example.org/data.rdf>
48
+ # load(RDF::URI(http://example.org/data.rdf)).silent
49
+ # load(RDF::URI(http://example.org/data.rdf), silent: true)
50
+ #
51
+ # @example LOAD <http://example.org/data.rdf> INTO <http://example.org/data.rdf>
52
+ # load(RDF::URI(http://example.org/data.rdf)).into(RDF::URI(http://example.org/data.rdf))
53
+ # load(RDF::URI(http://example.org/data.rdf), into: RDF::URI(http://example.org/data.rdf))
54
+ #
55
+ # @param (see Load#initialize)
13
56
  def self.load(*arguments)
14
57
  Load.new(*arguments)
15
58
  end
16
59
 
60
+ ##
61
+ # Load statements into the graph
62
+ #
63
+ # @example CLEAR GRAPH <http://example.org/data.rdf>
64
+ # clear.graph(RDF::URI(http://example.org/data.rdf))
65
+ # clear(:graph, RDF::URI(http://example.org/data.rdf))
66
+ #
67
+ # @example CLEAR DEFAULT
68
+ # clear.default
69
+ # clear(:default)
70
+ #
71
+ # @example CLEAR NAMED
72
+ # clear.named
73
+ # clear(:named)
74
+ #
75
+ # @example CLEAR ALL
76
+ # clear.all
77
+ # clear(:all)
78
+ #
79
+ # @example CLEAR SILENT ALL
80
+ # clear.all.silent
81
+ # clear(:all, silent: true)
82
+ #
83
+ # @param (see Clear#initialize)
17
84
  def self.clear(*arguments)
18
85
  Clear.new(*arguments)
19
86
  end
20
87
 
88
+ ##
89
+ # Create a graph
90
+ #
91
+ # @example CREATE GRAPH <http://example.org/data.rdf>
92
+ # create(RDF::URI(http://example.org/data.rdf))
93
+ #
94
+ # @example CREATE SILENT GRAPH <http://example.org/data.rdf>
95
+ # create(RDF::URI(http://example.org/data.rdf)).silent
96
+ # create(RDF::URI(http://example.org/data.rdf), silent: true)
97
+ #
98
+ # @param (see Create#initialize)
21
99
  def self.create(*arguments)
22
100
  Create.new(*arguments)
23
101
  end
24
102
 
103
+ ##
104
+ # Drop a graph
105
+ #
106
+ # @example DROP GRAPH <http://example.org/data.rdf>
107
+ # drop.graph(RDF::URI(http://example.org/data.rdf))
108
+ # drop(:graph, RDF::URI(http://example.org/data.rdf))
109
+ #
110
+ # @example DROP DEFAULT
111
+ # drop.default
112
+ # drop(:default)
113
+ #
114
+ # @example DROP NAMED
115
+ # drop.named
116
+ # drop(:named)
117
+ #
118
+ # @example DROP ALL
119
+ # drop.all
120
+ # drop(:all)
121
+ #
122
+ # @example DROP ALL SILENT
123
+ # drop.all.silent
124
+ # drop(:all, silent: true)
125
+ #
126
+ # @param (see Drop#initialize)
25
127
  def self.drop(*arguments)
26
128
  Drop.new(*arguments)
27
129
  end
@@ -39,11 +141,13 @@ class SPARQL::Client
39
141
  ##
40
142
  # Generic Update always returns statements
41
143
  #
42
- # @return expects_statements?
144
+ # @return [true]
43
145
  def expects_statements?
44
146
  true
45
147
  end
46
148
 
149
+ ##
150
+ # Set `silent` option
47
151
  def silent
48
152
  self.options[:silent] = true
49
153
  self
@@ -53,13 +157,30 @@ class SPARQL::Client
53
157
  ##
54
158
  # @see http://www.w3.org/TR/sparql11-update/#insertData
55
159
  class InsertData < Operation
160
+ # @return [RDF::Enumerable]
56
161
  attr_reader :data
57
162
 
163
+ ##
164
+ # Insert statements into the graph
165
+ #
166
+ # @example INSERT DATA \{ <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> \"J. Random Hacker\" .\}
167
+ # data = RDF::Graph.new do |graph|
168
+ # graph << [RDF::URI('http://example.org/jhacker'), RDF::FOAF.name, "J. Random Hacker"]
169
+ # end
170
+ # insert_data(data)
171
+ #
172
+ # @param [Array<RDF::Statement>, RDF::Enumerable] data
173
+ # @param [Hash{Symbol => Object}] options
58
174
  def initialize(data, options = {})
59
175
  @data = data
60
176
  super(options)
61
177
  end
62
178
 
179
+ ##
180
+ # Cause data to be inserted into the graph specified by `uri`
181
+ #
182
+ # @param [RDF::URI] uri
183
+ # @return [self]
63
184
  def graph(uri)
64
185
  self.options[:graph] = uri
65
186
  self
@@ -68,7 +189,7 @@ class SPARQL::Client
68
189
  ##
69
190
  # InsertData always returns result set
70
191
  #
71
- # @return expects_statements?
192
+ # @return [true]
72
193
  def expects_statements?
73
194
  false
74
195
  end
@@ -86,13 +207,30 @@ class SPARQL::Client
86
207
  ##
87
208
  # @see http://www.w3.org/TR/sparql11-update/#deleteData
88
209
  class DeleteData < Operation
210
+ # @return [RDF::Enumerable]
89
211
  attr_reader :data
90
212
 
213
+ ##
214
+ # Delete statements from the graph
215
+ #
216
+ # @example DELETE DATA \{ <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> \"J. Random Hacker\" .\}
217
+ # data = RDF::Graph.new do |graph|
218
+ # graph << [RDF::URI('http://example.org/jhacker'), RDF::FOAF.name, "J. Random Hacker"]
219
+ # end
220
+ # delete_data(data)
221
+ #
222
+ # @param [Array<RDF::Statement>, RDF::Enumerable] data
223
+ # @param [Hash{Symbol => Object}] options
91
224
  def initialize(data, options = {})
92
225
  @data = data
93
226
  super(options)
94
227
  end
95
228
 
229
+ ##
230
+ # Cause data to be deleted from the graph specified by `uri`
231
+ #
232
+ # @param [RDF::URI] uri
233
+ # @return [self]
96
234
  def graph(uri)
97
235
  self.options[:graph] = uri
98
236
  self
@@ -122,6 +260,11 @@ class SPARQL::Client
122
260
  super(options)
123
261
  end
124
262
 
263
+ ##
264
+ # Cause data to be deleted and inserted from the graph specified by `uri`
265
+ #
266
+ # @param [RDF::URI] uri
267
+ # @return [self]
125
268
  def graph(uri)
126
269
  self.options[:graph] = uri
127
270
  self
@@ -163,6 +306,24 @@ class SPARQL::Client
163
306
  attr_reader :from
164
307
  attr_reader :into
165
308
 
309
+
310
+ ##
311
+ # Load statements into the graph
312
+ #
313
+ # @example LOAD <http://example.org/data.rdf>
314
+ # load(RDF::URI(http://example.org/data.rdf))
315
+ #
316
+ # @example LOAD SILENT<http://example.org/data.rdf>
317
+ # load(RDF::URI(http://example.org/data.rdf)).silent
318
+ # load(RDF::URI(http://example.org/data.rdf), silent: true)
319
+ #
320
+ # @example LOAD <http://example.org/data.rdf> INTO <http://example.org/data.rdf>
321
+ # load(RDF::URI(http://example.org/data.rdf)).into(RDF::URI(http://example.org/data.rdf))
322
+ # load(RDF::URI(http://example.org/data.rdf), into: RDF::URI(http://example.org/data.rdf))
323
+ # @param [RDF::URI] from
324
+ # @param [Hash{Symbol => Object}] options
325
+ # @option [RDF::URI] :into
326
+ # @option [Boolean] :silent
166
327
  def initialize(from, options = {})
167
328
  options = options.dup
168
329
  @from = RDF::URI(from)
@@ -170,8 +331,13 @@ class SPARQL::Client
170
331
  super(options)
171
332
  end
172
333
 
173
- def into(url)
174
- @into = RDF::URI(url)
334
+ ##
335
+ # Cause data to be loaded into graph specified by `uri`
336
+ #
337
+ # @param [RDF::URI] uri
338
+ # @return [self]
339
+ def into(uri)
340
+ @into = RDF::URI(uri)
175
341
  self
176
342
  end
177
343
 
@@ -189,21 +355,38 @@ class SPARQL::Client
189
355
  class Clear < Operation
190
356
  attr_reader :uri
191
357
 
358
+ ##
359
+ # Cause data to be cleared from graph specified by `uri`
360
+ #
361
+ # @param [RDF::URI] uri
362
+ # @return [self]
192
363
  def graph(uri)
193
364
  @what, @uri = :graph, uri
194
365
  self
195
366
  end
196
367
 
368
+ ##
369
+ # Cause data to be cleared from the default graph
370
+ #
371
+ # @return [self]
197
372
  def default
198
373
  @what = :default
199
374
  self
200
375
  end
201
376
 
377
+ ##
378
+ # Cause data to be cleared from named graphs
379
+ #
380
+ # @return [self]
202
381
  def named
203
382
  @what = :named
204
383
  self
205
384
  end
206
385
 
386
+ ##
387
+ # Cause data to be cleared from all graphs
388
+ #
389
+ # @return [self]
207
390
  def all
208
391
  @what = :all
209
392
  self
@@ -212,7 +395,7 @@ class SPARQL::Client
212
395
  ##
213
396
  # Clear always returns statements
214
397
  #
215
- # @return expects_statements?
398
+ # @return [false]
216
399
  def expects_statements?
217
400
  false
218
401
  end
@@ -236,6 +419,7 @@ class SPARQL::Client
236
419
  class Create < Operation
237
420
  attr_reader :uri
238
421
 
422
+ # @param [Hash{Symbol => Object}] options
239
423
  def initialize(uri, options = {})
240
424
  @uri = RDF::URI(uri)
241
425
  super(options)
data/lib/sparql/client.rb CHANGED
@@ -108,6 +108,7 @@ module SPARQL
108
108
  ##
109
109
  # Executes a boolean `ASK` query.
110
110
  #
111
+ # @param (see Query.ask)
111
112
  # @return [Query]
112
113
  def ask(*args)
113
114
  call_query_method(:ask, *args)
@@ -116,7 +117,7 @@ module SPARQL
116
117
  ##
117
118
  # Executes a tuple `SELECT` query.
118
119
  #
119
- # @param [Array<Symbol>] args
120
+ # @param (see Query.select)
120
121
  # @return [Query]
121
122
  def select(*args)
122
123
  call_query_method(:select, *args)
@@ -125,7 +126,7 @@ module SPARQL
125
126
  ##
126
127
  # Executes a `DESCRIBE` query.
127
128
  #
128
- # @param [Array<Symbol, RDF::URI>] args
129
+ # @param (see Query.describe)
129
130
  # @return [Query]
130
131
  def describe(*args)
131
132
  call_query_method(:describe, *args)
@@ -134,7 +135,7 @@ module SPARQL
134
135
  ##
135
136
  # Executes a graph `CONSTRUCT` query.
136
137
  #
137
- # @param [Array<Symbol>] args
138
+ # @param (see Query.construct)
138
139
  # @return [Query]
139
140
  def construct(*args)
140
141
  call_query_method(:construct, *args)
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: 1.1.5
4
+ version: 1.1.6
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: 2015-05-04 00:00:00.000000000 Z
13
+ date: 2015-08-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
@@ -80,14 +80,14 @@ dependencies:
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '3.0'
83
+ version: 3.0.0
84
84
  type: :development
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '3.0'
90
+ version: 3.0.0
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec-its
93
93
  requirement: !ruby/object:Gem::Requirement
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  requirements: []
172
172
  rubyforge_project: sparql-client
173
- rubygems_version: 2.4.3
173
+ rubygems_version: 2.4.7
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: SPARQL client for RDF.rb.