rdf 3.0.13 → 3.1.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 -2
- data/VERSION +1 -1
- data/lib/rdf.rb +19 -12
- data/lib/rdf/changeset.rb +1 -1
- data/lib/rdf/cli.rb +6 -6
- data/lib/rdf/format.rb +17 -10
- data/lib/rdf/mixin/enumerable.rb +2 -2
- data/lib/rdf/mixin/mutable.rb +2 -2
- data/lib/rdf/mixin/queryable.rb +4 -4
- data/lib/rdf/model/graph.rb +2 -2
- data/lib/rdf/model/list.rb +5 -5
- data/lib/rdf/model/uri.rb +39 -20
- data/lib/rdf/nquads.rb +4 -4
- data/lib/rdf/ntriples/reader.rb +4 -4
- data/lib/rdf/ntriples/writer.rb +1 -1
- data/lib/rdf/query.rb +24 -35
- data/lib/rdf/query/hash_pattern_normalizer.rb +5 -4
- data/lib/rdf/query/pattern.rb +2 -2
- data/lib/rdf/reader.rb +11 -5
- data/lib/rdf/repository.rb +5 -5
- data/lib/rdf/transaction.rb +1 -1
- data/lib/rdf/util/file.rb +2 -2
- data/lib/rdf/util/logger.rb +6 -6
- data/lib/rdf/vocab/rdfv.rb +25 -0
- data/lib/rdf/vocabulary.rb +3 -3
- data/lib/rdf/writer.rb +16 -10
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2daf8eddad46785b68f11f655491114ece3425f5af8e283ec5372f186fbf0494
|
4
|
+
data.tar.gz: d84668437ad7b0c703bf0cec3a0c2cd50a25f6a81e4e1b9289b87c33b70fe18f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30730b50722a1d159fdc4acc7d226253101a28475925451e0dffd599a20b837146a21202d539125aa513ded6dc7de50c290d570a273963052a4820c304a291eb
|
7
|
+
data.tar.gz: 611b837819f8470547ca79cd6d948201e39c288f2e8f2da25f6c39e557abd5efa4b39b3c549d47f09bd75db53af84de3e46fc43f8ebcbc082245556c0ed06b39
|
data/README.md
CHANGED
@@ -29,7 +29,8 @@ This is a pure-Ruby library for working with [Resource Description Framework
|
|
29
29
|
not modify any of Ruby's core classes or standard library.
|
30
30
|
* Based entirely on Ruby's autoloading, meaning that you can generally make
|
31
31
|
use of any one part of the library without needing to load up the rest.
|
32
|
-
* Compatible with Ruby Ruby >= 2.
|
32
|
+
* Compatible with Ruby Ruby >= 2.4, Rubinius and JRuby 9.0+.
|
33
|
+
* Note, changes in mapping hashes to keyword arguments for Ruby 2.7+ may require that arguments be passed more explicitly, especially when the first argument is a Hash and there are optional keyword arguments. In this case, Hash argument may need to be explicitly included within `{}` and the optional keyword arguments may need to be specified using `**{}` if there are no keyword arguments.
|
33
34
|
* Performs auto-detection of input to select appropriate Reader class if one
|
34
35
|
cannot be determined from file characteristics.
|
35
36
|
|
@@ -189,7 +190,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
|
|
189
190
|
FOAF.name => :name,
|
190
191
|
FOAF.mbox => :email,
|
191
192
|
}
|
192
|
-
})
|
193
|
+
}, **{})
|
193
194
|
|
194
195
|
query.execute(graph) do |solution|
|
195
196
|
puts "name=#{solution.name} email=#{solution.email}"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0
|
1
|
+
3.1.0
|
data/lib/rdf.rb
CHANGED
@@ -79,8 +79,8 @@ module RDF
|
|
79
79
|
#
|
80
80
|
# @param (see RDF::Resource#initialize)
|
81
81
|
# @return [RDF::Resource]
|
82
|
-
def self.Resource(*args
|
83
|
-
Resource.new(*args
|
82
|
+
def self.Resource(*args)
|
83
|
+
Resource.new(*args)
|
84
84
|
end
|
85
85
|
|
86
86
|
##
|
@@ -88,8 +88,8 @@ module RDF
|
|
88
88
|
#
|
89
89
|
# @param (see RDF::Node#initialize)
|
90
90
|
# @return [RDF::Node]
|
91
|
-
def self.Node(*args
|
92
|
-
Node.new(*args
|
91
|
+
def self.Node(*args)
|
92
|
+
Node.new(*args)
|
93
93
|
end
|
94
94
|
|
95
95
|
##
|
@@ -97,8 +97,15 @@ module RDF
|
|
97
97
|
#
|
98
98
|
# @param (see RDF::URI#initialize)
|
99
99
|
# @return [RDF::URI]
|
100
|
-
def self.URI(
|
101
|
-
|
100
|
+
def self.URI(*args)
|
101
|
+
if args.first.respond_to?(:to_uri)
|
102
|
+
args.first.to_uri
|
103
|
+
elsif args.first.is_a?(Hash)
|
104
|
+
URI.new(**args.first)
|
105
|
+
else
|
106
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
107
|
+
URI.new(*args, **opts)
|
108
|
+
end
|
102
109
|
end
|
103
110
|
|
104
111
|
##
|
@@ -106,10 +113,10 @@ module RDF
|
|
106
113
|
#
|
107
114
|
# @param (see RDF::Literal#initialize)
|
108
115
|
# @return [RDF::Literal]
|
109
|
-
def self.Literal(literal,
|
116
|
+
def self.Literal(literal, **options)
|
110
117
|
case literal
|
111
118
|
when RDF::Literal then literal
|
112
|
-
else Literal.new(literal,
|
119
|
+
else Literal.new(literal, **options)
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
@@ -119,7 +126,7 @@ module RDF
|
|
119
126
|
# @param (see RDF::Graph#initialize)
|
120
127
|
# @return [RDF::Graph]
|
121
128
|
def self.Graph(**options, &block)
|
122
|
-
Graph.new(options, &block)
|
129
|
+
Graph.new(**options, &block)
|
123
130
|
end
|
124
131
|
|
125
132
|
##
|
@@ -171,11 +178,11 @@ module RDF
|
|
171
178
|
# @option options [RDF::Resource] :graph_name (nil)
|
172
179
|
# @return [RDF::Statement]
|
173
180
|
#
|
174
|
-
def self.Statement(*args)
|
175
|
-
if args.empty?
|
181
|
+
def self.Statement(*args, **options)
|
182
|
+
if args.empty? && options.empty?
|
176
183
|
RDF[:Statement]
|
177
184
|
else
|
178
|
-
Statement.new(*args)
|
185
|
+
Statement.new(*args, **options)
|
179
186
|
end
|
180
187
|
end
|
181
188
|
|
data/lib/rdf/changeset.rb
CHANGED
data/lib/rdf/cli.rb
CHANGED
@@ -175,7 +175,7 @@ module RDF
|
|
175
175
|
unless repository.count > 0
|
176
176
|
start = Time.new
|
177
177
|
count = 0
|
178
|
-
self.parse(argv, opts) do |reader|
|
178
|
+
self.parse(argv, **opts) do |reader|
|
179
179
|
reader.each_statement do |statement|
|
180
180
|
count += 1
|
181
181
|
end
|
@@ -240,7 +240,7 @@ module RDF
|
|
240
240
|
out = opts[:output]
|
241
241
|
opts = opts.merge(prefixes: {})
|
242
242
|
writer_opts = opts.merge(standard_prefixes: true)
|
243
|
-
writer_class.new(out, writer_opts) do |writer|
|
243
|
+
writer_class.new(out, **writer_opts) do |writer|
|
244
244
|
writer << repository
|
245
245
|
end
|
246
246
|
end
|
@@ -501,7 +501,7 @@ module RDF
|
|
501
501
|
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
|
502
502
|
start = Time.new
|
503
503
|
count = 0
|
504
|
-
self.parse(args, options) do |reader|
|
504
|
+
self.parse(args, **options) do |reader|
|
505
505
|
@repository << reader
|
506
506
|
end
|
507
507
|
secs = Time.new - start
|
@@ -575,7 +575,7 @@ module RDF
|
|
575
575
|
RDF::Format.each do |format|
|
576
576
|
format.cli_commands.each do |command, options|
|
577
577
|
options = {lambda: options} unless options.is_a?(Hash)
|
578
|
-
add_command(command, options)
|
578
|
+
add_command(command, **options)
|
579
579
|
end
|
580
580
|
end
|
581
581
|
@commands_loaded = true
|
@@ -637,13 +637,13 @@ module RDF
|
|
637
637
|
r = RDF::Reader.for(format|| {sample: sample})
|
638
638
|
raise ArgumentError, "Unknown format for evaluated input" unless r
|
639
639
|
(@readers ||= []) << r
|
640
|
-
r.new(input, options) do |reader|
|
640
|
+
r.new(input, **options) do |reader|
|
641
641
|
yield(reader)
|
642
642
|
end
|
643
643
|
else
|
644
644
|
options[:format] = format if format
|
645
645
|
files.each do |file|
|
646
|
-
RDF::Reader.open(file, options) do |reader|
|
646
|
+
RDF::Reader.open(file, **options) do |reader|
|
647
647
|
(@readers ||= []) << reader.class.to_s
|
648
648
|
yield(reader)
|
649
649
|
end
|
data/lib/rdf/format.rb
CHANGED
@@ -122,7 +122,7 @@ module RDF
|
|
122
122
|
sample = case sample
|
123
123
|
when Proc then sample.call.to_s
|
124
124
|
else sample.dup.to_s
|
125
|
-
end.force_encoding(Encoding::ASCII_8BIT)
|
125
|
+
end.dup.force_encoding(Encoding::ASCII_8BIT)
|
126
126
|
# Given a sample, perform format detection across the appropriate formats, choosing the last that matches
|
127
127
|
# Return last format that has a positive detection
|
128
128
|
formats = formats.select {|f| f.detect(sample)}
|
@@ -145,10 +145,10 @@ module RDF
|
|
145
145
|
# @param [String, RDF::URI] filename
|
146
146
|
# @return [Class]
|
147
147
|
#
|
148
|
-
# @overload for(
|
148
|
+
# @overload for(options)
|
149
149
|
# Finds an RDF serialization format class based on various options.
|
150
150
|
#
|
151
|
-
# @param [Hash{Symbol => Object}] options
|
151
|
+
# @param [Hash{Symbol => Object}] options ({})
|
152
152
|
# @option options [String, #to_s] :file_name (nil)
|
153
153
|
# @option options [Symbol, #to_sym] :file_extension (nil)
|
154
154
|
# @option options [String, #to_s] :content_type (nil)
|
@@ -164,19 +164,26 @@ module RDF
|
|
164
164
|
# @yieldreturn [String] another way to provide a sample, allows lazy for retrieving the sample.
|
165
165
|
#
|
166
166
|
# @return [Class]
|
167
|
-
def self.for(*
|
167
|
+
def self.for(*arg, &block)
|
168
|
+
case arg.length
|
169
|
+
when 0 then arg = nil
|
170
|
+
when 1 then arg = arg.first
|
171
|
+
else
|
172
|
+
raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}."
|
173
|
+
end
|
174
|
+
|
175
|
+
options = arg.is_a?(Hash) ? arg : {}
|
168
176
|
options = {sample: block}.merge(options) if block_given?
|
169
|
-
formats = case
|
177
|
+
formats = case arg
|
170
178
|
when String, RDF::URI
|
171
179
|
# Find a format based on the file name
|
172
|
-
self.each(file_name:
|
180
|
+
self.each(file_name: arg, **options).to_a
|
173
181
|
when Symbol
|
174
182
|
# Try to find a match based on the full class name
|
175
183
|
# We want this to work even if autoloading fails
|
176
|
-
|
177
|
-
classes = self.each(options).select {|f| f.symbols.include?(fmt)}
|
184
|
+
classes = self.each(**options).select {|f| f.symbols.include?(arg)}
|
178
185
|
if classes.empty?
|
179
|
-
classes = case
|
186
|
+
classes = case arg
|
180
187
|
when :ntriples then [RDF::NTriples::Format]
|
181
188
|
when :nquads then [RDF::NQuads::Format]
|
182
189
|
else []
|
@@ -184,7 +191,7 @@ module RDF
|
|
184
191
|
end
|
185
192
|
classes
|
186
193
|
else
|
187
|
-
self.each(options.merge(all_if_none: false)).to_a
|
194
|
+
self.each(**options.merge(all_if_none: false)).to_a
|
188
195
|
end
|
189
196
|
|
190
197
|
# Return the last detected format
|
data/lib/rdf/mixin/enumerable.rb
CHANGED
@@ -220,7 +220,7 @@ module RDF
|
|
220
220
|
def each_triple
|
221
221
|
if block_given?
|
222
222
|
each_statement do |statement|
|
223
|
-
yield
|
223
|
+
yield(*statement.to_triple)
|
224
224
|
end
|
225
225
|
end
|
226
226
|
enum_triple
|
@@ -282,7 +282,7 @@ module RDF
|
|
282
282
|
def each_quad
|
283
283
|
if block_given?
|
284
284
|
each_statement do |statement|
|
285
|
-
yield
|
285
|
+
yield(*statement.to_quad)
|
286
286
|
end
|
287
287
|
end
|
288
288
|
enum_quad
|
data/lib/rdf/mixin/mutable.rb
CHANGED
@@ -37,10 +37,10 @@ module RDF
|
|
37
37
|
# @option options [RDF::Resource] :graph_name
|
38
38
|
# Set set graph name of each loaded statement
|
39
39
|
# @return [void]
|
40
|
-
|
40
|
+
def load(url, graph_name: nil, **options)
|
41
41
|
raise TypeError.new("#{self} is immutable") if immutable?
|
42
42
|
|
43
|
-
Reader.open(url,
|
43
|
+
Reader.open(url, base_uri: url, **options) do |reader|
|
44
44
|
if graph_name
|
45
45
|
statements = []
|
46
46
|
reader.each_statement do |statement|
|
data/lib/rdf/mixin/queryable.rb
CHANGED
@@ -19,7 +19,7 @@ module RDF
|
|
19
19
|
#
|
20
20
|
# @example Querying for statements having a given predicate
|
21
21
|
# queryable.query([nil, RDF::Vocab::DOAP.developer, nil])
|
22
|
-
# queryable.query(predicate: RDF::Vocab::DOAP.developer) do |statement|
|
22
|
+
# queryable.query({predicate: RDF::Vocab::DOAP.developer}) do |statement|
|
23
23
|
# puts statement.inspect
|
24
24
|
# end
|
25
25
|
#
|
@@ -50,7 +50,7 @@ module RDF
|
|
50
50
|
solutions = RDF::Query::Solutions.new
|
51
51
|
block = lambda {|solution| solutions << solution} unless block_given?
|
52
52
|
before_query(pattern) if respond_to?(:before_query)
|
53
|
-
query_execute(pattern, options, &block)
|
53
|
+
query_execute(pattern, **options, &block)
|
54
54
|
after_query(pattern) if respond_to?(:after_query)
|
55
55
|
# Returns the solutions, not an enumerator
|
56
56
|
solutions
|
@@ -85,7 +85,7 @@ module RDF
|
|
85
85
|
|
86
86
|
# Otherwise, we delegate to `#query_pattern`:
|
87
87
|
else # pattern.variable?
|
88
|
-
query_pattern(pattern, options, &block)
|
88
|
+
query_pattern(pattern, **options, &block)
|
89
89
|
end
|
90
90
|
after_query(pattern) if respond_to?(:after_query)
|
91
91
|
enum
|
@@ -116,7 +116,7 @@ module RDF
|
|
116
116
|
# query execution by breaking down the query into its constituent
|
117
117
|
# triple patterns and invoking `RDF::Query::Pattern#execute` on each
|
118
118
|
# pattern.
|
119
|
-
query.execute(self, options, &block)
|
119
|
+
query.execute(self, **options, &block)
|
120
120
|
end
|
121
121
|
protected :query_execute
|
122
122
|
|
data/lib/rdf/model/graph.rb
CHANGED
@@ -211,7 +211,7 @@ module RDF
|
|
211
211
|
# @return [Integer]
|
212
212
|
# @see RDF::Enumerable#count
|
213
213
|
def count
|
214
|
-
@data.query(graph_name: graph_name || false).count
|
214
|
+
@data.query({graph_name: graph_name || false}).count
|
215
215
|
end
|
216
216
|
|
217
217
|
##
|
@@ -237,7 +237,7 @@ module RDF
|
|
237
237
|
# @see RDF::Enumerable#each_statement
|
238
238
|
def each(&block)
|
239
239
|
if @data.respond_to?(:query)
|
240
|
-
@data.query(graph_name: graph_name || false, &block)
|
240
|
+
@data.query({graph_name: graph_name || false}, &block)
|
241
241
|
elsif @data.respond_to?(:each)
|
242
242
|
@data.each(&block)
|
243
243
|
else
|
data/lib/rdf/model/list.rb
CHANGED
@@ -59,7 +59,7 @@ module RDF
|
|
59
59
|
def initialize(subject: nil, graph: nil, values: nil, &block)
|
60
60
|
@subject = subject || RDF.nil
|
61
61
|
@graph = graph || RDF::Graph.new
|
62
|
-
is_empty = @graph.query(subject: subject, predicate: RDF.first).empty?
|
62
|
+
is_empty = @graph.query({subject: subject, predicate: RDF.first}).empty?
|
63
63
|
|
64
64
|
if subject && is_empty
|
65
65
|
# An empty list with explicit subject and value initializers
|
@@ -115,7 +115,7 @@ module RDF
|
|
115
115
|
list_nodes << li
|
116
116
|
rest = nil
|
117
117
|
firsts = rests = 0
|
118
|
-
@graph.query(subject: li) do |st|
|
118
|
+
@graph.query({subject: li}) do |st|
|
119
119
|
return false unless st.subject.node?
|
120
120
|
case st.predicate
|
121
121
|
when RDF.first
|
@@ -136,7 +136,7 @@ module RDF
|
|
136
136
|
|
137
137
|
# All elements other than the head must be referenced exactly once
|
138
138
|
return list_nodes.all? do |li|
|
139
|
-
refs = @graph.query(object: li).count
|
139
|
+
refs = @graph.query({object: li}).count
|
140
140
|
case refs
|
141
141
|
when 0 then li == subject
|
142
142
|
when 1 then true
|
@@ -479,7 +479,7 @@ module RDF
|
|
479
479
|
# @return [Boolean]
|
480
480
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-empty-3F
|
481
481
|
def empty?
|
482
|
-
graph.query(subject: subject, predicate: RDF.first).empty?
|
482
|
+
graph.query({subject: subject, predicate: RDF.first}).empty?
|
483
483
|
end
|
484
484
|
|
485
485
|
##
|
@@ -822,7 +822,7 @@ module RDF
|
|
822
822
|
return enum_statement unless block_given?
|
823
823
|
|
824
824
|
each_subject do |subject|
|
825
|
-
graph.query(subject: subject, &block)
|
825
|
+
graph.query({subject: subject}, &block)
|
826
826
|
end
|
827
827
|
end
|
828
828
|
alias_method :to_rdf, :each_statement
|
data/lib/rdf/model/uri.rb
CHANGED
@@ -141,8 +141,8 @@ module RDF
|
|
141
141
|
#
|
142
142
|
# (see #initialize)
|
143
143
|
# @return [RDF::URI] an immutable, frozen URI object
|
144
|
-
def self.intern(str, *args)
|
145
|
-
(cache[(str = str.to_s).to_sym] ||= self.new(str, *args)).freeze
|
144
|
+
def self.intern(str, *args, **options)
|
145
|
+
(cache[(str = str.to_s).to_sym] ||= self.new(str, *args, **options)).freeze
|
146
146
|
end
|
147
147
|
|
148
148
|
##
|
@@ -225,11 +225,9 @@ module RDF
|
|
225
225
|
@mutex = Mutex.new
|
226
226
|
uri = args.first
|
227
227
|
if uri
|
228
|
-
@value = uri.to_s
|
229
|
-
if @value.encoding != Encoding::UTF_8
|
230
|
-
|
231
|
-
@value.freeze
|
232
|
-
end
|
228
|
+
@value = uri.to_s.dup
|
229
|
+
@value.dup.force_encoding(Encoding::UTF_8) if @value.encoding != Encoding::UTF_8
|
230
|
+
@value.freeze
|
233
231
|
else
|
234
232
|
%w(
|
235
233
|
scheme
|
@@ -441,7 +439,7 @@ module RDF
|
|
441
439
|
end
|
442
440
|
|
443
441
|
# Return joined URI
|
444
|
-
RDF::URI.new(joined_parts)
|
442
|
+
RDF::URI.new(**joined_parts)
|
445
443
|
end
|
446
444
|
|
447
445
|
##
|
@@ -509,7 +507,7 @@ module RDF
|
|
509
507
|
case fragment.to_s[0,1]
|
510
508
|
when '#'
|
511
509
|
# Base ending with '/', fragment beginning with '#'. The fragment wins, we use '#'.
|
512
|
-
res.path = res.path.to_s.sub
|
510
|
+
res.path = res.path.to_s.sub(/\/*$/, '')
|
513
511
|
# Add fragment
|
514
512
|
res.fragment = fragment.to_s.sub(/^#+/,'')
|
515
513
|
else
|
@@ -574,7 +572,7 @@ module RDF
|
|
574
572
|
self
|
575
573
|
else
|
576
574
|
RDF::URI.new(
|
577
|
-
object.merge(path: '/').
|
575
|
+
**object.merge(path: '/').
|
578
576
|
keep_if {|k, v| [:scheme, :authority, :path].include?(k)})
|
579
577
|
end
|
580
578
|
end
|
@@ -659,7 +657,7 @@ module RDF
|
|
659
657
|
#
|
660
658
|
# @return [RDF::URI]
|
661
659
|
def dup
|
662
|
-
self.class.new(
|
660
|
+
self.class.new(@value, **(@object || {}))
|
663
661
|
end
|
664
662
|
|
665
663
|
##
|
@@ -848,7 +846,7 @@ module RDF
|
|
848
846
|
parts[:user] = (user.dup.force_encoding(Encoding::UTF_8) if user)
|
849
847
|
parts[:password] = (password.dup.force_encoding(Encoding::UTF_8) if password)
|
850
848
|
parts[:host] = (host.dup.force_encoding(Encoding::UTF_8) if host)
|
851
|
-
parts[:port] = (
|
849
|
+
parts[:port] = (URI.decode(port).to_i if port)
|
852
850
|
parts[:path] = (path.to_s.dup.force_encoding(Encoding::UTF_8) unless path.empty?)
|
853
851
|
parts[:query] = (query[1..-1].dup.force_encoding(Encoding::UTF_8) if query)
|
854
852
|
parts[:fragment] = (fragment[1..-1].dup.force_encoding(Encoding::UTF_8) if fragment)
|
@@ -904,7 +902,7 @@ module RDF
|
|
904
902
|
# Normalized version of user
|
905
903
|
# @return [String]
|
906
904
|
def normalized_user
|
907
|
-
|
905
|
+
URI.encode(URI.decode(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if user
|
908
906
|
end
|
909
907
|
|
910
908
|
##
|
@@ -930,7 +928,7 @@ module RDF
|
|
930
928
|
# Normalized version of password
|
931
929
|
# @return [String]
|
932
930
|
def normalized_password
|
933
|
-
|
931
|
+
URI.encode(URI.decode(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if password
|
934
932
|
end
|
935
933
|
|
936
934
|
HOST_FROM_AUTHORITY_RE = /(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
|
@@ -939,7 +937,7 @@ module RDF
|
|
939
937
|
# @return [String]
|
940
938
|
def host
|
941
939
|
object.fetch(:host) do
|
942
|
-
@object[:host] = ($1 if HOST_FROM_AUTHORITY_RE.match(@object[:authority]))
|
940
|
+
@object[:host] = ($1 if @object[:authority] && HOST_FROM_AUTHORITY_RE.match(@object[:authority]))
|
943
941
|
end
|
944
942
|
end
|
945
943
|
|
@@ -967,7 +965,7 @@ module RDF
|
|
967
965
|
# @return [String]
|
968
966
|
def port
|
969
967
|
object.fetch(:port) do
|
970
|
-
@object[:port] = ($1 if PORT_FROM_AUTHORITY_RE.match(@object[:authority]))
|
968
|
+
@object[:port] = ($1 if @object[:authority] && PORT_FROM_AUTHORITY_RE.match(@object[:authority]))
|
971
969
|
end
|
972
970
|
end
|
973
971
|
|
@@ -1182,8 +1180,8 @@ module RDF
|
|
1182
1180
|
inject(return_type == Hash ? {} : []) do |memo,kv|
|
1183
1181
|
k,v = kv.to_s.split('=', 2)
|
1184
1182
|
next if k.to_s.empty?
|
1185
|
-
k =
|
1186
|
-
v =
|
1183
|
+
k = URI.decode(k)
|
1184
|
+
v = URI.decode(v) if v
|
1187
1185
|
if return_type == Hash
|
1188
1186
|
case memo[k]
|
1189
1187
|
when nil then memo[k] = v
|
@@ -1295,9 +1293,9 @@ module RDF
|
|
1295
1293
|
def normalize_segment(value, expr, downcase = false)
|
1296
1294
|
if value
|
1297
1295
|
value = value.dup.force_encoding(Encoding::UTF_8)
|
1298
|
-
decoded =
|
1296
|
+
decoded = URI.decode(value)
|
1299
1297
|
decoded.downcase! if downcase
|
1300
|
-
|
1298
|
+
URI.encode(decoded, /[^(?:#{expr})]/)
|
1301
1299
|
end
|
1302
1300
|
end
|
1303
1301
|
|
@@ -1316,6 +1314,27 @@ module RDF
|
|
1316
1314
|
""
|
1317
1315
|
end
|
1318
1316
|
end
|
1317
|
+
|
1318
|
+
# URI encode matching characters in value
|
1319
|
+
# From URI gem, as this is now generally deprecated
|
1320
|
+
def self.encode(str, expr)
|
1321
|
+
str.gsub(expr) do
|
1322
|
+
us = $&
|
1323
|
+
tmp = ''
|
1324
|
+
us.each_byte do |uc|
|
1325
|
+
tmp << sprintf('%%%02X', uc)
|
1326
|
+
end
|
1327
|
+
tmp
|
1328
|
+
end.force_encoding(Encoding::US_ASCII)
|
1329
|
+
end
|
1330
|
+
|
1331
|
+
# URI decode escape sequences in value
|
1332
|
+
# From URI gem, as this is now generally deprecated
|
1333
|
+
def self.decode(str)
|
1334
|
+
enc = str.encoding
|
1335
|
+
enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
|
1336
|
+
str.gsub(PCT_ENCODED) { [$&[1, 2]].pack('H2').force_encoding(enc) }
|
1337
|
+
end
|
1319
1338
|
end
|
1320
1339
|
|
1321
1340
|
# RDF::IRI is a synonym for RDF::URI
|
data/lib/rdf/nquads.rb
CHANGED
@@ -96,7 +96,7 @@ module RDF
|
|
96
96
|
# @param [RDF::Term] object
|
97
97
|
# @return [void]
|
98
98
|
def write_quad(subject, predicate, object, graph_name)
|
99
|
-
puts format_quad(subject, predicate, object, graph_name,
|
99
|
+
puts format_quad(subject, predicate, object, graph_name, **@options)
|
100
100
|
end
|
101
101
|
|
102
102
|
##
|
@@ -107,7 +107,7 @@ module RDF
|
|
107
107
|
# @return [String]
|
108
108
|
# @since 0.4.0
|
109
109
|
def format_statement(statement, **options)
|
110
|
-
format_quad(*statement.to_quad, options)
|
110
|
+
format_quad(*statement.to_quad, **options)
|
111
111
|
end
|
112
112
|
|
113
113
|
##
|
@@ -120,8 +120,8 @@ module RDF
|
|
120
120
|
# @param [Hash{Symbol => Object}] options = ({})
|
121
121
|
# @return [String]
|
122
122
|
def format_quad(subject, predicate, object, graph_name, **options)
|
123
|
-
s = "%s %s %s " % [subject, predicate, object].map { |value| format_term(value, options) }
|
124
|
-
s += format_term(graph_name, options) + " " if graph_name
|
123
|
+
s = "%s %s %s " % [subject, predicate, object].map { |value| format_term(value, **options) }
|
124
|
+
s += format_term(graph_name, **options) + " " if graph_name
|
125
125
|
s + "."
|
126
126
|
end
|
127
127
|
end # Writer
|
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -96,7 +96,7 @@ module RDF::NTriples
|
|
96
96
|
def self.unserialize(input, **options)
|
97
97
|
case input
|
98
98
|
when nil then nil
|
99
|
-
else self.new(input,
|
99
|
+
else self.new(input, logger: [], **options).read_value
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -104,20 +104,20 @@ module RDF::NTriples
|
|
104
104
|
# (see unserialize)
|
105
105
|
# @return [RDF::Resource]
|
106
106
|
def self.parse_subject(input, **options)
|
107
|
-
parse_uri(input, options) || parse_node(input, options)
|
107
|
+
parse_uri(input, **options) || parse_node(input, **options)
|
108
108
|
end
|
109
109
|
|
110
110
|
##
|
111
111
|
# (see unserialize)
|
112
112
|
# @return [RDF::URI]
|
113
|
-
def self.parse_predicate(input,
|
113
|
+
def self.parse_predicate(input, **options)
|
114
114
|
parse_uri(input, intern: true)
|
115
115
|
end
|
116
116
|
|
117
117
|
##
|
118
118
|
# (see unserialize)
|
119
119
|
def self.parse_object(input, **options)
|
120
|
-
parse_uri(input, options) || parse_node(input, options) || parse_literal(input, options)
|
120
|
+
parse_uri(input, **options) || parse_node(input, **options) || parse_literal(input, **options)
|
121
121
|
end
|
122
122
|
|
123
123
|
##
|
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -208,7 +208,7 @@ module RDF::NTriples
|
|
208
208
|
# @param [RDF::Term] object
|
209
209
|
# @return [void]
|
210
210
|
def write_triple(subject, predicate, object)
|
211
|
-
puts format_triple(subject, predicate, object,
|
211
|
+
puts format_triple(subject, predicate, object, **@options)
|
212
212
|
end
|
213
213
|
|
214
214
|
##
|
data/lib/rdf/query.rb
CHANGED
@@ -90,7 +90,7 @@ module RDF
|
|
90
90
|
# the resulting solution sequence
|
91
91
|
# @see RDF::Query#execute
|
92
92
|
def self.execute(queryable, patterns = {}, options = {}, &block)
|
93
|
-
self.new(patterns, options, &block).execute(queryable, options)
|
93
|
+
self.new(patterns, **options, &block).execute(queryable, **options)
|
94
94
|
end
|
95
95
|
|
96
96
|
##
|
@@ -134,6 +134,12 @@ module RDF
|
|
134
134
|
# @return [Hash]
|
135
135
|
attr_reader :options
|
136
136
|
|
137
|
+
##
|
138
|
+
# Scope the query to named graphs matching value
|
139
|
+
#
|
140
|
+
# @return [RDF::Resource, RDF::Query::Variable, false] graph_name
|
141
|
+
attr_accessor :graph_name
|
142
|
+
|
137
143
|
##
|
138
144
|
# Initializes a new basic graph pattern query.
|
139
145
|
#
|
@@ -180,6 +186,7 @@ module RDF
|
|
180
186
|
@options = options.dup
|
181
187
|
@solutions = Query::Solutions(solutions)
|
182
188
|
graph_name = name if graph_name.nil?
|
189
|
+
@graph_name = graph_name
|
183
190
|
|
184
191
|
patterns << @options if patterns.empty?
|
185
192
|
|
@@ -189,8 +196,6 @@ module RDF
|
|
189
196
|
else patterns
|
190
197
|
end
|
191
198
|
|
192
|
-
self.graph_name = graph_name
|
193
|
-
|
194
199
|
if block_given?
|
195
200
|
case block.arity
|
196
201
|
when 1 then block.call(self)
|
@@ -223,7 +228,7 @@ module RDF
|
|
223
228
|
# whether this is an optional pattern
|
224
229
|
# @return [void] self
|
225
230
|
def pattern(pattern, **options)
|
226
|
-
@patterns << Pattern.from(pattern, options)
|
231
|
+
@patterns << Pattern.from(pattern, **options)
|
227
232
|
self
|
228
233
|
end
|
229
234
|
|
@@ -235,7 +240,7 @@ module RDF
|
|
235
240
|
# @return [RDF::Query] a copy of `self`
|
236
241
|
# @since 0.3.0
|
237
242
|
def optimize(**options)
|
238
|
-
self.dup.optimize!(options)
|
243
|
+
self.dup.optimize!(**options)
|
239
244
|
end
|
240
245
|
|
241
246
|
##
|
@@ -294,9 +299,7 @@ module RDF
|
|
294
299
|
# the resulting solution sequence
|
295
300
|
# @see http://www.holygoat.co.uk/blog/entry/2005-10-25-1
|
296
301
|
# @see http://www.w3.org/TR/sparql11-query/#emptyGroupPattern
|
297
|
-
def execute(queryable, solutions: Solution.new, graph_name: nil, name: nil, **options, &block)
|
298
|
-
options = {bindings: {}}.merge(options)
|
299
|
-
|
302
|
+
def execute(queryable, bindings: {}, solutions: Solution.new, graph_name: nil, name: nil, **options, &block)
|
300
303
|
# Use provided solutions to allow for query chaining
|
301
304
|
# Otherwise, a quick empty solution simplifies the logic below; no special case for
|
302
305
|
# the first pattern
|
@@ -310,15 +313,14 @@ module RDF
|
|
310
313
|
|
311
314
|
patterns = @patterns
|
312
315
|
graph_name = name if graph_name.nil?
|
313
|
-
graph_name =
|
314
|
-
options[:graph_name] = graph_name unless graph_name.nil?
|
316
|
+
@graph_name = graph_name unless graph_name.nil?
|
315
317
|
|
316
318
|
# Add graph_name to pattern, if necessary
|
317
|
-
unless graph_name.nil?
|
319
|
+
unless @graph_name.nil?
|
318
320
|
if patterns.empty?
|
319
|
-
patterns = [Pattern.new(nil, nil, nil, graph_name: graph_name)]
|
321
|
+
patterns = [Pattern.new(nil, nil, nil, graph_name: @graph_name)]
|
320
322
|
else
|
321
|
-
apply_graph_name(graph_name)
|
323
|
+
apply_graph_name(@graph_name)
|
322
324
|
end
|
323
325
|
end
|
324
326
|
|
@@ -326,15 +328,15 @@ module RDF
|
|
326
328
|
|
327
329
|
old_solutions, @solutions = @solutions, Query::Solutions()
|
328
330
|
|
329
|
-
|
331
|
+
bindings.each_key do |variable|
|
330
332
|
if pattern.variables.include?(variable)
|
331
333
|
unbound_solutions, old_solutions = old_solutions, Query::Solutions()
|
332
|
-
|
334
|
+
bindings[variable].each do |binding|
|
333
335
|
unbound_solutions.each do |solution|
|
334
336
|
old_solutions << solution.merge(variable => binding)
|
335
337
|
end
|
336
338
|
end
|
337
|
-
|
339
|
+
bindings.delete(variable)
|
338
340
|
end
|
339
341
|
end
|
340
342
|
|
@@ -407,38 +409,26 @@ module RDF
|
|
407
409
|
# Is this query scoped to a named graph?
|
408
410
|
# @return [Boolean]
|
409
411
|
def named?
|
410
|
-
!!
|
412
|
+
!!graph_name
|
411
413
|
end
|
412
414
|
|
413
415
|
# Is this query scoped to the default graph?
|
414
416
|
# @return [Boolean]
|
415
417
|
def default?
|
416
|
-
|
418
|
+
graph_name == false
|
417
419
|
end
|
418
420
|
|
419
421
|
# Is this query unscoped? This indicates that it can return results from
|
420
422
|
# either a named graph or the default graph.
|
421
423
|
# @return [Boolean]
|
422
424
|
def unnamed?
|
423
|
-
|
424
|
-
end
|
425
|
-
|
426
|
-
# Scope the query to named graphs matching value
|
427
|
-
# @param [RDF::IRI, RDF::Query::Variable] value
|
428
|
-
# @return [RDF::IRI, RDF::Query::Variable]
|
429
|
-
def graph_name=(value)
|
430
|
-
options[:graph_name] = value
|
431
|
-
end
|
432
|
-
|
433
|
-
# Scope of this query, if any
|
434
|
-
# @return [RDF::IRI, RDF::Query::Variable]
|
435
|
-
def graph_name
|
436
|
-
options[:graph_name]
|
425
|
+
graph_name.nil?
|
437
426
|
end
|
438
427
|
|
439
428
|
# Apply the graph name specified (or configured) to all patterns that have no graph name
|
440
429
|
# @param [RDF::IRI, RDF::Query::Variable] graph_name (self.graph_name)
|
441
|
-
def apply_graph_name(graph_name =
|
430
|
+
def apply_graph_name(graph_name = nil)
|
431
|
+
graph_name ||= self.graph_name
|
442
432
|
patterns.each {|pattern| pattern.graph_name = graph_name if pattern.graph_name.nil?} unless graph_name.nil?
|
443
433
|
end
|
444
434
|
|
@@ -515,8 +505,7 @@ module RDF
|
|
515
505
|
# @return [RDF::Query]
|
516
506
|
def dup
|
517
507
|
patterns = @patterns.map {|p| p.dup}
|
518
|
-
patterns
|
519
|
-
Query.new(*patterns)
|
508
|
+
Query.new(patterns, solutions: @solutions.dup, **options)
|
520
509
|
end
|
521
510
|
|
522
511
|
##
|
@@ -85,13 +85,14 @@ module RDF; class Query
|
|
85
85
|
# the string format for anonymous subjects.
|
86
86
|
# @return [Hash{Symbol => Object}]
|
87
87
|
# the resulting query pattern as a normalized hash.
|
88
|
-
def normalize!(
|
88
|
+
def normalize!(*args)
|
89
|
+
hash_pattern = args.shift
|
90
|
+
options = args.shift || {}
|
91
|
+
anonymous_subject_format = options.fetch(:anonymous_subject_format, '__%s__')
|
89
92
|
raise ArgumentError, "invalid hash pattern: #{hash_pattern.inspect}" unless hash_pattern.is_a?(Hash)
|
90
93
|
|
91
94
|
counter = RDF::Query::HashPatternNormalizer::Counter.new
|
92
95
|
|
93
|
-
anonymous_subject_format = (options[:anonymous_subject_format] || '__%s__').to_s
|
94
|
-
|
95
96
|
hash_pattern.inject({}) { |acc, pair|
|
96
97
|
subject, predicate_to_object = pair
|
97
98
|
|
@@ -184,7 +185,7 @@ module RDF; class Query
|
|
184
185
|
# the query pattern as a hash.
|
185
186
|
# @return [Hash{Symbol => Object}]
|
186
187
|
# the resulting query pattern as a normalized hash.
|
187
|
-
def normalize!(
|
188
|
+
def normalize!(hash_pattern)
|
188
189
|
self.class.normalize!(hash_pattern, @options)
|
189
190
|
end
|
190
191
|
end # RDF::Query::HashPatternNormalizer
|
data/lib/rdf/query/pattern.rb
CHANGED
@@ -17,7 +17,7 @@ module RDF; class Query
|
|
17
17
|
end
|
18
18
|
|
19
19
|
##
|
20
|
-
# @overload initialize(
|
20
|
+
# @overload initialize(options = {})
|
21
21
|
# @param [Hash{Symbol => Object}] options
|
22
22
|
# @option options [Variable, Resource, Symbol, nil] :subject (nil)
|
23
23
|
# @option options [Variable, URI, Symbol, nil] :predicate (nil)
|
@@ -26,7 +26,7 @@ module RDF; class Query
|
|
26
26
|
# A graph_name of nil matches any graph, a graph_name of false, matches only the default graph.
|
27
27
|
# @option options [Boolean] :optional (false)
|
28
28
|
#
|
29
|
-
# @overload initialize(subject, predicate, object,
|
29
|
+
# @overload initialize(subject, predicate, object, options = {})
|
30
30
|
# @param [Variable, Resource, Symbol, nil] subject
|
31
31
|
# @param [Variable, URI, Symbol, nil] predicate
|
32
32
|
# @param [Variable, Termm, Symbol, nil] object
|
data/lib/rdf/reader.rb
CHANGED
@@ -88,9 +88,15 @@ module RDF
|
|
88
88
|
# @yieldreturn [String] another way to provide a sample, allows lazy for retrieving the sample.
|
89
89
|
#
|
90
90
|
# @return [Class]
|
91
|
-
def self.for(
|
92
|
-
|
93
|
-
|
91
|
+
def self.for(*arg, &block)
|
92
|
+
case arg.length
|
93
|
+
when 0 then arg = nil
|
94
|
+
when 1 then arg = arg.first
|
95
|
+
else
|
96
|
+
raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}."
|
97
|
+
end
|
98
|
+
arg = arg.merge(has_reader: true) if arg.is_a?(Hash)
|
99
|
+
if format = self.format || Format.for(arg, &block)
|
94
100
|
format.reader
|
95
101
|
end
|
96
102
|
end
|
@@ -206,7 +212,7 @@ module RDF
|
|
206
212
|
headers['Accept'] ||= (self.format.accept_type + %w(*/*;q=0.1)).join(", ")
|
207
213
|
end
|
208
214
|
|
209
|
-
Util::File.open_file(filename, options) do |file|
|
215
|
+
Util::File.open_file(filename, **options) do |file|
|
210
216
|
format_options = options.dup
|
211
217
|
format_options[:content_type] ||= file.content_type if
|
212
218
|
file.respond_to?(:content_type) &&
|
@@ -229,7 +235,7 @@ module RDF
|
|
229
235
|
options[:filename] ||= filename
|
230
236
|
|
231
237
|
if reader
|
232
|
-
reader.new(file, options, &block)
|
238
|
+
reader.new(file, **options, &block)
|
233
239
|
else
|
234
240
|
raise FormatError, "unknown RDF format: #{format_options.inspect}#{"\nThis may be resolved with a require of the 'linkeddata' gem." unless Object.const_defined?(:LinkedData)}"
|
235
241
|
end
|
data/lib/rdf/repository.rb
CHANGED
@@ -119,9 +119,9 @@ module RDF
|
|
119
119
|
# @yieldparam [Repository]
|
120
120
|
# @return [void]
|
121
121
|
def self.load(urls, **options, &block)
|
122
|
-
self.new(options) do |repository|
|
122
|
+
self.new(**options) do |repository|
|
123
123
|
Array(urls).each do |url|
|
124
|
-
repository.load(url, options)
|
124
|
+
repository.load(url, **options)
|
125
125
|
end
|
126
126
|
|
127
127
|
if block_given?
|
@@ -411,7 +411,7 @@ module RDF
|
|
411
411
|
end
|
412
412
|
end
|
413
413
|
else
|
414
|
-
enum_for(:query_pattern, pattern, options)
|
414
|
+
enum_for(:query_pattern, pattern, **options)
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
@@ -512,8 +512,8 @@ module RDF
|
|
512
512
|
class SerializedTransaction < Transaction
|
513
513
|
##
|
514
514
|
# @see Transaction#initialize
|
515
|
-
def initialize(*)
|
516
|
-
super
|
515
|
+
def initialize(*args, **options, &block)
|
516
|
+
super(*args, **options, &block)
|
517
517
|
@base_snapshot = @snapshot
|
518
518
|
end
|
519
519
|
|
data/lib/rdf/transaction.rb
CHANGED
@@ -24,7 +24,7 @@ module RDF
|
|
24
24
|
# repository = RDF::Repository.new
|
25
25
|
#
|
26
26
|
# RDF::Transaction.begin(repository) do |tx|
|
27
|
-
# tx.query(predicate: RDF::Vocab::DOAP.developer) do |statement|
|
27
|
+
# tx.query({predicate: RDF::Vocab::DOAP.developer}) do |statement|
|
28
28
|
# puts statement.inspect
|
29
29
|
# end
|
30
30
|
# end
|
data/lib/rdf/util/file.rb
CHANGED
@@ -319,7 +319,7 @@ module RDF; module Util
|
|
319
319
|
url_no_frag_or_query.query = nil
|
320
320
|
url_no_frag_or_query.fragment = nil
|
321
321
|
options[:encoding] ||= Encoding::UTF_8
|
322
|
-
Kernel.open(url_no_frag_or_query, "r", options) do |file|
|
322
|
+
Kernel.open(url_no_frag_or_query, "r", **options) do |file|
|
323
323
|
document_options = {
|
324
324
|
base_uri: filename_or_url.to_s,
|
325
325
|
charset: file.external_encoding.to_s,
|
@@ -430,7 +430,7 @@ module RDF; module Util
|
|
430
430
|
end if body.respond_to?(:unicode_normalized?)
|
431
431
|
end
|
432
432
|
|
433
|
-
super(body
|
433
|
+
super(body).set_encoding encoding
|
434
434
|
end
|
435
435
|
|
436
436
|
##
|
data/lib/rdf/util/logger.rb
CHANGED
@@ -38,7 +38,7 @@ module RDF; module Util
|
|
38
38
|
# @option options [Logger, #<<] :logger
|
39
39
|
# @return [Hash{Symbol => Integer}]
|
40
40
|
def log_statistics(**options)
|
41
|
-
logger(options).log_statistics
|
41
|
+
logger(**options).log_statistics
|
42
42
|
end
|
43
43
|
|
44
44
|
##
|
@@ -84,7 +84,7 @@ module RDF; module Util
|
|
84
84
|
# @return [void]
|
85
85
|
# @raise Raises the provided exception class using the first element from args as the message component, if `:exception` option is provided.
|
86
86
|
def log_error(*args, level: :error, **options, &block)
|
87
|
-
logger = self.logger(options)
|
87
|
+
logger = self.logger(**options)
|
88
88
|
return if logger.recovering
|
89
89
|
logger.recovering = true
|
90
90
|
logger_common(*args, level: level, **options, &block)
|
@@ -96,7 +96,7 @@ module RDF; module Util
|
|
96
96
|
# @option options [Logger, #<<] :logger
|
97
97
|
# @return [Boolean]
|
98
98
|
def log_recovering?(**options)
|
99
|
-
self.logger(options).recovering
|
99
|
+
self.logger(**options).recovering
|
100
100
|
end
|
101
101
|
|
102
102
|
##
|
@@ -135,7 +135,7 @@ module RDF; module Util
|
|
135
135
|
# @yieldreturn [String] added to message
|
136
136
|
# @return [void]
|
137
137
|
def log_recover(*args, level: :info, **options, &block)
|
138
|
-
logger = self.logger(options)
|
138
|
+
logger = self.logger(**options)
|
139
139
|
logger.recovering = false
|
140
140
|
return if args.empty? && !block_given?
|
141
141
|
logger_common(*args, level: level, **options, &block)
|
@@ -192,7 +192,7 @@ module RDF; module Util
|
|
192
192
|
# # Return the current log depth
|
193
193
|
# @return [Integer]
|
194
194
|
def log_depth(**options, &block)
|
195
|
-
self.logger(options).log_depth(&block)
|
195
|
+
self.logger(**options).log_depth(&block)
|
196
196
|
end
|
197
197
|
|
198
198
|
private
|
@@ -218,7 +218,7 @@ module RDF; module Util
|
|
218
218
|
# @yieldreturn [String] added to message
|
219
219
|
# @return [void]
|
220
220
|
def logger_common(*args, level:, **options)
|
221
|
-
logger = self.logger(options)
|
221
|
+
logger = self.logger(**options)
|
222
222
|
logger.log_statistics[level] = logger.log_statistics[level].to_i + 1
|
223
223
|
# Some older code uses integer level numbers
|
224
224
|
level = LOGGER_COMMON_LEVELS_REVERSE.fetch(level) if level.is_a?(Integer)
|
data/lib/rdf/vocab/rdfv.rb
CHANGED
@@ -33,6 +33,12 @@ module RDF
|
|
33
33
|
isDefinedBy: %(rdf:).freeze,
|
34
34
|
subClassOf: "rdfs:Container".freeze,
|
35
35
|
type: "rdfs:Class".freeze
|
36
|
+
term :CompoundLiteral,
|
37
|
+
comment: %(A class representing a compound literal.).freeze,
|
38
|
+
label: "CompoundLiteral".freeze,
|
39
|
+
isDefinedBy: %(http://www.w3.org/1999/02/22-rdf-syntax-ns#).freeze,
|
40
|
+
subClassOf: "rdfs:Class".freeze,
|
41
|
+
type: "rdfs:Class".freeze
|
36
42
|
term :List,
|
37
43
|
comment: %(The class of RDF Lists.).freeze,
|
38
44
|
label: "List".freeze,
|
@@ -59,6 +65,13 @@ module RDF
|
|
59
65
|
type: "rdfs:Class".freeze
|
60
66
|
|
61
67
|
# Property definitions
|
68
|
+
property :direction,
|
69
|
+
comment: %(The direction component of a CompoundLiteral.).freeze,
|
70
|
+
domain: "rdf:CompoundLiteral".freeze,
|
71
|
+
label: "direction".freeze,
|
72
|
+
range: "rdfs:Resource".freeze,
|
73
|
+
isDefinedBy: %(http://www.w3.org/1999/02/22-rdf-syntax-ns#).freeze,
|
74
|
+
type: "rdf:Property".freeze
|
62
75
|
property :first,
|
63
76
|
comment: %(The first item in the subject RDF list.).freeze,
|
64
77
|
domain: "rdf:List".freeze,
|
@@ -73,6 +86,13 @@ module RDF
|
|
73
86
|
range: "rdfs:Resource".freeze,
|
74
87
|
isDefinedBy: %(rdf:).freeze,
|
75
88
|
type: "rdf:Property".freeze
|
89
|
+
property :language,
|
90
|
+
comment: %(The language component of a CompoundLiteral.).freeze,
|
91
|
+
domain: "rdf:CompoundLiteral".freeze,
|
92
|
+
label: "language".freeze,
|
93
|
+
range: "rdfs:Resource".freeze,
|
94
|
+
isDefinedBy: %(http://www.w3.org/1999/02/22-rdf-syntax-ns#).freeze,
|
95
|
+
type: "rdf:Property".freeze
|
76
96
|
property :predicate,
|
77
97
|
comment: %(The predicate of the subject RDF statement.).freeze,
|
78
98
|
domain: "rdf:Statement".freeze,
|
@@ -117,6 +137,11 @@ module RDF
|
|
117
137
|
"rdfs:seeAlso": %(http://www.w3.org/TR/rdf11-concepts/#section-html).freeze,
|
118
138
|
subClassOf: "rdfs:Literal".freeze,
|
119
139
|
type: "rdfs:Datatype".freeze
|
140
|
+
property :JSON,
|
141
|
+
comment: %(The datatype of RDF literals storing JSON content.).freeze,
|
142
|
+
label: "JSON".freeze,
|
143
|
+
isDefinedBy: %(http://www.w3.org/1999/02/22-rdf-syntax-ns#).freeze,
|
144
|
+
type: "rdfs:Datatype".freeze
|
120
145
|
term :PlainLiteral,
|
121
146
|
comment: %(The class of plain \(i.e. untyped\) literal values, as used in RIF and OWL 2).freeze,
|
122
147
|
label: "PlainLiteral".freeze,
|
data/lib/rdf/vocabulary.rb
CHANGED
@@ -873,8 +873,8 @@ module RDF
|
|
873
873
|
#
|
874
874
|
# @param (see #initialize)
|
875
875
|
# @return [RDF::URI] an immutable, frozen URI object
|
876
|
-
def self.intern(str, *args)
|
877
|
-
(URI.cache[(str = str.to_s).to_sym] ||= self.new(str, *args)).freeze
|
876
|
+
def self.intern(str, *args, **options)
|
877
|
+
(URI.cache[(str = str.to_s).to_sym] ||= self.new(str, *args, **options)).freeze
|
878
878
|
end
|
879
879
|
|
880
880
|
##
|
@@ -1001,7 +1001,7 @@ module RDF
|
|
1001
1001
|
when :domainIncludes, :rangeIncludes
|
1002
1002
|
RDF::Vocabulary.find_term("http://schema.org/#{p}")
|
1003
1003
|
when :broader, :definition, :exactMatch, :hasTopConcept, :inScheme,
|
1004
|
-
:member, :narrower, :related, :altLabel, :
|
1004
|
+
:member, :narrower, :related, :altLabel, :editorialNote,
|
1005
1005
|
:notation, :note, :prefLabel
|
1006
1006
|
RDF::Vocabulary.find_term("http://www.w3.org/2004/02/skos/core##{p}")
|
1007
1007
|
else
|
data/lib/rdf/writer.rb
CHANGED
@@ -79,7 +79,7 @@ module RDF
|
|
79
79
|
# @param [String] filename
|
80
80
|
# @return [Class]
|
81
81
|
#
|
82
|
-
# @overload for(
|
82
|
+
# @overload for(options = {})
|
83
83
|
# Finds an RDF writer class based on various options.
|
84
84
|
#
|
85
85
|
# @param [Hash{Symbol => Object}] options
|
@@ -89,9 +89,15 @@ module RDF
|
|
89
89
|
# @return [Class]
|
90
90
|
#
|
91
91
|
# @return [Class]
|
92
|
-
def self.for(
|
93
|
-
|
94
|
-
|
92
|
+
def self.for(*arg, &block)
|
93
|
+
case arg.length
|
94
|
+
when 0 then arg = nil
|
95
|
+
when 1 then arg = arg.first
|
96
|
+
else
|
97
|
+
raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}."
|
98
|
+
end
|
99
|
+
arg = arg.merge(has_writer: true) if arg.is_a?(Hash)
|
100
|
+
if format = self.format || Format.for(arg)
|
95
101
|
format.writer
|
96
102
|
end
|
97
103
|
end
|
@@ -505,11 +511,11 @@ module RDF
|
|
505
511
|
# @since 0.3.0
|
506
512
|
def format_term(term, **options)
|
507
513
|
case term
|
508
|
-
when String then format_literal(RDF::Literal(term, options), options)
|
509
|
-
when RDF::List then format_list(term, options)
|
510
|
-
when RDF::Literal then format_literal(term, options)
|
511
|
-
when RDF::URI then format_uri(term, options)
|
512
|
-
when RDF::Node then format_node(term, options)
|
514
|
+
when String then format_literal(RDF::Literal(term, **options), **options)
|
515
|
+
when RDF::List then format_list(term, **options)
|
516
|
+
when RDF::Literal then format_literal(term, **options)
|
517
|
+
when RDF::URI then format_uri(term, **options)
|
518
|
+
when RDF::Node then format_node(term, **options)
|
513
519
|
else nil
|
514
520
|
end
|
515
521
|
end
|
@@ -553,7 +559,7 @@ module RDF
|
|
553
559
|
# @abstract
|
554
560
|
# @since 0.2.3
|
555
561
|
def format_list(value, **options)
|
556
|
-
format_term(value.subject, options)
|
562
|
+
format_term(value.subject, **options)
|
557
563
|
end
|
558
564
|
|
559
565
|
protected
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
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: 2019-
|
13
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: link_header
|
@@ -52,28 +52,28 @@ dependencies:
|
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '3.
|
55
|
+
version: '3.1'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '3.
|
62
|
+
version: '3.1'
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: rdf-turtle
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
69
|
+
version: '3.1'
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '3.
|
76
|
+
version: '3.1'
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
78
|
name: rdf-vocab
|
79
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,98 +108,98 @@ dependencies:
|
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '2.
|
111
|
+
version: '2.1'
|
112
112
|
type: :development
|
113
113
|
prerelease: false
|
114
114
|
version_requirements: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '2.
|
118
|
+
version: '2.1'
|
119
119
|
- !ruby/object:Gem::Dependency
|
120
120
|
name: rspec
|
121
121
|
requirement: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '3.
|
125
|
+
version: '3.9'
|
126
126
|
type: :development
|
127
127
|
prerelease: false
|
128
128
|
version_requirements: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '3.
|
132
|
+
version: '3.9'
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
name: rspec-its
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: '1.
|
139
|
+
version: '1.3'
|
140
140
|
type: :development
|
141
141
|
prerelease: false
|
142
142
|
version_requirements: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - "~>"
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: '1.
|
146
|
+
version: '1.3'
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: webmock
|
149
149
|
requirement: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
151
|
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version: '3.
|
153
|
+
version: '3.7'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
156
|
version_requirements: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
158
|
- - "~>"
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version: '3.
|
160
|
+
version: '3.7'
|
161
161
|
- !ruby/object:Gem::Dependency
|
162
162
|
name: yard
|
163
163
|
requirement: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
165
|
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version: 0.9.
|
167
|
+
version: 0.9.20
|
168
168
|
type: :development
|
169
169
|
prerelease: false
|
170
170
|
version_requirements: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
172
|
- - "~>"
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: 0.9.
|
174
|
+
version: 0.9.20
|
175
175
|
- !ruby/object:Gem::Dependency
|
176
176
|
name: faraday
|
177
177
|
requirement: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
179
|
- - "~>"
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version: '0.
|
181
|
+
version: '0.17'
|
182
182
|
type: :development
|
183
183
|
prerelease: false
|
184
184
|
version_requirements: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
186
|
- - "~>"
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
version: '0.
|
188
|
+
version: '0.17'
|
189
189
|
- !ruby/object:Gem::Dependency
|
190
190
|
name: faraday_middleware
|
191
191
|
requirement: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
193
|
- - "~>"
|
194
194
|
- !ruby/object:Gem::Version
|
195
|
-
version: '0.
|
195
|
+
version: '0.13'
|
196
196
|
type: :development
|
197
197
|
prerelease: false
|
198
198
|
version_requirements: !ruby/object:Gem::Requirement
|
199
199
|
requirements:
|
200
200
|
- - "~>"
|
201
201
|
- !ruby/object:Gem::Version
|
202
|
-
version: '0.
|
202
|
+
version: '0.13'
|
203
203
|
description: RDF.rb is a pure-Ruby library for working with Resource Description Framework
|
204
204
|
(RDF) data.
|
205
205
|
email: public-rdf-ruby@w3.org
|
@@ -295,14 +295,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
295
295
|
requirements:
|
296
296
|
- - ">="
|
297
297
|
- !ruby/object:Gem::Version
|
298
|
-
version: 2.
|
298
|
+
version: '2.4'
|
299
299
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
300
300
|
requirements:
|
301
301
|
- - ">="
|
302
302
|
- !ruby/object:Gem::Version
|
303
303
|
version: '0'
|
304
304
|
requirements: []
|
305
|
-
rubygems_version: 3.0.
|
305
|
+
rubygems_version: 3.0.6
|
306
306
|
signing_key:
|
307
307
|
specification_version: 4
|
308
308
|
summary: A Ruby library for working with Resource Description Framework (RDF) data.
|