sparql-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/VERSION +1 -1
- data/lib/sparql/client/query.rb +23 -3
- data/lib/sparql/client/version.rb +1 -1
- metadata +5 -5
data/README
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/sparql/client/query.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
module SPARQL; class Client
|
2
3
|
##
|
3
4
|
# A SPARQL query builder.
|
@@ -222,15 +223,19 @@ module SPARQL; class Client
|
|
222
223
|
when :select
|
223
224
|
buffer << 'DISTINCT' if options[:distinct]
|
224
225
|
buffer << 'REDUCED' if options[:reduced]
|
225
|
-
buffer << (variables.empty? ? '*' : variables.values.map(
|
226
|
+
buffer << (variables.empty? ? '*' : variables.values.map { |v| serialize_value(v) }.join(' '))
|
226
227
|
when :construct
|
227
228
|
buffer << '{'
|
228
|
-
buffer += options[:template].map
|
229
|
+
buffer += options[:template].map do |p|
|
230
|
+
p.to_triple.map { |v| serialize_value(v) }.join(' ') + " . "
|
231
|
+
end
|
229
232
|
buffer << '}'
|
230
233
|
end
|
231
234
|
|
232
235
|
buffer << 'WHERE {'
|
233
|
-
buffer += patterns.map
|
236
|
+
buffer += patterns.map do |p|
|
237
|
+
p.to_triple.map { |v| serialize_value(v) }.join(' ') + " . "
|
238
|
+
end
|
234
239
|
if options[:filters]
|
235
240
|
buffer += options[:filters].map { |filter| "FILTER(#{filter})" }
|
236
241
|
end
|
@@ -263,5 +268,20 @@ module SPARQL; class Client
|
|
263
268
|
def inspect
|
264
269
|
sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s)
|
265
270
|
end
|
271
|
+
|
272
|
+
##
|
273
|
+
# Serializes an RDF::Value into a format appropriate for select, construct, and where clauses
|
274
|
+
#
|
275
|
+
# @param [RDF::Value]
|
276
|
+
# @return [String]
|
277
|
+
# @private
|
278
|
+
def serialize_value(value)
|
279
|
+
# SPARQL queries are UTF-8, but support ASCII-style Unicode escapes, so
|
280
|
+
# the N-Triples serializer is fine unless it's a variable:
|
281
|
+
case
|
282
|
+
when value.variable? then "?#{value.name}"
|
283
|
+
else RDF::NTriples.serialize(value)
|
284
|
+
end
|
285
|
+
end
|
266
286
|
end
|
267
287
|
end; end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arto Bendiken
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-17 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -70,8 +70,8 @@ dependencies:
|
|
70
70
|
segments:
|
71
71
|
- 0
|
72
72
|
- 1
|
73
|
-
-
|
74
|
-
version: 0.1.
|
73
|
+
- 7
|
74
|
+
version: 0.1.7
|
75
75
|
type: :runtime
|
76
76
|
version_requirements: *id004
|
77
77
|
- !ruby/object:Gem::Dependency
|