rdf 2.1.1 → 2.2.0.pre.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rdf.rb +2 -2
- data/lib/rdf/changeset.rb +2 -2
- data/lib/rdf/cli.rb +18 -12
- data/lib/rdf/format.rb +1 -1
- data/lib/rdf/mixin/enumerable.rb +22 -7
- data/lib/rdf/mixin/enumerator.rb +40 -4
- data/lib/rdf/mixin/queryable.rb +3 -3
- data/lib/rdf/model/dataset.rb +1 -1
- data/lib/rdf/model/graph.rb +4 -4
- data/lib/rdf/model/literal.rb +42 -20
- data/lib/rdf/model/literal/boolean.rb +5 -6
- data/lib/rdf/model/literal/date.rb +5 -6
- data/lib/rdf/model/literal/datetime.rb +3 -4
- data/lib/rdf/model/literal/decimal.rb +12 -8
- data/lib/rdf/model/literal/double.rb +5 -6
- data/lib/rdf/model/literal/integer.rb +6 -7
- data/lib/rdf/model/literal/time.rb +5 -6
- data/lib/rdf/model/literal/token.rb +6 -7
- data/lib/rdf/model/node.rb +1 -1
- data/lib/rdf/model/statement.rb +43 -15
- data/lib/rdf/model/uri.rb +23 -5
- data/lib/rdf/nquads.rb +2 -2
- data/lib/rdf/ntriples/reader.rb +13 -10
- data/lib/rdf/ntriples/writer.rb +18 -19
- data/lib/rdf/query.rb +33 -30
- data/lib/rdf/query/hash_pattern_normalizer.rb +2 -2
- data/lib/rdf/query/pattern.rb +5 -4
- data/lib/rdf/query/solution.rb +25 -13
- data/lib/rdf/query/variable.rb +20 -2
- data/lib/rdf/reader.rb +33 -22
- data/lib/rdf/repository.rb +2 -2
- data/lib/rdf/transaction.rb +1 -1
- data/lib/rdf/util/file.rb +34 -41
- data/lib/rdf/util/logger.rb +36 -36
- data/lib/rdf/util/uuid.rb +3 -2
- data/lib/rdf/vocab/writer.rb +4 -4
- data/lib/rdf/vocabulary.rb +10 -12
- data/lib/rdf/writer.rb +32 -22
- metadata +6 -6
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -182,15 +182,14 @@ module RDF::NTriples
|
|
182
182
|
#
|
183
183
|
# @param [IO, File] output
|
184
184
|
# the output stream
|
185
|
-
# @param
|
186
|
-
# any additional options. See {RDF::Writer#initialize}
|
187
|
-
# @option options [Boolean] :validate (true)
|
185
|
+
# @param [Boolean] validate (true)
|
188
186
|
# whether to validate terms when serializing
|
187
|
+
# @param [Hash{Symbol => Object}] options ({})
|
188
|
+
# any additional options. See {RDF::Writer#initialize}
|
189
189
|
# @yield [writer] `self`
|
190
190
|
# @yieldparam [RDF::Writer] writer
|
191
191
|
# @yieldreturn [void]
|
192
|
-
def initialize(output = $stdout,
|
193
|
-
options = {validate: true}.merge(options)
|
192
|
+
def initialize(output = $stdout, validate: true, **options, &block)
|
194
193
|
super
|
195
194
|
end
|
196
195
|
|
@@ -218,10 +217,10 @@ module RDF::NTriples
|
|
218
217
|
# Returns the N-Triples representation of a statement.
|
219
218
|
#
|
220
219
|
# @param [RDF::Statement] statement
|
221
|
-
# @param [Hash{Symbol => Object}] options
|
220
|
+
# @param [Hash{Symbol => Object}] options ({})
|
222
221
|
# @return [String]
|
223
|
-
def format_statement(statement, options
|
224
|
-
format_triple(*statement.to_triple, options)
|
222
|
+
def format_statement(statement, **options)
|
223
|
+
format_triple(*statement.to_triple, **options)
|
225
224
|
end
|
226
225
|
|
227
226
|
##
|
@@ -230,31 +229,31 @@ module RDF::NTriples
|
|
230
229
|
# @param [RDF::Resource] subject
|
231
230
|
# @param [RDF::URI] predicate
|
232
231
|
# @param [RDF::Term] object
|
233
|
-
# @param [Hash{Symbol => Object}] options
|
232
|
+
# @param [Hash{Symbol => Object}] options ({})
|
234
233
|
# @return [String]
|
235
|
-
def format_triple(subject, predicate, object, options
|
236
|
-
"%s %s %s ." % [subject, predicate, object].map { |value| format_term(value, options) }
|
234
|
+
def format_triple(subject, predicate, object, **options)
|
235
|
+
"%s %s %s ." % [subject, predicate, object].map { |value| format_term(value, **options) }
|
237
236
|
end
|
238
237
|
|
239
238
|
##
|
240
239
|
# Returns the N-Triples representation of a blank node.
|
241
240
|
#
|
242
241
|
# @param [RDF::Node] node
|
243
|
-
# @param
|
244
|
-
# @option options [Boolean] :unique_bnodes (false)
|
242
|
+
# @param [Boolean] unique_bnodes (false)
|
245
243
|
# Serialize node using unique identifier, rather than any used to create the node.
|
244
|
+
# @param [Hash{Symbol => Object}] options ({})
|
246
245
|
# @return [String]
|
247
|
-
def format_node(node,
|
248
|
-
|
246
|
+
def format_node(node, unique_bnodes: false, **options)
|
247
|
+
unique_bnodes ? node.to_unique_base : node.to_s
|
249
248
|
end
|
250
249
|
|
251
250
|
##
|
252
251
|
# Returns the N-Triples representation of a URI reference using write encoding.
|
253
252
|
#
|
254
253
|
# @param [RDF::URI] uri
|
255
|
-
# @param [Hash{Symbol => Object}] options
|
254
|
+
# @param [Hash{Symbol => Object}] options ({})
|
256
255
|
# @return [String]
|
257
|
-
def format_uri(uri, options
|
256
|
+
def format_uri(uri, **options)
|
258
257
|
string = uri.to_s
|
259
258
|
iriref = case
|
260
259
|
when string =~ ESCAPE_PLAIN_U # a shortcut for the simple case
|
@@ -296,9 +295,9 @@ module RDF::NTriples
|
|
296
295
|
# Returns the N-Triples representation of a literal.
|
297
296
|
#
|
298
297
|
# @param [RDF::Literal, String, #to_s] literal
|
299
|
-
# @param [Hash{Symbol => Object}] options
|
298
|
+
# @param [Hash{Symbol => Object}] options ({})
|
300
299
|
# @return [String]
|
301
|
-
def format_literal(literal, options
|
300
|
+
def format_literal(literal, **options)
|
302
301
|
case literal
|
303
302
|
when RDF::Literal
|
304
303
|
# Note, escaping here is more robust than in Term
|
data/lib/rdf/query.rb
CHANGED
@@ -109,7 +109,7 @@ module RDF
|
|
109
109
|
# @param [Array<Solution>] args
|
110
110
|
# @return [Solutions] returns new solutions including the arguments, which must each be a {Solution}
|
111
111
|
def self.Solutions(*args)
|
112
|
-
|
112
|
+
if args.length == 1
|
113
113
|
return args[0] if args[0].is_a?(Solutions)
|
114
114
|
args = args[0] if args[0].is_a?(Array)
|
115
115
|
end
|
@@ -143,7 +143,7 @@ module RDF
|
|
143
143
|
##
|
144
144
|
# Initializes a new basic graph pattern query.
|
145
145
|
#
|
146
|
-
# @overload initialize(patterns = [], options
|
146
|
+
# @overload initialize(patterns = [], **options)
|
147
147
|
# @param [Array<RDF::Query::Pattern>] patterns
|
148
148
|
# ...
|
149
149
|
# @param [Hash{Symbol => Object}] options
|
@@ -162,32 +162,31 @@ module RDF
|
|
162
162
|
# @yieldparam [RDF::Query] query
|
163
163
|
# @yieldreturn [void] ignored
|
164
164
|
#
|
165
|
-
# @overload initialize(patterns, options
|
165
|
+
# @overload initialize(patterns, **options)
|
166
166
|
# @param [Hash{Object => Object}] patterns
|
167
167
|
# ...
|
168
|
-
# @param
|
169
|
-
#
|
170
|
-
# @option options [RDF::Query::Solutions] :solutions (Solutions.new)
|
171
|
-
# @option options [RDF::Resource, RDF::Query::Variable, false] :graph_name (nil)
|
168
|
+
# @param [RDF::Query::Solutions] solutions (Solutions.new)
|
169
|
+
# @param [RDF::Resource, RDF::Query::Variable, false] graph_name (false)
|
172
170
|
# Default graph name for matching against queryable.
|
173
171
|
# Named queries either match against a specifically named
|
174
172
|
# graphs if the name is an {RDF::Resource} or bound {RDF::Query::Variable}.
|
175
173
|
# Names that are against unbound variables match either default
|
176
174
|
# or named graphs.
|
177
175
|
# The name of `false` will only match against the default graph.
|
178
|
-
# @
|
176
|
+
# @param [RDF::Resource, RDF::Query::Variable, false] name (false)
|
179
177
|
# Alias for `:graph_name`.
|
178
|
+
# @param [Hash{Symbol => Object}] options
|
179
|
+
# any additional keyword options
|
180
180
|
# @yield [query]
|
181
181
|
# @yieldparam [RDF::Query] query
|
182
182
|
# @yieldreturn [void] ignored
|
183
|
-
def initialize(*patterns, &block)
|
184
|
-
@options
|
185
|
-
patterns << @options if patterns.empty?
|
183
|
+
def initialize(*patterns, solutions: nil, graph_name: nil, name: nil, **options, &block)
|
184
|
+
@options = options.dup
|
186
185
|
@variables = {}
|
187
|
-
@solutions = Query::Solutions(
|
188
|
-
graph_name =
|
189
|
-
|
190
|
-
@options.
|
186
|
+
@solutions = Query::Solutions(solutions)
|
187
|
+
graph_name = name if graph_name.nil?
|
188
|
+
|
189
|
+
patterns << @options if patterns.empty?
|
191
190
|
|
192
191
|
@patterns = case patterns.first
|
193
192
|
when Hash then compile_hash_patterns(HashPatternNormalizer.normalize!(patterns.first.dup, @options))
|
@@ -226,7 +225,7 @@ module RDF
|
|
226
225
|
# @option options [Boolean] :optional (false)
|
227
226
|
# whether this is an optional pattern
|
228
227
|
# @return [void] self
|
229
|
-
def pattern(pattern, options
|
228
|
+
def pattern(pattern, **options)
|
230
229
|
@patterns << Pattern.from(pattern, options)
|
231
230
|
self
|
232
231
|
end
|
@@ -238,7 +237,7 @@ module RDF
|
|
238
237
|
# any additional options for optimization
|
239
238
|
# @return [RDF::Query] a copy of `self`
|
240
239
|
# @since 0.3.0
|
241
|
-
def optimize(options
|
240
|
+
def optimize(**options)
|
242
241
|
self.dup.optimize!(options)
|
243
242
|
end
|
244
243
|
|
@@ -251,7 +250,7 @@ module RDF
|
|
251
250
|
# @return [self]
|
252
251
|
# @see RDF::Query::Pattern#cost
|
253
252
|
# @since 0.3.0
|
254
|
-
def optimize!(options
|
253
|
+
def optimize!(**options)
|
255
254
|
@patterns.sort! do |a, b|
|
256
255
|
(a.cost || 0) <=> (b.cost || 0)
|
257
256
|
end
|
@@ -274,15 +273,20 @@ module RDF
|
|
274
273
|
#
|
275
274
|
# @param [RDF::Queryable] queryable
|
276
275
|
# the graph or repository to query
|
276
|
+
# @param [RDF::Query::Solutions] solutions (Solutions.new)
|
277
|
+
# @param [RDF::Resource, RDF::Query::Variable, false] graph_name (nil)
|
278
|
+
# Default graph name for matching against queryable.
|
279
|
+
# Named queries either match against a specifically named
|
280
|
+
# graphs if the name is an {RDF::Resource} or bound {RDF::Query::Variable}.
|
281
|
+
# Names that are against unbound variables match either default
|
282
|
+
# or named graphs.
|
283
|
+
# The name of `false` will only match against the default graph.
|
284
|
+
# @param [RDF::Resource, RDF::Query::Variable, false] name (nil)
|
285
|
+
# Alias for `:graph_name`.
|
277
286
|
# @param [Hash{Symbol => Object}] options
|
278
287
|
# any additional keyword options
|
279
288
|
# @option options [Hash{Symbol => RDF::Term}] bindings
|
280
289
|
# optional variable bindings to use
|
281
|
-
# @option options [RDF::Resource, RDF::Query::Variable, false] graph_name (nil)
|
282
|
-
# Specific graph name for matching against queryable;
|
283
|
-
# overrides default graph defined on query.
|
284
|
-
# @option options [RDF::Resource, RDF::Query::Variable, false] name (nil)
|
285
|
-
# Alias for `:graph_name`.
|
286
290
|
# @option options [RDF::Query::Solutions] solutions
|
287
291
|
# optional initial solutions for chained queries
|
288
292
|
# @yield [solution]
|
@@ -293,17 +297,14 @@ module RDF
|
|
293
297
|
# the resulting solution sequence
|
294
298
|
# @see http://www.holygoat.co.uk/blog/entry/2005-10-25-1
|
295
299
|
# @see http://www.w3.org/TR/sparql11-query/#emptyGroupPattern
|
296
|
-
def execute(queryable,
|
300
|
+
def execute(queryable, solutions: Solution.new, graph_name: nil, name: nil, **options, &block)
|
297
301
|
validate!
|
298
|
-
options = options
|
299
|
-
|
300
|
-
# just so we can call #keys below without worrying
|
301
|
-
options[:bindings] ||= {}
|
302
|
+
options = {bindings: {}}.merge(options)
|
302
303
|
|
303
304
|
# Use provided solutions to allow for query chaining
|
304
305
|
# Otherwise, a quick empty solution simplifies the logic below; no special case for
|
305
306
|
# the first pattern
|
306
|
-
@solutions = Query::Solutions(
|
307
|
+
@solutions = Query::Solutions(solutions)
|
307
308
|
|
308
309
|
# If there are no patterns, just return the empty solution
|
309
310
|
if empty?
|
@@ -312,7 +313,9 @@ module RDF
|
|
312
313
|
end
|
313
314
|
|
314
315
|
patterns = @patterns
|
315
|
-
graph_name =
|
316
|
+
graph_name = name if graph_name.nil?
|
317
|
+
graph_name = self.graph_name if graph_name.nil?
|
318
|
+
options[:graph_name] = graph_name unless graph_name.nil?
|
316
319
|
|
317
320
|
# Add graph_name to pattern, if necessary
|
318
321
|
unless graph_name.nil?
|
@@ -173,7 +173,7 @@ module RDF; class Query
|
|
173
173
|
# any additional normalization options.
|
174
174
|
# @option options [String] :anonymous_subject_format ("__%s__")
|
175
175
|
# the string format for anonymous subjects.
|
176
|
-
def initialize(options
|
176
|
+
def initialize(**options)
|
177
177
|
@options = options.dup
|
178
178
|
end
|
179
179
|
|
@@ -184,7 +184,7 @@ module RDF; class Query
|
|
184
184
|
# the query pattern as a hash.
|
185
185
|
# @return [Hash{Symbol => Object}]
|
186
186
|
# the resulting query pattern as a normalized hash.
|
187
|
-
def normalize!(hash_pattern
|
187
|
+
def normalize!(**hash_pattern)
|
188
188
|
self.class.normalize!(hash_pattern, @options)
|
189
189
|
end
|
190
190
|
end # RDF::Query::HashPatternNormalizer
|
data/lib/rdf/query/pattern.rb
CHANGED
@@ -5,18 +5,19 @@ module RDF; class Query
|
|
5
5
|
##
|
6
6
|
# @private
|
7
7
|
# @since 0.2.2
|
8
|
-
def self.from(pattern,
|
8
|
+
def self.from(pattern, graph_name: nil, **options)
|
9
9
|
case pattern
|
10
10
|
when Pattern then pattern
|
11
11
|
when Array, Statement
|
12
|
-
|
12
|
+
graph_name ||= pattern[3]
|
13
|
+
self.new(pattern[0], pattern[1], pattern[2], graph_name: graph_name, **options)
|
13
14
|
when Hash then self.new(options.merge(pattern))
|
14
15
|
else raise ArgumentError, "expected RDF::Query::Pattern, RDF::Statement, Hash, or Array, but got #{pattern.inspect}"
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
##
|
19
|
-
# @overload initialize(options
|
20
|
+
# @overload initialize(**options)
|
20
21
|
# @param [Hash{Symbol => Object}] options
|
21
22
|
# @option options [Variable, Resource, Symbol, nil] :subject (nil)
|
22
23
|
# @option options [Variable, URI, Symbol, nil] :predicate (nil)
|
@@ -25,7 +26,7 @@ module RDF; class Query
|
|
25
26
|
# A graph_name of nil matches any graph, a graph_name of false, matches only the default graph.
|
26
27
|
# @option options [Boolean] :optional (false)
|
27
28
|
#
|
28
|
-
# @overload initialize(subject, predicate, object, options
|
29
|
+
# @overload initialize(subject, predicate, object, **options)
|
29
30
|
# @param [Variable, Resource, Symbol, nil] subject
|
30
31
|
# @param [Variable, URI, Symbol, nil] predicate
|
31
32
|
# @param [Variable, Termm, Symbol, nil] object
|
data/lib/rdf/query/solution.rb
CHANGED
@@ -18,7 +18,7 @@ class RDF::Query
|
|
18
18
|
# solution.mbox
|
19
19
|
#
|
20
20
|
# @example Retrieving all bindings in the solution as a `Hash`
|
21
|
-
# solution.
|
21
|
+
# solution.to_h #=> {mbox: "jrhacker@example.org", ...}
|
22
22
|
#
|
23
23
|
class Solution
|
24
24
|
# Undefine all superfluous instance methods:
|
@@ -152,12 +152,12 @@ class RDF::Query
|
|
152
152
|
# Merges the bindings from the given `other` query solution into this
|
153
153
|
# one, overwriting any existing ones having the same name.
|
154
154
|
#
|
155
|
-
# @param [RDF::Query::Solution, #
|
155
|
+
# @param [RDF::Query::Solution, #to_h] other
|
156
156
|
# another query solution or hash bindings
|
157
157
|
# @return [void] self
|
158
158
|
# @since 0.3.0
|
159
159
|
def merge!(other)
|
160
|
-
@bindings.merge!(other.
|
160
|
+
@bindings.merge!(other.to_h)
|
161
161
|
self
|
162
162
|
end
|
163
163
|
|
@@ -165,7 +165,7 @@ class RDF::Query
|
|
165
165
|
# Merges the bindings from the given `other` query solution with a copy
|
166
166
|
# of this one.
|
167
167
|
#
|
168
|
-
# @param [RDF::Query::Solution, #
|
168
|
+
# @param [RDF::Query::Solution, #to_h] other
|
169
169
|
# another query solution or hash bindings
|
170
170
|
# @return [RDF::Query::Solution]
|
171
171
|
# @since 0.3.0
|
@@ -185,13 +185,13 @@ class RDF::Query
|
|
185
185
|
#
|
186
186
|
# Two solution mappings u1 and u2 are compatible if, for every variable v in dom(u1) and in dom(u2), u1(v) = u2(v).
|
187
187
|
#
|
188
|
-
# @param [RDF::Query::Solution, #
|
188
|
+
# @param [RDF::Query::Solution, #to_h] other
|
189
189
|
# another query solution or hash bindings
|
190
190
|
# @return [Boolean]
|
191
191
|
# @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#defn_algCompatibleMapping
|
192
192
|
def compatible?(other)
|
193
193
|
@bindings.all? do |k, v|
|
194
|
-
!other.
|
194
|
+
!other.to_h.has_key?(k) || other[k].eql?(v)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -205,7 +205,7 @@ class RDF::Query
|
|
205
205
|
# @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#defn_algMinus
|
206
206
|
def disjoint?(other)
|
207
207
|
@bindings.none? do |k, v|
|
208
|
-
v && other.
|
208
|
+
v && other.to_h.has_key?(k) && other[k].eql?(v)
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
@@ -214,12 +214,12 @@ class RDF::Query
|
|
214
214
|
# Two solution mappings u1 and u2 are isomorphic if,
|
215
215
|
# for every variable v in dom(u1) and in dom(u2), u1(v) = u2(v).
|
216
216
|
#
|
217
|
-
# @param [RDF::Query::Solution, #
|
217
|
+
# @param [RDF::Query::Solution, #to_h] other
|
218
218
|
# another query solution or hash bindings
|
219
219
|
# @return [Boolean]
|
220
220
|
def isomorphic_with?(other)
|
221
221
|
@bindings.all? do |k, v|
|
222
|
-
!other.
|
222
|
+
!other.to_h.has_key?(k) || other[k].eql?(v)
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
@@ -231,7 +231,7 @@ class RDF::Query
|
|
231
231
|
|
232
232
|
##
|
233
233
|
# @return [Hash{Symbol => RDF::Term}}
|
234
|
-
def
|
234
|
+
def to_h
|
235
235
|
@bindings.dup
|
236
236
|
end
|
237
237
|
|
@@ -264,10 +264,22 @@ class RDF::Query
|
|
264
264
|
protected
|
265
265
|
|
266
266
|
##
|
267
|
-
# @
|
268
|
-
#
|
267
|
+
# @overload #to_hash
|
268
|
+
# Returns object representation of this URI, broken into components
|
269
|
+
#
|
270
|
+
# @return (see #to_h)
|
271
|
+
# @deprecated Use {#to_h} instead.
|
272
|
+
#
|
273
|
+
# @overload binding(name)
|
274
|
+
# Return the binding for this name
|
275
|
+
#
|
276
|
+
# @param [Symbol] name
|
277
|
+
# @return [RDF::Term]
|
269
278
|
def method_missing(name, *args, &block)
|
270
|
-
if
|
279
|
+
if name == :to_hash
|
280
|
+
warn "[DEPRECATION] Solution#to_hash is deprecated, use Solution#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
|
281
|
+
self.to_h
|
282
|
+
elsif args.empty? && @bindings.has_key?(name.to_sym)
|
271
283
|
@bindings[name.to_sym]
|
272
284
|
else
|
273
285
|
super # raises NoMethodError
|
data/lib/rdf/query/variable.rb
CHANGED
@@ -151,7 +151,7 @@ class RDF::Query
|
|
151
151
|
def variables
|
152
152
|
{name => self}
|
153
153
|
end
|
154
|
-
alias_method :
|
154
|
+
alias_method :to_h, :variables
|
155
155
|
|
156
156
|
##
|
157
157
|
# Returns this variable's bindings (if any) as a `Hash`.
|
@@ -164,7 +164,7 @@ class RDF::Query
|
|
164
164
|
##
|
165
165
|
# Returns a hash code for this variable.
|
166
166
|
#
|
167
|
-
# @return [
|
167
|
+
# @return [Integer]
|
168
168
|
# @since 0.3.0
|
169
169
|
def hash
|
170
170
|
@name.hash
|
@@ -219,5 +219,23 @@ class RDF::Query
|
|
219
219
|
prefix = distinguished? ? '?' : "??"
|
220
220
|
unbound? ? "#{prefix}#{name}" : "#{prefix}#{name}=#{value}"
|
221
221
|
end
|
222
|
+
|
223
|
+
protected
|
224
|
+
##
|
225
|
+
# @overload #to_hash
|
226
|
+
# Returns object representation of this URI, broken into components
|
227
|
+
#
|
228
|
+
# @return (see #object)
|
229
|
+
# @deprecated Use {#to_h} instead.
|
230
|
+
def method_missing(name, *args, &block)
|
231
|
+
if name == :to_hash
|
232
|
+
warn "[DEPRECATION] Variable#to_hash is deprecated, use Variable#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
|
233
|
+
self.to_h
|
234
|
+
elsif args.empty? && @bindings.has_key?(name.to_sym)
|
235
|
+
@bindings[name.to_sym]
|
236
|
+
else
|
237
|
+
super # raises NoMethodError
|
238
|
+
end
|
239
|
+
end
|
222
240
|
end # Variable
|
223
241
|
end # RDF::Query
|
data/lib/rdf/reader.rb
CHANGED
@@ -219,31 +219,43 @@ module RDF
|
|
219
219
|
#
|
220
220
|
# @param [IO, File, String] input
|
221
221
|
# the input stream to read
|
222
|
-
# @param
|
223
|
-
# any additional options
|
224
|
-
# @option options [Encoding] :encoding (Encoding::UTF_8)
|
222
|
+
# @param [Encoding] encoding (Encoding::UTF_8)
|
225
223
|
# the encoding of the input stream
|
226
|
-
# @
|
224
|
+
# @param [Boolean] validate (false)
|
227
225
|
# whether to validate the parsed statements and values
|
228
|
-
# @
|
226
|
+
# @param [Boolean] canonicalize (false)
|
229
227
|
# whether to canonicalize parsed literals
|
230
|
-
# @
|
228
|
+
# @param [Boolean] intern (true)
|
231
229
|
# whether to intern all parsed URIs
|
232
|
-
# @
|
230
|
+
# @param [Hash] prefixes (Hash.new)
|
233
231
|
# the prefix mappings to use (not supported by all readers)
|
234
|
-
# @
|
232
|
+
# @param [#to_s] base_uri (nil)
|
235
233
|
# the base URI to use when resolving relative URIs (not supported by
|
236
234
|
# all readers)
|
235
|
+
# @param [Hash{Symbol => Object}] options
|
236
|
+
# any additional options
|
237
237
|
# @yield [reader] `self`
|
238
238
|
# @yieldparam [RDF::Reader] reader
|
239
239
|
# @yieldreturn [void] ignored
|
240
|
-
def initialize(input = $stdin,
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
240
|
+
def initialize(input = $stdin,
|
241
|
+
encoding: Encoding::UTF_8,
|
242
|
+
validate: false,
|
243
|
+
canonicalize: false,
|
244
|
+
intern: true,
|
245
|
+
prefixes: Hash.new,
|
246
|
+
base_uri: nil,
|
247
|
+
**options,
|
248
|
+
&block)
|
249
|
+
|
250
|
+
base_uri ||= input.base_uri if input.respond_to?(:base_uri)
|
251
|
+
@options = options.merge({
|
252
|
+
encoding: encoding,
|
253
|
+
validate: validate,
|
254
|
+
canonicalize: canonicalize,
|
255
|
+
intern: intern,
|
256
|
+
prefixes: prefixes,
|
257
|
+
base_uri: base_uri
|
258
|
+
})
|
247
259
|
|
248
260
|
@input = case input
|
249
261
|
when String then StringIO.new(input)
|
@@ -619,13 +631,12 @@ module RDF
|
|
619
631
|
##
|
620
632
|
# Initializes a new lexer error instance.
|
621
633
|
#
|
622
|
-
# @param [String, #to_s]
|
623
|
-
# @param [
|
624
|
-
# @
|
625
|
-
|
626
|
-
|
627
|
-
@
|
628
|
-
@lineno = options[:lineno] || (@token.lineno if @token.respond_to?(:lineno))
|
634
|
+
# @param [String, #to_s] message
|
635
|
+
# @param [String] token (nil)
|
636
|
+
# @param [Integer] lineno (nil)
|
637
|
+
def initialize(message, token: nil, lineno: nil)
|
638
|
+
@token = token
|
639
|
+
@lineno = lineno || (token.lineno if token.respond_to?(:lineno))
|
629
640
|
super(message.to_s)
|
630
641
|
end
|
631
642
|
end # ReaderError
|