sparql-client 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/README +1 -1
  3. data/VERSION +1 -1
  4. data/lib/sparql/client.rb +50 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWRmNDMzMmY0MmFhNTI2MDc1NTdkNmM5YTk3YWJlYjhlOGI5NzM4OQ==
4
+ ZDg1MzljNzgxZjQ1N2NhZDYyMzdmN2FkMDZlNTIzNmNjMTE4YTE5ZA==
5
5
  data.tar.gz: !binary |-
6
- Y2I2MTVhNDhlYzU3MDI0YWRmNjJjM2ZkOGI5NGI4ZTAyN2RiMWU0Nw==
6
+ MTRlMmZhYmVlMmI3MzdiMzlmNzUwMjYyYjcwYzE5ZTU0MWVhMGZmOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjBlOTRmOTViNzY1ZGE5ZjVkMGI2NWMzM2MzNzVhNjNjNDMwYTRmMjVkYWQ4
10
- MjBkNjRjNDAxNWFkNTA1MDYwMTczNTU4NzkzMmVjZGJjYWUwMmE4YjRkYzQw
11
- Zjg2M2M0ODI5ODBiZjVlZmNhZjY3ZjU2ZGVkZWI1OGFjMWJhNmI=
9
+ MGYxMDJjM2EwYTRiZjhmNTEzNjVjZTNhODNlZDM2N2QwYThmYjRhZmFkNTUy
10
+ YjJjZjQ2MjQ0NGQyYjM4MjgxYmM0NTI2ZmZlZGRlYWRjYTRiYzNkYjU1YmY4
11
+ NmQ3YTAxN2YxNDZlZmRjMTgwMDY0NmRmYjVjMjRlMjY4YTVlYzU=
12
12
  data.tar.gz: !binary |-
13
- ODMyN2MzNjk0NWQyMzMwYmViNDNhYTgxODJhOGM3YjRkM2UwMjdlODA4ZDlk
14
- MGVhNzk4NTY3NWUzN2U3OTkzZjIzMzc2MWYwNDI0MzNhMTI1MDBhNGQwYjNh
15
- Y2E2NjM3YWU0MzBlY2UwYjY4NGY4N2YyM2VjMWM1YTEwNzQyMzI=
13
+ YTY4MjMyY2Q1MDQ1YzFlMDE5ZjJlOTViYjZjYmQ2N2FmMjM1ZDgzMjM0NmY5
14
+ MWVlZGE2OTZjZDE0ZWQ0NmU5ZWY4ZDA2MDc4YmViOGI4ZDA3YmIwNzA0YTYz
15
+ YTVjYTljMzRjYzA4ZTBjYzBlZmRjNmM1MTQ4NGIwMWM1ZGQwM2E=
data/README CHANGED
@@ -13,7 +13,7 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
13
13
  * Provides a query builder [DSL][] for `ASK`, `SELECT`, `DESCRIBE` and
14
14
  `CONSTRUCT` queries.
15
15
  * Includes preliminary support for some SPARQL 1.1 Update operations.
16
- * Supports tuple result sets in both XML and JSON formats, with JSON being
16
+ * Supports tuple result sets in both XML, JSON, CSV and TSV formats, with JSON being
17
17
  the preferred default for content-negotiation purposes.
18
18
  * Supports graph results in any RDF serialization format understood by RDF.rb.
19
19
  * Returns results using the [RDF.rb object model][RDF.rb model].
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -329,6 +329,56 @@ module SPARQL
329
329
  end
330
330
  end
331
331
 
332
+ ##
333
+ # @param [String, Array<Array<String>>] csv
334
+ # @return [<RDF::Query::Solutions>]
335
+ # @see http://www.w3.org/TR/sparql11-results-csv-tsv/
336
+ def self.parse_csv_bindings(csv, nodes = {})
337
+ require 'csv' unless defined?(::CSV)
338
+ csv = CSV.parse(csv.to_s) unless csv.is_a?(Array)
339
+ vars = csv.shift
340
+ solutions = RDF::Query::Solutions.new
341
+ csv.each do |row|
342
+ solution = RDF::Query::Solution.new
343
+ row.each_with_index do |v, i|
344
+ term = case v
345
+ when /^_:(.*)$/ then nodes[$1] ||= RDF::Node($1)
346
+ when /^\w+:.*$/ then RDF::URI(v)
347
+ else RDF::Literal(v)
348
+ end
349
+ solution[vars[i].to_sym] = term
350
+ end
351
+ solutions << solution
352
+ end
353
+ solutions
354
+ end
355
+
356
+ ##
357
+ # @param [String, Array<Array<String>>] tsv
358
+ # @return [<RDF::Query::Solutions>]
359
+ # @see http://www.w3.org/TR/sparql11-results-csv-tsv/
360
+ def self.parse_tsv_bindings(tsv, nodes = {})
361
+ tsv = tsv.lines.map {|l| l.chomp.split("\t")} unless tsv.is_a?(Array)
362
+ vars = tsv.shift.map {|h| h.sub(/^\?/, '')}
363
+ solutions = RDF::Query::Solutions.new
364
+ tsv.each do |row|
365
+ solution = RDF::Query::Solution.new
366
+ row.each_with_index do |v, i|
367
+ term = RDF::NTriples.unserialize(v) || case v
368
+ when /^\d+\.\d*[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
369
+ when /^\d*\.\d+[eE][+-]?[0-9]+$/ then RDF::Literal::Double.new(v)
370
+ when /^\d*\.\d+$/ then RDF::Literal::Decimal.new(v)
371
+ when /^\d+$/ then RDF::Literal::Integer.new(v)
372
+ else
373
+ RDF::Literal(v)
374
+ end
375
+ solution[vars[i].to_sym] = term
376
+ end
377
+ solutions << solution
378
+ end
379
+ solutions
380
+ end
381
+
332
382
  ##
333
383
  # @param [String, REXML::Element] xml
334
384
  # @return [<RDF::Query::Solutions>]
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.0.2
4
+ version: 1.0.3
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: 2013-06-05 00:00:00.000000000 Z
13
+ date: 2013-06-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf