sparql 3.1.3 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -586,7 +586,7 @@ module SPARQL::Grammar
586
586
  production(:GroupGraphPatternSub) do |input, data, callback|
587
587
  debug("GroupGraphPatternSub") {"q #{data[:query].inspect}"}
588
588
 
589
- res = case data[:query].length
589
+ res = case Array(data[:query]).length
590
590
  when 0 then SPARQL::Algebra::Operator::BGP.new
591
591
  when 1 then data[:query].first
592
592
  when 2
@@ -867,9 +867,17 @@ module SPARQL::Grammar
867
867
  add_prod_datum(:path, data[:path])
868
868
  end
869
869
 
870
- # [80] Object ::= GraphNode
870
+ # [177] AnnotationPattern ::= '{|' PropertyListNotEmpty '|}'
871
+ start_production(:AnnotationPattern) do |input, data, callback|
872
+ data[:TriplesNode] = prod_data[:pattern].first
873
+ end
874
+ production(:AnnotationPattern) do |input, data, callback|
875
+ add_prod_datum(:pattern, data[:pattern])
876
+ end
877
+
878
+ # [80] Object ::= GraphNode | EmbTP
871
879
  production(:Object) do |input, data, callback|
872
- object = data[:VarOrTerm] || data[:TriplesNode] || data[:GraphNode]
880
+ object = data[:GraphNode] || data[:EmbTP]
873
881
  if object
874
882
  if prod_data[:Verb]
875
883
  add_pattern(:Object, subject: prod_data[:Subject], predicate: prod_data[:Verb], object: object)
@@ -1114,11 +1122,6 @@ module SPARQL::Grammar
1114
1122
  data.values.each {|v| add_prod_datum(:VarOrIri, v)}
1115
1123
  end
1116
1124
 
1117
- # [107s] VarOrBlankNodeOrIriOrEmbTP ::= Var | BlankNode| iri | EmbTP
1118
- production(:VarOrBlankNodeOrIriOrEmbTP) do |input, data, callback|
1119
- data.values.each {|v| add_prod_datum(:VarOrBlankNodeOrIriOrEmbTP, v)}
1120
- end
1121
-
1122
1125
  # [109] GraphTerm ::= iri | RDFLiteral | NumericLiteral
1123
1126
  # | BooleanLiteral | BlankNode | NIL
1124
1127
  production(:GraphTerm) do |input, data, callback|
@@ -1129,17 +1132,22 @@ module SPARQL::Grammar
1129
1132
  data[:NIL])
1130
1133
  end
1131
1134
 
1132
- # [1xx] EmbTP ::= '<<' VarOrBlankNodeOrIriOrEmbTP Verb VarOrTermOrEmbTP '>>'
1135
+ # [174] EmbTP ::= '<<' EmbSubjectOrObject Verb EmbSubjectOrObject '>>'
1133
1136
  production(:EmbTP) do |input, data, callback|
1134
- subject = data[:VarOrBlankNodeOrIriOrEmbTP]
1137
+ subject, object = data[:EmbSubjectOrObject]
1135
1138
  predicate = data[:Verb]
1136
- object = data[:VarOrTerm]
1137
1139
  add_pattern(:EmbTP,
1138
1140
  subject: subject,
1139
1141
  predicate: predicate,
1140
1142
  object: object)
1141
1143
  end
1142
1144
 
1145
+ # [175] EmbSubjectOrObject ::= Var | BlankNode | iri | RDFLiteral
1146
+ # | NumericLiteral | BooleanLiteral | EmbTP
1147
+ production(:EmbSubjectOrObject) do |input, data, callback|
1148
+ data.values.each {|v| add_prod_datum(:EmbSubjectOrObject, v)}
1149
+ end
1150
+
1143
1151
  # [110] Expression ::= ConditionalOrExpression
1144
1152
  production(:Expression) do |input, data, callback|
1145
1153
  add_prod_datum(:Expression, data[:Expression])
@@ -1479,10 +1487,8 @@ module SPARQL::Grammar
1479
1487
  # definitions.
1480
1488
  # @option options [Boolean] :validate (false)
1481
1489
  # whether to validate the parsed statements and values
1482
- # @option options [Boolean] :progress
1483
- # Show progress of parser productions
1484
- # @option options [Boolean] :debug
1485
- # Detailed debug output
1490
+ # @option options [Logger, #write, #<<] :logger
1491
+ # Record error/info/debug output
1486
1492
  # @yield [parser] `self`
1487
1493
  # @yieldparam [SPARQL::Grammar::Parser] parser
1488
1494
  # @yieldreturn [void] ignored
@@ -1494,10 +1500,6 @@ module SPARQL::Grammar
1494
1500
  end
1495
1501
  @input.encode!(Encoding::UTF_8) if @input.respond_to?(:encode!)
1496
1502
  @options = {anon_base: "b0", validate: false}.merge(options)
1497
- @options[:debug] ||= case
1498
- when options[:progress] then 2
1499
- when options[:validate] then 1
1500
- end
1501
1503
 
1502
1504
  debug("base IRI") {base_uri.inspect}
1503
1505
  debug("validate") {validate?.inspect}
@@ -1558,23 +1560,7 @@ module SPARQL::Grammar
1558
1560
  follow: FOLLOW,
1559
1561
  whitespace: WS,
1560
1562
  **@options
1561
- ) do |context, *data|
1562
- case context
1563
- when :trace
1564
- level, lineno, depth, *args = data
1565
- message = args.to_sse
1566
- d_str = depth > 100 ? ' ' * 100 + '+' : ' ' * depth
1567
- str = "[#{lineno}](#{level})#{d_str}#{message}".chop
1568
- case @options[:debug]
1569
- when Array
1570
- @options[:debug] << str unless level > 2
1571
- when TrueClass
1572
- $stderr.puts str
1573
- when Integer
1574
- $stderr.puts(str) if level <= @options[:debug]
1575
- end
1576
- end
1577
- end
1563
+ )
1578
1564
 
1579
1565
  # The last thing on the @prod_data stack is the result
1580
1566
  @result = case
@@ -111,6 +111,7 @@ module SPARQL::Grammar
111
111
  |true
112
112
  |false
113
113
  |<<|>>
114
+ |\{\||\|\}
114
115
  |&&|!=|!|<=|>=|\^\^|\|\||[\(\),.;\[\]\{\}\+\-=<>\?\^\|\*\/a]
115
116
  )xim.freeze
116
117
 
@@ -34,9 +34,9 @@ module SPARQL
34
34
  {
35
35
  type: 'triple',
36
36
  value: {
37
- s: format.call(value.subject),
38
- p: format.call(value.predicate),
39
- o: format.call(value.object)
37
+ subject: format.call(value.subject),
38
+ predicate: format.call(value.predicate),
39
+ object: format.call(value.object)
40
40
  }
41
41
  }
42
42
  end
@@ -81,9 +81,9 @@ module SPARQL
81
81
  end
82
82
  when RDF::Statement
83
83
  xml.triple do
84
- xml.s {format.call(s.subject)}
85
- xml.p {format.call(s.predicate)}
86
- xml.o {format.call(s.object)}
84
+ xml.subject {format.call(s.subject)}
85
+ xml.predicate {format.call(s.predicate)}
86
+ xml.object {format.call(s.object)}
87
87
  end
88
88
  end
89
89
  end
@@ -140,9 +140,8 @@ module SPARQL
140
140
  # Generate Solutions as CSV
141
141
  # @return [String]
142
142
  # @see https://www.w3.org/TR/2013/REC-sparql11-results-csv-tsv-20130321/
143
- def to_csv
143
+ def to_csv(bnode_map: {})
144
144
  require 'csv' unless defined?(::CSV)
145
- bnode_map = {}
146
145
  bnode_gen = "_:a"
147
146
  CSV.generate(row_sep: "\r\n") do |csv|
148
147
  csv << variable_names.to_a
@@ -155,6 +154,10 @@ module SPARQL
155
154
  bnode_gen = bnode_gen.succ
156
155
  this
157
156
  end
157
+ when RDF::Statement
158
+ RDF::Query::Solutions(
159
+ RDF::Query::Solution.new(subject: term.subject, predicate: term.predicate, object: term.object)
160
+ ).to_csv(bnode_map: bnode_map).split.last.strip
158
161
  else
159
162
  solution[n].to_s.strip
160
163
  end
@@ -175,10 +178,15 @@ module SPARQL
175
178
  case term = solution[n]
176
179
  when RDF::Literal::Integer, RDF::Literal::Decimal, RDF::Literal::Double
177
180
  term.canonicalize.to_s
181
+ when RDF::Statement
182
+ emb_stmt = RDF::Query::Solutions(
183
+ RDF::Query::Solution.new(subject: term.subject, predicate: term.predicate, object: term.object)
184
+ ).to_tsv.split("\n").last.strip
185
+ emb_stmt.gsub(/[\t\n\r]/, "\t" => '\t', "\n" => '\n', "\r" => '\r')
178
186
  when nil
179
187
  ""
180
188
  else
181
- RDF::NTriples.serialize(term).strip
189
+ RDF::NTriples.serialize(term).strip.gsub(/[\t\n\r]/, "\t" => '\t', "\n" => '\n', "\r" => '\r')
182
190
  end
183
191
  end.join("\t")
184
192
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparql
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-13 00:00:00.000000000 Z
12
+ date: 2020-12-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '3.1'
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 3.1.2
23
+ version: 3.1.8
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '3.1'
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.1.2
33
+ version: 3.1.8
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdf-aggregate-repo
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -49,16 +49,16 @@ dependencies:
49
49
  name: ebnf
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.1'
54
+ version: '2.1'
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.1'
61
+ version: '2.1'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: builder
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -177,48 +177,28 @@ dependencies:
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '3.0'
181
- type: :development
182
- prerelease: false
183
- version_requirements: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: '3.0'
188
- - !ruby/object:Gem::Dependency
189
- name: open-uri-cached
190
- requirement: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: '0.0'
195
- - - ">="
196
- - !ruby/object:Gem::Version
197
- version: 0.0.5
180
+ version: '3.1'
198
181
  type: :development
199
182
  prerelease: false
200
183
  version_requirements: !ruby/object:Gem::Requirement
201
184
  requirements:
202
185
  - - "~>"
203
186
  - !ruby/object:Gem::Version
204
- version: '0.0'
205
- - - ">="
206
- - !ruby/object:Gem::Version
207
- version: 0.0.5
187
+ version: '3.1'
208
188
  - !ruby/object:Gem::Dependency
209
189
  name: rspec
210
190
  requirement: !ruby/object:Gem::Requirement
211
191
  requirements:
212
192
  - - "~>"
213
193
  - !ruby/object:Gem::Version
214
- version: '3.9'
194
+ version: '3.10'
215
195
  type: :development
216
196
  prerelease: false
217
197
  version_requirements: !ruby/object:Gem::Requirement
218
198
  requirements:
219
199
  - - "~>"
220
200
  - !ruby/object:Gem::Version
221
- version: '3.9'
201
+ version: '3.10'
222
202
  - !ruby/object:Gem::Dependency
223
203
  name: rspec-its
224
204
  requirement: !ruby/object:Gem::Requirement
@@ -239,14 +219,14 @@ dependencies:
239
219
  requirements:
240
220
  - - "~>"
241
221
  - !ruby/object:Gem::Version
242
- version: 0.9.20
222
+ version: '0.9'
243
223
  type: :development
244
224
  prerelease: false
245
225
  version_requirements: !ruby/object:Gem::Requirement
246
226
  requirements:
247
227
  - - "~>"
248
228
  - !ruby/object:Gem::Version
249
- version: 0.9.20
229
+ version: '0.9'
250
230
  description: |2-
251
231
 
252
232
  Implements SPARQL grammar parsing to SPARQL Algebra, SPARQL Algebra processing