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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63643389b5260847e6a5ff81f8ec4e7a8d754adf
4
- data.tar.gz: b0ed32a9d7f1fd58efe6de87ab64f2eb0f10a758
3
+ metadata.gz: 996cb716d6311ccd569174d200c39d05a035e3b7
4
+ data.tar.gz: 23d718dd6a3e23cec61d02df0689d46dd87cf481
5
5
  SHA512:
6
- metadata.gz: fcfec9d172d4bb98f27136bdde32f242780080b05b1fa92390fa69f3c4faea3aad03971dc7d19b22026e228065210b86ccd543d6a749d7fe1d132737480e9459
7
- data.tar.gz: b0a1ce446f6930c620b78aee2978cd46b0c9d54f9fec3c08ea00c91f5761eeae083a19f07f00d8a48867505addb370d986d54ad9cb345dcd026826244caed2c3
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) (>= 2.0)
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) (>= 2.0)
99
- * Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.6)
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
- 2.2.1
1
+ 3.0.0
@@ -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: 2.2.1
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 00:00:00.000000000 Z
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: '4.0'
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: '4.0'
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: sparql
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: '4.0'
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: '4.0'
62
+ version: '3.0'
75
63
  - !ruby/object:Gem::Dependency
76
- name: rdf-spec
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: '4.0'
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: '4.0'
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.0'
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.0'
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: '0.9'
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: '0.9'
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.