sparql-client 2.2.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/VERSION +1 -1
- data/lib/sparql/client/query.rb +77 -6
- data/lib/sparql/client/repository.rb +0 -1
- metadata +20 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 996cb716d6311ccd569174d200c39d05a035e3b7
|
4
|
+
data.tar.gz: 23d718dd6a3e23cec61d02df0689d46dd87cf481
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ae85660825933ff2779a03acc8837f3cc82442edd6b5e725e44e2fd4558c346cce7d1bfd8a03d63fbc0ef5bbd4e7a6bfccb626575106d1b256f5a6e36eb8a71
|
7
|
+
data.tar.gz: a89eaac82c304cc3fc28d6b63c0c3e317728d20d2773262871fd111a2bf4dd8fe3597a87dbcfddf2284975bd12af7183856f9dcc603b2be1178a46e5f189e6db
|
data/README.md
CHANGED
@@ -93,10 +93,10 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
|
|
93
93
|
## Dependencies
|
94
94
|
|
95
95
|
* [Ruby](http://ruby-lang.org/) (>= 2.2.2)
|
96
|
-
* [RDF.rb](http://rubygems.org/gems/rdf) (
|
96
|
+
* [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0)
|
97
97
|
* [Net::HTTP::Persistent](http://rubygems.org/gems/net-http-persistent) (>= 1.4)
|
98
|
-
* Soft dependency on [SPARQL](http://rubygems.org/gems/sparql) (
|
99
|
-
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.
|
98
|
+
* Soft dependency on [SPARQL](http://rubygems.org/gems/sparql) (~> 3.0)
|
99
|
+
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.7)
|
100
100
|
|
101
101
|
## Installation
|
102
102
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
data/lib/sparql/client/query.rb
CHANGED
@@ -17,12 +17,6 @@ module SPARQL; class Client
|
|
17
17
|
# @return [Hash{Symbol => Object}]
|
18
18
|
attr_reader :options
|
19
19
|
|
20
|
-
##
|
21
|
-
# Values returned from previous query.
|
22
|
-
#
|
23
|
-
# @return [Array<[key, RDF::Value]>]
|
24
|
-
attr_reader :values
|
25
|
-
|
26
20
|
##
|
27
21
|
# Creates a boolean `ASK` query.
|
28
22
|
#
|
@@ -528,6 +522,71 @@ module SPARQL; class Client
|
|
528
522
|
self
|
529
523
|
end
|
530
524
|
|
525
|
+
##
|
526
|
+
# Specify inline data for a query
|
527
|
+
#
|
528
|
+
# @overload values
|
529
|
+
# Values returned from previous query.
|
530
|
+
#
|
531
|
+
# @return [Array<Array(key, RDF::Value)>]
|
532
|
+
#
|
533
|
+
# @overload values(vars, *data)
|
534
|
+
# @example single variable with multiple values
|
535
|
+
# query.select
|
536
|
+
# .where([:s, RDF::URI('http://purl.org/dc/terms/title'), :title])
|
537
|
+
# .values(:title, "This title", "Another title")
|
538
|
+
#
|
539
|
+
# @example multiple variables with multiple values
|
540
|
+
# query.select
|
541
|
+
# .where([:s, RDF::URI('http://purl.org/dc/terms/title'), :title],
|
542
|
+
# [:s, RDF.type, :type])
|
543
|
+
# .values([:type, :title],
|
544
|
+
# [RDF::URI('http://pcdm.org/models#Object'), "This title"],
|
545
|
+
# [RDF::URI('http://pcdm.org/models#Collection', 'Another title'])
|
546
|
+
#
|
547
|
+
# @example multiple variables with UNDEF
|
548
|
+
# query.select
|
549
|
+
# .where([:s, RDF::URI('http://purl.org/dc/terms/title'), :title],
|
550
|
+
# [:s, RDF.type, :type])
|
551
|
+
# .values([:type, :title],
|
552
|
+
# [nil "This title"],
|
553
|
+
# [RDF::URI('http://pcdm.org/models#Collection', nil])
|
554
|
+
#
|
555
|
+
# @param [Symbol, Array<Symbol>] vars
|
556
|
+
# @param [Array<RDF::Term, String, nil>] *data
|
557
|
+
# @return [Query]
|
558
|
+
def values(*args)
|
559
|
+
return @values if args.empty?
|
560
|
+
vars, *data = *args
|
561
|
+
vars = Array(vars).map {|var| RDF::Query::Variable.new(var)}
|
562
|
+
if vars.length == 1
|
563
|
+
# data may be a in array form or simple form
|
564
|
+
if data.any? {|d| d.is_a?(Array)} && !data.all? {|d| d.is_a?(Array)}
|
565
|
+
raise ArgumentError, "values data must all be in array form or all simple"
|
566
|
+
end
|
567
|
+
data = data.map {|d| Array(d)}
|
568
|
+
end
|
569
|
+
|
570
|
+
# Each data value must be an array with the same number of entries as vars
|
571
|
+
unless data.all? {|d| d.is_a?(Array) && d.all? {|dd| dd.is_a?(RDF::Value) || dd.is_a?(String) || dd.nil?}}
|
572
|
+
raise ArgumentError, "values data must each be an array of terms, strings, or nil"
|
573
|
+
end
|
574
|
+
|
575
|
+
# Turn strings into Literals
|
576
|
+
data = data.map do |d|
|
577
|
+
d.map do |nil_literal_or_term|
|
578
|
+
case nil_literal_or_term
|
579
|
+
when nil then nil
|
580
|
+
when String then RDF::Literal(nil_literal_or_term)
|
581
|
+
when RDF::Value then graph_uri_or_var
|
582
|
+
else raise ArgumentError
|
583
|
+
end
|
584
|
+
end
|
585
|
+
end
|
586
|
+
options[:values] = [vars, *data]
|
587
|
+
self
|
588
|
+
end
|
589
|
+
|
531
590
|
##
|
532
591
|
# @return expects_statements?
|
533
592
|
def expects_statements?
|
@@ -712,6 +771,18 @@ module SPARQL; class Client
|
|
712
771
|
if options[:filters]
|
713
772
|
buffer += options[:filters].map(&:to_s)
|
714
773
|
end
|
774
|
+
if options[:values]
|
775
|
+
vars = options[:values].first.map {|var| SPARQL::Client.serialize_value(var)}
|
776
|
+
buffer << "VALUES (#{vars.join(' ')}) {"
|
777
|
+
options[:values][1..-1].each do |data_block_value|
|
778
|
+
buffer << '('
|
779
|
+
buffer << data_block_value.map do |value|
|
780
|
+
value.nil? ? 'UNDEF' : SPARQL::Client.serialize_value(value)
|
781
|
+
end.join(' ')
|
782
|
+
buffer << ')'
|
783
|
+
end
|
784
|
+
buffer << '}'
|
785
|
+
end
|
715
786
|
if options[:graph]
|
716
787
|
buffer << '}' # GRAPH
|
717
788
|
end
|
@@ -10,7 +10,6 @@ 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
|
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.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -10,28 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-12-
|
13
|
+
date: 2017-12-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rdf
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '2.2'
|
22
|
-
- - "<"
|
19
|
+
- - "~>"
|
23
20
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
21
|
+
version: '3.0'
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
requirements:
|
29
|
-
- - "
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: '2.2'
|
32
|
-
- - "<"
|
26
|
+
- - "~>"
|
33
27
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
28
|
+
version: '3.0'
|
35
29
|
- !ruby/object:Gem::Dependency
|
36
30
|
name: net-http-persistent
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,45 +47,33 @@ dependencies:
|
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '4'
|
55
49
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
50
|
+
name: rdf-spec
|
57
51
|
requirement: !ruby/object:Gem::Requirement
|
58
52
|
requirements:
|
59
|
-
- - "
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.2'
|
62
|
-
- - "<"
|
53
|
+
- - "~>"
|
63
54
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
55
|
+
version: '3.0'
|
65
56
|
type: :development
|
66
57
|
prerelease: false
|
67
58
|
version_requirements: !ruby/object:Gem::Requirement
|
68
59
|
requirements:
|
69
|
-
- - "
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '2.2'
|
72
|
-
- - "<"
|
60
|
+
- - "~>"
|
73
61
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
62
|
+
version: '3.0'
|
75
63
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
64
|
+
name: sparql
|
77
65
|
requirement: !ruby/object:Gem::Requirement
|
78
66
|
requirements:
|
79
|
-
- - "
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '2.2'
|
82
|
-
- - "<"
|
67
|
+
- - "~>"
|
83
68
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
69
|
+
version: '3.0'
|
85
70
|
type: :development
|
86
71
|
prerelease: false
|
87
72
|
version_requirements: !ruby/object:Gem::Requirement
|
88
73
|
requirements:
|
89
|
-
- - "
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '2.2'
|
92
|
-
- - "<"
|
74
|
+
- - "~>"
|
93
75
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
76
|
+
version: '3.0'
|
95
77
|
- !ruby/object:Gem::Dependency
|
96
78
|
name: rspec
|
97
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,28 +108,28 @@ dependencies:
|
|
126
108
|
requirements:
|
127
109
|
- - "~>"
|
128
110
|
- !ruby/object:Gem::Version
|
129
|
-
version: '3.
|
111
|
+
version: '3.1'
|
130
112
|
type: :development
|
131
113
|
prerelease: false
|
132
114
|
version_requirements: !ruby/object:Gem::Requirement
|
133
115
|
requirements:
|
134
116
|
- - "~>"
|
135
117
|
- !ruby/object:Gem::Version
|
136
|
-
version: '3.
|
118
|
+
version: '3.1'
|
137
119
|
- !ruby/object:Gem::Dependency
|
138
120
|
name: yard
|
139
121
|
requirement: !ruby/object:Gem::Requirement
|
140
122
|
requirements:
|
141
123
|
- - "~>"
|
142
124
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
125
|
+
version: 0.9.12
|
144
126
|
type: :development
|
145
127
|
prerelease: false
|
146
128
|
version_requirements: !ruby/object:Gem::Requirement
|
147
129
|
requirements:
|
148
130
|
- - "~>"
|
149
131
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
132
|
+
version: 0.9.12
|
151
133
|
description: |-
|
152
134
|
Executes SPARQL queries and updates against a remote SPARQL 1.0 or 1.1 endpoint,
|
153
135
|
or against a local repository. Generates SPARQL queries using a simple DSL.
|