rdf 2.2.12 → 3.0.0
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 +5 -5
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/rdf.rb +1 -1
- data/lib/rdf/format.rb +97 -66
- data/lib/rdf/mixin/enumerable.rb +0 -17
- data/lib/rdf/mixin/enumerator.rb +0 -34
- data/lib/rdf/model/literal/date.rb +1 -1
- data/lib/rdf/model/literal/datetime.rb +1 -1
- data/lib/rdf/model/literal/decimal.rb +1 -1
- data/lib/rdf/model/literal/double.rb +1 -1
- data/lib/rdf/model/literal/integer.rb +1 -1
- data/lib/rdf/model/literal/time.rb +1 -1
- data/lib/rdf/model/node.rb +3 -14
- data/lib/rdf/model/statement.rb +0 -28
- data/lib/rdf/model/uri.rb +3 -24
- data/lib/rdf/query.rb +23 -8
- data/lib/rdf/query/pattern.rb +6 -12
- data/lib/rdf/query/solution.rb +2 -14
- data/lib/rdf/query/variable.rb +0 -21
- data/lib/rdf/util/file.rb +1 -2
- data/lib/rdf/vocab/owl.rb +84 -84
- data/lib/rdf/vocab/rdfs.rb +17 -17
- data/lib/rdf/vocab/rdfv.rb +23 -23
- data/lib/rdf/vocab/writer.rb +50 -8
- data/lib/rdf/vocabulary.rb +554 -191
- metadata +23 -24
- data/lib/df.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: faf85190255c4c7a4d081a70108143f0aa084c62fbb75b9a61bd063d75d1b324
|
4
|
+
data.tar.gz: f851e574e23e8a795a008e150827a24e3daab79c79abb26a84b29cc768060810
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd23a8bb42a9f9a0eabf5d378c9ef128917c96a4b8030738c60ef2babc0edc049d16118692d0825cb8058d70da1909df0bbe202b020881eca01eb8b387a19a07
|
7
|
+
data.tar.gz: 7972ad893f01703c35ea71f6fa7962fd2552359e79aeb317511da52c0a91b5e459573a6a729b3477653e62ac7360a6f539945fa9a18abb37c8afc43c61283ade
|
data/README.md
CHANGED
@@ -333,7 +333,7 @@ from BNode identity (i.e., they each entail the other)
|
|
333
333
|
|
334
334
|
## Dependencies
|
335
335
|
|
336
|
-
* [Ruby](http://ruby-lang.org/) (>= 2.
|
336
|
+
* [Ruby](http://ruby-lang.org/) (>= 2.2)
|
337
337
|
* [LinkHeader][] (>= 0.0.8)
|
338
338
|
* Soft dependency on [RestClient][] (>= 1.7)
|
339
339
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
data/lib/rdf.rb
CHANGED
@@ -55,7 +55,7 @@ module RDF
|
|
55
55
|
# RDF vocabularies
|
56
56
|
autoload :Vocabulary, 'rdf/vocabulary'
|
57
57
|
autoload :StrictVocabulary, 'rdf/vocabulary'
|
58
|
-
VOCABS = Dir.glob(File.
|
58
|
+
VOCABS = Dir.glob(File.expand_path("../rdf/vocab/*.rb", __FILE__)).map { |f| File.basename(f)[0...-(File.extname(f).size)].to_sym } rescue []
|
59
59
|
|
60
60
|
# Use const_missing instead of autoload to load most vocabularies so we can provide deprecation messages
|
61
61
|
def self.const_missing(constant)
|
data/lib/rdf/format.rb
CHANGED
@@ -48,11 +48,83 @@ module RDF
|
|
48
48
|
##
|
49
49
|
# Enumerates known RDF serialization format classes.
|
50
50
|
#
|
51
|
+
# Given options from {Format.for}, it returns just those formats that match the specified criteria.
|
52
|
+
#
|
53
|
+
# @example finding all formats that have a writer supporting text/html
|
54
|
+
# RDF::Format.each(content_type: 'text/html', has_writer: true).to_a
|
55
|
+
# #=> RDF::RDFa::Format
|
56
|
+
#
|
57
|
+
# @param [String, #to_s] file_name (nil)
|
58
|
+
# @param [Symbol, #to_sym] file_extension (nil)
|
59
|
+
# @param [String, #to_s] content_type (nil)
|
60
|
+
# Content type may include wildcard characters, which will select among matching formats.
|
61
|
+
# Note that content_type will be taken from a URL opened using {RDF::Util::File.open_file}.
|
62
|
+
# @param [Boolean] has_reader (false)
|
63
|
+
# Only return a format having a reader.
|
64
|
+
# @param [Boolean] has_writer (false)
|
65
|
+
# Only return a format having a writer.
|
66
|
+
# @param [String, Proc] sample (nil)
|
67
|
+
# A sample of input used for performing format detection. If we find no formats, or we find more than one, and we have a sample, we can perform format detection to find a specific format to use, in which case we pick the last one we find
|
51
68
|
# @yield [klass]
|
52
69
|
# @yieldparam [Class]
|
53
70
|
# @return [Enumerator]
|
54
|
-
def self.each(
|
55
|
-
|
71
|
+
def self.each(file_name: nil,
|
72
|
+
file_extension: nil,
|
73
|
+
content_type: nil,
|
74
|
+
has_reader: false,
|
75
|
+
has_writer: false,
|
76
|
+
sample: nil,
|
77
|
+
**options,
|
78
|
+
&block)
|
79
|
+
formats = case
|
80
|
+
# Find a format based on the MIME content type:
|
81
|
+
when content_type
|
82
|
+
# @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
|
83
|
+
# @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
|
84
|
+
mime_type = content_type.to_s.split(';').first # remove any media type parameters
|
85
|
+
|
86
|
+
# Ignore text/plain, a historical encoding for N-Triples, which is
|
87
|
+
# problematic in format detection, as many web servers will serve
|
88
|
+
# content by default text/plain.
|
89
|
+
if (mime_type == 'text/plain' && sample) || mime_type == '*/*'
|
90
|
+
# All content types
|
91
|
+
@@subclasses
|
92
|
+
elsif mime_type.end_with?('/*')
|
93
|
+
# All content types that have the first part of the mime-type as a prefix
|
94
|
+
prefix = mime_type[0..-3]
|
95
|
+
content_types.map do |ct, fmts|
|
96
|
+
ct.start_with?(prefix) ? fmts : []
|
97
|
+
end.flatten.uniq
|
98
|
+
else
|
99
|
+
content_types[mime_type]
|
100
|
+
end
|
101
|
+
# Find a format based on the file name:
|
102
|
+
when file_name
|
103
|
+
ext = File.extname(RDF::URI(file_name).path.to_s)[1..-1].to_s
|
104
|
+
file_extensions[ext.to_sym]
|
105
|
+
# Find a format based on the file extension:
|
106
|
+
when file_extension
|
107
|
+
file_extensions[file_extension.to_sym]
|
108
|
+
else
|
109
|
+
@@subclasses
|
110
|
+
end || (sample ? @@subclasses : []) # If we can sample, check all classes
|
111
|
+
|
112
|
+
# Subset by available reader or writer
|
113
|
+
formats = formats.select do |f|
|
114
|
+
has_reader ? f.reader : (has_writer ? f.writer : true)
|
115
|
+
end
|
116
|
+
|
117
|
+
# If we have multiple formats and a sample, use that for format detection
|
118
|
+
if formats.length != 1 && sample
|
119
|
+
sample = case sample
|
120
|
+
when Proc then sample.call.to_s
|
121
|
+
else sample.dup.to_s
|
122
|
+
end.force_encoding(Encoding::ASCII_8BIT)
|
123
|
+
# Given a sample, perform format detection across the appropriate formats, choosing the last that matches
|
124
|
+
# Return last format that has a positive detection
|
125
|
+
formats = formats.select {|f| f.detect(sample)}
|
126
|
+
end
|
127
|
+
formats.each(&block)
|
56
128
|
end
|
57
129
|
|
58
130
|
##
|
@@ -77,6 +149,7 @@ module RDF
|
|
77
149
|
# @option options [String, #to_s] :file_name (nil)
|
78
150
|
# @option options [Symbol, #to_sym] :file_extension (nil)
|
79
151
|
# @option options [String, #to_s] :content_type (nil)
|
152
|
+
# Content type may include wildcard characters, which will select among matching formats.
|
80
153
|
# Note that content_type will be taken from a URL opened using {RDF::Util::File.open_file}.
|
81
154
|
# @option options [Boolean] :has_reader (false)
|
82
155
|
# Only return a format having a reader.
|
@@ -88,73 +161,31 @@ module RDF
|
|
88
161
|
# @yieldreturn [String] another way to provide a sample, allows lazy for retrieving the sample.
|
89
162
|
#
|
90
163
|
# @return [Class]
|
91
|
-
def self.for(options
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
# Ignore text/plain, a historical encoding for N-Triples, which is
|
108
|
-
# problematic in format detection, as many web servers will serve
|
109
|
-
# content by default text/plain.
|
110
|
-
content_types[mime_type] unless mime_type == 'text/plain' && (options[:sample] || block_given?)
|
111
|
-
# Find a format based on the file name:
|
112
|
-
when file_name = options[:file_name]
|
113
|
-
self.for(file_extension: File.extname(RDF::URI(file_name).path.to_s)[1..-1]) { yield if block_given? }
|
114
|
-
# Find a format based on the file extension:
|
115
|
-
when file_ext = options[:file_extension]
|
116
|
-
file_extensions[file_ext.to_sym]
|
117
|
-
end
|
118
|
-
|
119
|
-
when Symbol
|
120
|
-
# Try to find a match based on the full class name
|
121
|
-
# We want this to work even if autoloading fails
|
122
|
-
fmt, options = options, {}
|
123
|
-
classes = @@subclasses.select { |klass| klass.symbols.include?(fmt) }
|
124
|
-
if classes.empty?
|
125
|
-
classes = case fmt
|
126
|
-
when :ntriples then [RDF::NTriples::Format]
|
127
|
-
when :nquads then [RDF::NQuads::Format]
|
128
|
-
else []
|
129
|
-
end
|
164
|
+
def self.for(*args, **options, &block)
|
165
|
+
options = {sample: block}.merge(options) if block_given?
|
166
|
+
formats = case args.first
|
167
|
+
when String, RDF::URI
|
168
|
+
# Find a format based on the file name
|
169
|
+
self.each(file_name: args.first, **options).to_a
|
170
|
+
when Symbol
|
171
|
+
# Try to find a match based on the full class name
|
172
|
+
# We want this to work even if autoloading fails
|
173
|
+
fmt = args.first
|
174
|
+
classes = self.each(options).select {|f| f.symbols.include?(fmt)}
|
175
|
+
if classes.empty?
|
176
|
+
classes = case fmt
|
177
|
+
when :ntriples then [RDF::NTriples::Format]
|
178
|
+
when :nquads then [RDF::NQuads::Format]
|
179
|
+
else []
|
130
180
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
if format.is_a?(Array)
|
135
|
-
format = format.select {|f| f.reader} if options[:has_reader]
|
136
|
-
format = format.select {|f| f.writer} if options[:has_writer]
|
137
|
-
|
138
|
-
return format.last if format.uniq.length == 1
|
139
|
-
elsif !format.nil?
|
140
|
-
return format
|
141
|
-
end
|
142
|
-
|
143
|
-
# If we have a sample, use that for format detection
|
144
|
-
if sample = (options[:sample] if options.is_a?(Hash)) || (yield if block_given?)
|
145
|
-
sample = sample.dup.to_s
|
146
|
-
sample.force_encoding(Encoding::ASCII_8BIT) if sample.respond_to?(:force_encoding)
|
147
|
-
# Given a sample, perform format detection across the appropriate formats, choosing the last that matches
|
148
|
-
format ||= @@subclasses
|
149
|
-
|
150
|
-
# Return last format that has a positive detection
|
151
|
-
format.reverse.detect {|f| f.detect(sample)} || format.last
|
152
|
-
elsif format.is_a?(Array)
|
153
|
-
# Otherwise, just return the last matching format
|
154
|
-
format.last
|
181
|
+
end
|
182
|
+
classes
|
155
183
|
else
|
156
|
-
|
184
|
+
self.each(options).to_a
|
157
185
|
end
|
186
|
+
|
187
|
+
# Return the last detected format
|
188
|
+
formats.last
|
158
189
|
end
|
159
190
|
|
160
191
|
##
|
data/lib/rdf/mixin/enumerable.rb
CHANGED
@@ -747,15 +747,6 @@ module RDF
|
|
747
747
|
protected
|
748
748
|
|
749
749
|
##
|
750
|
-
# @overload #to_hash
|
751
|
-
# Returns all RDF object terms indexed by their subject and predicate
|
752
|
-
# terms.
|
753
|
-
#
|
754
|
-
# The return value is a `Hash` instance that has the structure:
|
755
|
-
# `{subject => {predicate => [*objects]}}`.
|
756
|
-
#
|
757
|
-
# @return [Hash]
|
758
|
-
# @deprecated Use {#to_h} instead.
|
759
750
|
# @overload #to_writer
|
760
751
|
# Implements #to_writer for each available instance of {RDF::Writer},
|
761
752
|
# based on the writer symbol.
|
@@ -763,14 +754,6 @@ module RDF
|
|
763
754
|
# @return [String]
|
764
755
|
# @see {RDF::Writer.sym}
|
765
756
|
def method_missing(meth, *args)
|
766
|
-
case meth
|
767
|
-
when :to_hash
|
768
|
-
warn "[DEPRECATION] RDF::Enumerable#to_hash is deprecated, use RDF::Enumerable#to_h instead.\n" +
|
769
|
-
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
|
770
|
-
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
|
771
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
772
|
-
return self.to_h
|
773
|
-
end
|
774
757
|
writer = RDF::Writer.for(meth.to_s[3..-1].to_sym) if meth.to_s[0,3] == "to_"
|
775
758
|
if writer
|
776
759
|
writer.buffer(standard_prefixes: true) {|w| w << self}
|
data/lib/rdf/mixin/enumerator.rb
CHANGED
@@ -13,23 +13,6 @@ module RDF
|
|
13
13
|
def to_a
|
14
14
|
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
|
15
15
|
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
##
|
20
|
-
# @overload #to_ary
|
21
|
-
# @see #to_a
|
22
|
-
# @deprecated use {#to_a} instead
|
23
|
-
def method_missing(name, *args)
|
24
|
-
if name == :to_ary
|
25
|
-
warn "[DEPRECATION] #{self.class}#to_ary is deprecated, use " \
|
26
|
-
"#{self.class}#to_a instead. Called from " \
|
27
|
-
"#{Gem.location_of_caller.join(':')}"
|
28
|
-
to_a
|
29
|
-
else
|
30
|
-
super
|
31
|
-
end
|
32
|
-
end
|
33
16
|
end
|
34
17
|
end
|
35
18
|
|
@@ -52,23 +35,6 @@ module RDF
|
|
52
35
|
def to_a
|
53
36
|
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
|
54
37
|
end
|
55
|
-
|
56
|
-
protected
|
57
|
-
|
58
|
-
##
|
59
|
-
# @overload #to_ary
|
60
|
-
# @see #to_a
|
61
|
-
# @deprecated use {#to_a} instead
|
62
|
-
def method_missing(name, *args)
|
63
|
-
if name == :to_ary
|
64
|
-
warn "[DEPRECATION] #{self.class}#to_ary is deprecated, use " \
|
65
|
-
"#{self.class}#to_a instead. Called from " \
|
66
|
-
"#{Gem.location_of_caller.join(':')}"
|
67
|
-
self.to_a
|
68
|
-
else
|
69
|
-
super
|
70
|
-
end
|
71
|
-
end
|
72
38
|
end
|
73
39
|
end
|
74
40
|
end
|
@@ -24,7 +24,7 @@ module RDF; class Literal
|
|
24
24
|
when value.is_a?(::DateTime) then value
|
25
25
|
when value.respond_to?(:to_datetime) then value.to_datetime rescue ::DateTime.parse(value.to_s)
|
26
26
|
else ::DateTime.parse(value.to_s)
|
27
|
-
end rescue
|
27
|
+
end rescue ::DateTime.new
|
28
28
|
end
|
29
29
|
|
30
30
|
##
|
data/lib/rdf/model/node.rb
CHANGED
@@ -37,22 +37,11 @@ module RDF
|
|
37
37
|
# * `:default` Produces 36 characters, including hyphens separating the UUID value parts
|
38
38
|
# * `:compact` Produces a 32 digits (hexadecimal) value with no hyphens
|
39
39
|
# * `:urn` Adds the prefix urn:uuid: to the default format
|
40
|
-
#
|
41
|
-
# a grammar specification that the generated UUID must match
|
42
|
-
# The UUID is generated such that its initial part is guaranteed
|
43
|
-
# to match the given `grammar`, e.g. `/^[A-Za-z][A-Za-z0-9]*/`.
|
44
|
-
# Some RDF storage systems (e.g. AllegroGraph) require this.
|
40
|
+
#
|
45
41
|
# Requires that the `uuid` gem be loadable to use `format`
|
46
42
|
# @return [RDF::Node]
|
47
|
-
def self.uuid(format: :default
|
48
|
-
|
49
|
-
when grammar
|
50
|
-
warn "[DEPRECATION] The grammar parameter to RDF::Node#uri is deprecated.\n" +
|
51
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
52
|
-
uuid = RDF::Util::UUID.generate(format: format) until uuid =~ grammar
|
53
|
-
else
|
54
|
-
uuid = RDF::Util::UUID.generate(format: format)
|
55
|
-
end
|
43
|
+
def self.uuid(format: :default)
|
44
|
+
uuid = RDF::Util::UUID.generate(format: format)
|
56
45
|
self.new(uuid)
|
57
46
|
end
|
58
47
|
|
data/lib/rdf/model/statement.rb
CHANGED
@@ -339,13 +339,6 @@ module RDF
|
|
339
339
|
end
|
340
340
|
alias_method :to_a, :to_triple
|
341
341
|
|
342
|
-
##
|
343
|
-
# @deprecated use {#to_a} or {#to_triple} instead
|
344
|
-
# @see #to_triple
|
345
|
-
def to_ary
|
346
|
-
to_triple
|
347
|
-
end
|
348
|
-
|
349
342
|
##
|
350
343
|
# Canonicalizes each unfrozen term in the statement
|
351
344
|
#
|
@@ -414,26 +407,5 @@ module RDF
|
|
414
407
|
graph << [subject, RDF.object, self.object]
|
415
408
|
end
|
416
409
|
end
|
417
|
-
|
418
|
-
protected
|
419
|
-
##
|
420
|
-
# @overload #to_hash
|
421
|
-
# Returns the terms of this statement as a `Hash`.
|
422
|
-
#
|
423
|
-
# @param (see #to_h)
|
424
|
-
# @return (see #to_h)
|
425
|
-
# @deprecated Use {#to_h} instead.
|
426
|
-
def method_missing(meth, *args)
|
427
|
-
case meth
|
428
|
-
when :to_hash
|
429
|
-
warn "[DEPRECATION] RDF::Statement#to_hash is deprecated, use RDF::Statement#to_h instead.\n" +
|
430
|
-
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
|
431
|
-
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
|
432
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
433
|
-
self.to_h
|
434
|
-
else
|
435
|
-
super
|
436
|
-
end
|
437
|
-
end
|
438
410
|
end
|
439
411
|
end
|
data/lib/rdf/model/uri.rb
CHANGED
@@ -139,10 +139,9 @@ module RDF
|
|
139
139
|
# object can't be returned for some reason, this method will fall back
|
140
140
|
# to returning a freshly-allocated one.
|
141
141
|
#
|
142
|
-
#
|
142
|
+
# (see #initialize)
|
143
143
|
# @return [RDF::URI] an immutable, frozen URI object
|
144
144
|
def self.intern(str, *args)
|
145
|
-
args << {} unless args.last.is_a?(Hash) # FIXME: needed until #to_hash is removed to avoid DEPRECATION warning.
|
146
145
|
(cache[(str = str.to_s).to_sym] ||= self.new(str, *args)).freeze
|
147
146
|
end
|
148
147
|
|
@@ -200,10 +199,10 @@ module RDF
|
|
200
199
|
end
|
201
200
|
|
202
201
|
##
|
203
|
-
# @overload
|
202
|
+
# @overload initialize(uri, **options)
|
204
203
|
# @param [URI, String, #to_s] uri
|
205
204
|
#
|
206
|
-
# @overload
|
205
|
+
# @overload initialize(**options)
|
207
206
|
# @param [Hash{Symbol => Object}] options
|
208
207
|
# @option [String, #to_s] :scheme The scheme component.
|
209
208
|
# @option [String, #to_s] :user The user component.
|
@@ -1293,26 +1292,6 @@ module RDF
|
|
1293
1292
|
""
|
1294
1293
|
end
|
1295
1294
|
end
|
1296
|
-
|
1297
|
-
protected
|
1298
|
-
##
|
1299
|
-
# @overload #to_hash
|
1300
|
-
# Returns object representation of this URI, broken into components
|
1301
|
-
#
|
1302
|
-
# @return (see #object)
|
1303
|
-
# @deprecated Use {#to_h} instead.
|
1304
|
-
def method_missing(meth, *args)
|
1305
|
-
case meth
|
1306
|
-
when :to_hash
|
1307
|
-
warn "[DEPRECATION] RDF::URI#to_hash is deprecated, use RDF::URI#to_h instead.\n" +
|
1308
|
-
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
|
1309
|
-
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
|
1310
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
1311
|
-
self.to_h
|
1312
|
-
else
|
1313
|
-
super
|
1314
|
-
end
|
1315
|
-
end
|
1316
1295
|
end
|
1317
1296
|
|
1318
1297
|
# RDF::IRI is a synonym for RDF::URI
|