rdf 3.3.2 → 3.3.4
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/README.md +12 -11
- data/VERSION +1 -1
- data/lib/rdf/format.rb +4 -0
- data/lib/rdf/mixin/enumerable.rb +0 -1
- data/lib/rdf/mixin/writable.rb +2 -3
- data/lib/rdf/model/dataset.rb +1 -2
- data/lib/rdf/model/graph.rb +32 -3
- data/lib/rdf/model/literal/date.rb +1 -3
- data/lib/rdf/model/literal/decimal.rb +2 -2
- data/lib/rdf/model/literal/double.rb +2 -2
- data/lib/rdf/model/statement.rb +3 -12
- data/lib/rdf/model/uri.rb +31 -10
- data/lib/rdf/nquads.rb +7 -4
- data/lib/rdf/ntriples/reader.rb +42 -46
- data/lib/rdf/ntriples/writer.rb +42 -26
- data/lib/rdf/ntriples.rb +1 -5
- data/lib/rdf/reader.rb +34 -7
- data/lib/rdf/repository.rb +0 -3
- data/lib/rdf/util/file.rb +10 -1
- data/lib/rdf/writer.rb +29 -19
- metadata +56 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b4ec33ae5dd1070409bb56bf6391519dc56fe9e2455e0a9710ea7ec4cbb5308
|
4
|
+
data.tar.gz: 628f0e9bb2ad05d3889f1d9e0003c11fa11ec2e664dd762ccc3a0a75782782da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f67156c9411d9a2f1249c4ad7369faaaf76131be64aae3668553a38d4e102ca5d3a7b329cf5e35a8a5688fb815b6a6ecb9cec311f8324a2450b0e4607f175ee
|
7
|
+
data.tar.gz: a8bb3b7a87d49fd2dc78cec8ebb2f92690d0de80d60abcf9e9d14dd949ac3f2395a228fedc892e51c58bc7ddb08bd1f5a5a64390777048b854ec7a67c053e427
|
data/README.md
CHANGED
@@ -265,12 +265,6 @@ A separate [SPARQL][SPARQL doc] gem builds on basic BGP support to provide full
|
|
265
265
|
foaf[:name] #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
|
266
266
|
foaf['mbox'] #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")
|
267
267
|
|
268
|
-
## RDF-star CG
|
269
|
-
|
270
|
-
[RDF.rb][] includes provisional support for [RDF-star][] with an N-Triples/N-Quads syntax for quoted triples in the _subject_ or _object_ position.
|
271
|
-
|
272
|
-
Support for RDF-star quoted triples is now deprecated, use RDF 1.2 triple terms instead.
|
273
|
-
|
274
268
|
## RDF 1.2
|
275
269
|
|
276
270
|
[RDF.rb][] includes provisional support for [RDF 1.2][] with an N-Triples/N-Quads syntax for triple terms in the _object_ position.
|
@@ -280,19 +274,24 @@ Internally, an `RDF::Statement` is treated as another resource, along with `RDF:
|
|
280
274
|
|
281
275
|
**Note: This feature is subject to change or elimination as the standards process progresses.**
|
282
276
|
|
283
|
-
### Serializing a Graph containing
|
277
|
+
### Serializing a Graph containing triple terms
|
284
278
|
|
285
279
|
require 'rdf/ntriples'
|
286
280
|
statement = RDF::Statement(RDF::URI('bob'), RDF::Vocab::FOAF.age, RDF::Literal(23))
|
287
|
-
|
281
|
+
reifier = RDF::Node.new
|
282
|
+
graph = RDF::Graph.new do |g|
|
283
|
+
g << [reifier, RDF.reifies, statement]
|
284
|
+
g << [reifier, RDF::URI("ex:certainty"), RDF::Literal(0.9)]
|
285
|
+
end
|
288
286
|
graph.dump(:ntriples, validate: false)
|
289
|
-
#
|
287
|
+
# ==> '_:bn <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(<bob> <http://xmlns.com/foaf/0.1/age> "23"^^<http://www.w3.org/2001/XMLSchema#integer>)>> .
|
288
|
+
_:bn <ex:certainty> "0.9"^^<http://www.w3.org/2001/XMLSchema#double> .'
|
290
289
|
|
291
|
-
### Reading a Graph containing
|
290
|
+
### Reading a Graph containing triple terms
|
292
291
|
|
293
292
|
By default, the N-Triples reader will reject a document containing a subject resource.
|
294
293
|
|
295
|
-
nt = '
|
294
|
+
nt = '<<(<bob> <http://xmlns.com/foaf/0.1/age> "23"^^<http://www.w3.org/2001/XMLSchema#integer>)>> <ex:certainty> "0.9"^^<http://www.w3.org/2001/XMLSchema#double> .'
|
296
295
|
graph = RDF::Graph.new do |graph|
|
297
296
|
RDF::NTriples::Reader.new(nt) {|reader| graph << reader}
|
298
297
|
end
|
@@ -346,6 +345,7 @@ other gems:
|
|
346
345
|
* [RDF::TriG][] (extension)
|
347
346
|
* [RDF::TriX][] (extension)
|
348
347
|
* [RDF::Turtle][] (extension)
|
348
|
+
* [RDF::Borsh][] (extension)
|
349
349
|
|
350
350
|
The meta-gem [LinkedData][LinkedData doc] includes many of these gems.
|
351
351
|
|
@@ -511,6 +511,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
511
511
|
[RDF 1.2]: https://www.w3.org/TR/rdf12-concepts/
|
512
512
|
[SPARQL 1.1]: https://www.w3.org/TR/sparql11-query/
|
513
513
|
[RDF.rb]: https://ruby-rdf.github.io/
|
514
|
+
[RDF::Borsh]: https://ruby-rdf.github.io/rdf-borsh
|
514
515
|
[RDF::DO]: https://ruby-rdf.github.io/rdf-do
|
515
516
|
[RDF::Mongo]: https://ruby-rdf.github.io/rdf-mongo
|
516
517
|
[RDF::Sesame]: https://ruby-rdf.github.io/rdf-sesame
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.3.
|
1
|
+
3.3.4
|
data/lib/rdf/format.rb
CHANGED
data/lib/rdf/mixin/enumerable.rb
CHANGED
@@ -84,7 +84,6 @@ module RDF
|
|
84
84
|
# * `:validity` allows a concrete Enumerable implementation to indicate that it does or does not support valididty checking. By default implementations are assumed to support validity checking.
|
85
85
|
# * `:skolemize` supports [Skolemization](https://www.w3.org/wiki/BnodeSkolemization) of an `Enumerable`. Implementations supporting this feature must implement a `#skolemize` method, taking a base URI used for minting URIs for BNodes as stable identifiers and a `#deskolemize` method, also taking a base URI used for turning URIs having that prefix back into the same BNodes which were originally skolemized.
|
86
86
|
# * `:rdf_full` supports RDF 1.2 Full profile, including support for embedded Triple Terms.
|
87
|
-
# * `:quoted_triples` supports RDF-star quoted triples.
|
88
87
|
# * `:base_direction` supports RDF 1.2 directional language-tagged strings.
|
89
88
|
#
|
90
89
|
# @param [Symbol, #to_sym] feature
|
data/lib/rdf/mixin/writable.rb
CHANGED
@@ -127,9 +127,8 @@ module RDF
|
|
127
127
|
def insert_statements(statements)
|
128
128
|
each = statements.respond_to?(:each_statement) ? :each_statement : :each
|
129
129
|
statements.__send__(each) do |statement|
|
130
|
-
|
131
|
-
|
132
|
-
raise ArgumentError, "Writable does not support quoted triples"
|
130
|
+
if statement.embedded? && respond_to?(:supports?) && !supports?(:rdf_full)
|
131
|
+
raise ArgumentError, "Writable does not support triple terms"
|
133
132
|
end
|
134
133
|
if statement.object && statement.object.literal? && statement.object.direction? && respond_to?(:supports?) && !supports?(:base_direction)
|
135
134
|
raise ArgumentError, "Writable does not support directional languaged-tagged strings"
|
data/lib/rdf/model/dataset.rb
CHANGED
@@ -104,8 +104,7 @@ module RDF
|
|
104
104
|
# @private
|
105
105
|
# @see RDF::Enumerable#supports?
|
106
106
|
def supports?(feature)
|
107
|
-
|
108
|
-
return true if %i(graph_name quoted_triples rdf_full).include?(feature)
|
107
|
+
return true if %i(graph_name rdf_full).include?(feature)
|
109
108
|
super
|
110
109
|
end
|
111
110
|
|
data/lib/rdf/model/graph.rb
CHANGED
@@ -20,7 +20,7 @@ module RDF
|
|
20
20
|
#
|
21
21
|
# @example Loading graph data from a URL
|
22
22
|
# require 'rdf/rdfxml' # for RDF/XML support
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# graph = RDF::Graph.load("http://www.bbc.co.uk/programmes/b0081dq5.rdf")
|
25
25
|
#
|
26
26
|
# @example Accessing a specific named graph within a {RDF::Repository}
|
@@ -250,6 +250,36 @@ module RDF
|
|
250
250
|
end
|
251
251
|
alias_method :has_statement?, :statement?
|
252
252
|
|
253
|
+
##
|
254
|
+
# Returns `true` if `self` contains the given RDF subject term.
|
255
|
+
#
|
256
|
+
# @param [RDF::Resource] value
|
257
|
+
# @return [Boolean]
|
258
|
+
def subject? value
|
259
|
+
!@data.query({ subject: value, graph_name: graph_name || false }).empty?
|
260
|
+
end
|
261
|
+
alias_method :has_subject?, :subject?
|
262
|
+
|
263
|
+
##
|
264
|
+
# Returns `true` if `self` contains the given RDF predicate term.
|
265
|
+
#
|
266
|
+
# @param [RDF::URI] value
|
267
|
+
# @return [Boolean]
|
268
|
+
def predicate? value
|
269
|
+
!@data.query({ predicate: value, graph_name: graph_name || false }).empty?
|
270
|
+
end
|
271
|
+
alias_method :has_predicate?, :predicate?
|
272
|
+
|
273
|
+
##
|
274
|
+
# Returns `true` if `self` contains the given RDF object term.
|
275
|
+
#
|
276
|
+
# @param [RDF::Term] value
|
277
|
+
# @return [Boolean]
|
278
|
+
def object? value
|
279
|
+
!@data.query({ object: value, graph_name: graph_name || false }).empty?
|
280
|
+
end
|
281
|
+
alias_method :has_object?, :object?
|
282
|
+
|
253
283
|
##
|
254
284
|
# Enumerates each RDF statement in this graph.
|
255
285
|
#
|
@@ -305,8 +335,7 @@ module RDF
|
|
305
335
|
# @private
|
306
336
|
# @see RDF::Mutable#insert
|
307
337
|
def insert_statement(statement)
|
308
|
-
|
309
|
-
if statement.embedded? && !(@data.supports?(:quoted_triples) || @data.supports?(:rdf_full))
|
338
|
+
if statement.embedded? && !@data.supports?(:rdf_full)
|
310
339
|
raise ArgumentError, "Graph does not support the RDF Full profile"
|
311
340
|
end
|
312
341
|
if statement.object && statement.object.literal? && statement.object.direction? && !@data.supports?(:base_direction)
|
@@ -26,9 +26,7 @@ module RDF; class Literal
|
|
26
26
|
# Use midnight as midpoint of the interval
|
27
27
|
::DateTime.parse(value.strftime('%FT00:00:00'))
|
28
28
|
when value.respond_to?(:to_datetime)
|
29
|
-
|
30
|
-
@zone = dt.zone
|
31
|
-
dt
|
29
|
+
value.to_datetime
|
32
30
|
else
|
33
31
|
md = value.to_s.match(GRAMMAR)
|
34
32
|
_, dt, tz = Array(md)
|
@@ -12,10 +12,10 @@ module RDF; class Literal
|
|
12
12
|
# @since 0.2.1
|
13
13
|
class Decimal < Numeric
|
14
14
|
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#decimal")
|
15
|
-
GRAMMAR = /^[\+\-]
|
15
|
+
GRAMMAR = /^[\+\-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))$/.freeze
|
16
16
|
|
17
17
|
##
|
18
|
-
# @param [String,
|
18
|
+
# @param [String, BigDecimal, Numeric] value
|
19
19
|
# @param (see Literal#initialize)
|
20
20
|
def initialize(value, datatype: nil, lexical: nil, **options)
|
21
21
|
@datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
|
@@ -12,7 +12,7 @@ module RDF; class Literal
|
|
12
12
|
# @since 0.2.1
|
13
13
|
class Double < Numeric
|
14
14
|
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#double")
|
15
|
-
GRAMMAR = /^(?:NaN
|
15
|
+
GRAMMAR = /^(?:NaN|[+\-]?INF|[+\-]?(?:\d+(:?\.\d*)?|\.\d+)(?:[eE][\+\-]?\d+)?)$/.freeze
|
16
16
|
|
17
17
|
##
|
18
18
|
# @param [String, Float, #to_f] value
|
@@ -26,7 +26,7 @@ module RDF; class Literal
|
|
26
26
|
when 'INF' then 1/0.0
|
27
27
|
when '-INF' then -1/0.0
|
28
28
|
when 'NAN' then 0/0.0
|
29
|
-
else Float(value.sub(/\.[eE]/, '.0E')) rescue nil
|
29
|
+
else Float(value.sub(/\.[eE]/, '.0E').sub(/\.$/, '.0')) rescue nil
|
30
30
|
end
|
31
31
|
when value.is_a?(::Float) then value
|
32
32
|
when value.respond_to?(:to_f) then value.to_f
|
data/lib/rdf/model/statement.rb
CHANGED
@@ -72,7 +72,6 @@ module RDF
|
|
72
72
|
# Note, in RDF 1.1, a graph name MUST be an {Resource}.
|
73
73
|
# @option options [Boolean] :inferred used as a marker to record that this statement was inferred based on semantic relationships (T-Box).
|
74
74
|
# @option options [Boolean] :tripleTerm used as a marker to record that this statement appears as the object of another RDF::Statement.
|
75
|
-
# @option options [Boolean] :quoted used as a marker to record that this statement quoted and appears as the subject or object of another RDF::Statement (deprecated).
|
76
75
|
# @return [RDF::Statement]
|
77
76
|
#
|
78
77
|
# @overload initialize(subject, predicate, object, **options)
|
@@ -86,7 +85,6 @@ module RDF
|
|
86
85
|
# Note, in RDF 1.1, a graph name MUST be an {Resource}.
|
87
86
|
# @option options [Boolean] :inferred used as a marker to record that this statement was inferred based on semantic relationships (T-Box).
|
88
87
|
# @option options [Boolean] :tripleTerm used as a marker to record that this statement appears as the object of another RDF::Statement.
|
89
|
-
# @option options [Boolean] :quoted used as a marker to record that this statement quoted and appears as the subject or object of another RDF::Statement (deprecated).
|
90
88
|
# @return [RDF::Statement]
|
91
89
|
def initialize(subject = nil, predicate = nil, object = nil, options = {})
|
92
90
|
if subject.is_a?(Hash)
|
@@ -187,7 +185,7 @@ module RDF
|
|
187
185
|
# Note: Nomenclature is evolving, alternatives could include `#complex?` and `#nested?`
|
188
186
|
# @return [Boolean]
|
189
187
|
def embedded?
|
190
|
-
|
188
|
+
object && object.statement?
|
191
189
|
end
|
192
190
|
|
193
191
|
##
|
@@ -208,7 +206,7 @@ module RDF
|
|
208
206
|
##
|
209
207
|
# @return [Boolean]
|
210
208
|
def asserted?
|
211
|
-
!
|
209
|
+
!embedded?
|
212
210
|
end
|
213
211
|
|
214
212
|
##
|
@@ -217,13 +215,6 @@ module RDF
|
|
217
215
|
!!@options[:tripleTerm]
|
218
216
|
end
|
219
217
|
|
220
|
-
##
|
221
|
-
# @return [Boolean]
|
222
|
-
# @deprecated Quoted triples are now deprecated
|
223
|
-
def quoted?
|
224
|
-
!!@options[:quoted]
|
225
|
-
end
|
226
|
-
|
227
218
|
##
|
228
219
|
# @return [Boolean]
|
229
220
|
def inferred?
|
@@ -476,7 +467,7 @@ module RDF
|
|
476
467
|
def to_s
|
477
468
|
(graph_name ? to_quad : to_triple).map do |term|
|
478
469
|
if term.is_a?(Statement)
|
479
|
-
"
|
470
|
+
"<<(#{term.to_s[0..-3]})>>"
|
480
471
|
elsif term.respond_to?(:to_base)
|
481
472
|
term.to_base
|
482
473
|
else
|
data/lib/rdf/model/uri.rb
CHANGED
@@ -80,6 +80,10 @@ module RDF
|
|
80
80
|
# scheme, authority, path, query, fragment
|
81
81
|
IRI_PARTS = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/.freeze
|
82
82
|
|
83
|
+
# Special version for file-scheme on Windows (path SHOULD begin with /, but may not)
|
84
|
+
# scheme, authority, path, query, fragment
|
85
|
+
FILE_PARTS = /^file:(?:\/\/(#{IHOST}))?(\/?[^?#]*)(\?[^#]*)?(#.*)?$/.freeze
|
86
|
+
|
83
87
|
# Remove dot expressions regular expressions
|
84
88
|
RDS_2A = /^\.?\.\/(.*)$/.freeze
|
85
89
|
RDS_2B1 = /^\/\.$/.freeze
|
@@ -160,7 +164,7 @@ module RDF
|
|
160
164
|
# (see #initialize)
|
161
165
|
# @return [RDF::URI] an immutable, frozen URI object
|
162
166
|
def self.intern(str, *args, **options)
|
163
|
-
(cache[(str = str.to_s).to_sym] ||= self.new(str, *args, **options)).freeze
|
167
|
+
(cache[(str = str.to_s).to_sym] ||= self.new(str.to_s, *args, **options)).freeze
|
164
168
|
end
|
165
169
|
|
166
170
|
##
|
@@ -716,8 +720,8 @@ module RDF
|
|
716
720
|
##
|
717
721
|
# @private
|
718
722
|
def freeze
|
719
|
-
|
720
|
-
|
723
|
+
@mutex.synchronize do
|
724
|
+
unless frozen?
|
721
725
|
# Create derived components
|
722
726
|
authority; userinfo; user; password; host; port
|
723
727
|
@value = value.freeze
|
@@ -851,8 +855,7 @@ module RDF
|
|
851
855
|
# lexical representation of URI, either absolute or relative
|
852
856
|
# @return [String]
|
853
857
|
def value
|
854
|
-
|
855
|
-
@value = [
|
858
|
+
@value ||= [
|
856
859
|
("#{scheme}:" if absolute?),
|
857
860
|
("//#{authority}" if authority),
|
858
861
|
path,
|
@@ -883,17 +886,35 @@ module RDF
|
|
883
886
|
#
|
884
887
|
# @param [String, to_s] value
|
885
888
|
# @return [Object{Symbol => String}]
|
889
|
+
# @see https://datatracker.ietf.org/doc/html/rfc8089
|
886
890
|
def parse(value)
|
887
|
-
value = value.to_s.dup.force_encoding(Encoding::
|
891
|
+
value = value.to_s.dup.force_encoding(Encoding::UTF_8) unless value && value.encoding == Encoding::UTF_8
|
888
892
|
parts = {}
|
889
|
-
if matchdata =
|
893
|
+
if matchdata = FILE_PARTS.match(value)
|
894
|
+
# A file-based URI is always in the folloring form:
|
895
|
+
# * file:/path - absolute path, no host name
|
896
|
+
# * file:///path - absolute path, empty host name
|
897
|
+
# * file://hostname/path - absolute path with authority.
|
898
|
+
# * file://path – is invalid, but treated as file:///path
|
899
|
+
scheme = 'file'
|
900
|
+
authority, path, query, fragment = matchdata[1..-1]
|
901
|
+
if authority && authority.match?(/^[A-Za-z]$/) && Gem.win_platform?
|
902
|
+
# In this case, if the authority is a drive letter and part of the path
|
903
|
+
authority, path = nil, "#{authority}#{path}"
|
904
|
+
end
|
905
|
+
# We accept paths that aren't absolute, but coerce them to be absolute
|
906
|
+
path = "/#{path}" unless path.start_with?('/')
|
907
|
+
elsif matchdata = IRI_PARTS.match(value)
|
890
908
|
scheme, authority, path, query, fragment = matchdata[1..-1]
|
909
|
+
authority = nil if authority && authority.empty?
|
891
910
|
|
892
|
-
if
|
893
|
-
#
|
894
|
-
scheme, path = nil, "
|
911
|
+
if scheme && scheme.match?(/^[A-Za-z]$/) && Gem.win_platform?
|
912
|
+
# On Windows treat D:/foo/bar as a path, not a scheme
|
913
|
+
scheme, authority, path = 'file', nil, "/#{scheme}:#{path}"
|
895
914
|
end
|
915
|
+
end
|
896
916
|
|
917
|
+
if matchdata
|
897
918
|
userinfo, hostport = authority.to_s.split('@', 2)
|
898
919
|
hostport, userinfo = userinfo, nil unless hostport
|
899
920
|
user, password = userinfo.to_s.split(':', 2)
|
data/lib/rdf/nquads.rb
CHANGED
@@ -70,11 +70,14 @@ module RDF
|
|
70
70
|
line = @line # for backtracking input in case of parse error
|
71
71
|
|
72
72
|
begin
|
73
|
-
|
74
|
-
#
|
75
|
-
|
73
|
+
if blank? || read_comment
|
74
|
+
# No-op
|
75
|
+
elsif version = read_version
|
76
|
+
@options[:version] = version
|
77
|
+
else
|
78
|
+
subject = read_uriref || read_node || fail_subject
|
76
79
|
predicate = read_uriref(intern: true) || fail_predicate
|
77
|
-
object = read_uriref || read_node || read_literal || read_tripleTerm ||
|
80
|
+
object = read_uriref || read_node || read_literal || read_tripleTerm || fail_object
|
78
81
|
graph_name = read_uriref || read_node
|
79
82
|
if validate? && !read_eos
|
80
83
|
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -30,7 +30,7 @@ module RDF::NTriples
|
|
30
30
|
#
|
31
31
|
# ** RDF=star
|
32
32
|
#
|
33
|
-
# Supports statements as resources using `<<s p o>>`.
|
33
|
+
# Supports statements as resources using `<<(s p o)>>`.
|
34
34
|
#
|
35
35
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
36
36
|
# @see http://www.w3.org/TR/n-triples/
|
@@ -40,8 +40,8 @@ module RDF::NTriples
|
|
40
40
|
|
41
41
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
|
42
42
|
ESCAPE_CHARS = ["\b", "\f", "\t", "\n", "\r", "\"", "'", "\\"].freeze
|
43
|
-
UCHAR4 =
|
44
|
-
UCHAR8 =
|
43
|
+
UCHAR4 = /(?<!\\)\\(?!\\)u([0-9A-Fa-f]{4,4})/.freeze
|
44
|
+
UCHAR8 = /(?<!\\)\\(?!\\)U([0-9A-Fa-f]{8,8})/.freeze
|
45
45
|
UCHAR = Regexp.union(UCHAR4, UCHAR8).freeze
|
46
46
|
|
47
47
|
|
@@ -73,8 +73,8 @@ module RDF::NTriples
|
|
73
73
|
TT_START = /^<<\(/.freeze
|
74
74
|
TT_END = /^\s*\)>>/.freeze
|
75
75
|
|
76
|
-
QT_START = /^<</.freeze
|
77
|
-
QT_END = /^\s*>>/.freeze
|
76
|
+
QT_START = /^<</.freeze # DEPRECATED
|
77
|
+
QT_END = /^\s*>>/.freeze # DEPRECATED
|
78
78
|
|
79
79
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_grammar
|
80
80
|
COMMENT = /^#\s*(.*)$/.freeze
|
@@ -92,6 +92,7 @@ module RDF::NTriples
|
|
92
92
|
|
93
93
|
# LANGTAG is deprecated
|
94
94
|
LANGTAG = LANG_DIR
|
95
|
+
RDF_VERSION = /VERSION/.freeze
|
95
96
|
|
96
97
|
##
|
97
98
|
# Reconstructs an RDF value from its serialized N-Triples
|
@@ -154,7 +155,8 @@ module RDF::NTriples
|
|
154
155
|
def self.parse_literal(input, **options)
|
155
156
|
case input
|
156
157
|
when LITERAL_WITH_LANGUAGE
|
157
|
-
|
158
|
+
language, direction = $4.split('--')
|
159
|
+
RDF::Literal.new(unescape($1), language: language, direction: direction)
|
158
160
|
when LITERAL_WITH_DATATYPE
|
159
161
|
RDF::Literal.new(unescape($1), datatype: $4)
|
160
162
|
when LITERAL_PLAIN
|
@@ -187,22 +189,12 @@ module RDF::NTriples
|
|
187
189
|
# Note: avoiding copying the input string when no escaping is needed
|
188
190
|
# greatly reduces the number of allocations and the processing time.
|
189
191
|
string = string.dup.force_encoding(Encoding::UTF_8) unless string.encoding == Encoding::UTF_8
|
190
|
-
scanner = StringScanner.new(string)
|
191
|
-
|
192
|
-
buffer = ""
|
193
|
-
|
194
|
-
while !scanner.eos?
|
195
|
-
buffer << if scanner.scan(ESCAPE_CHARS_ESCAPED_REGEXP)
|
196
|
-
ESCAPE_CHARS_ESCAPED[scanner.matched]
|
197
|
-
elsif scanner.scan(UCHAR)
|
198
|
-
scanner.matched.sub(UCHAR) {[($1 || $2).hex].pack('U*')}
|
199
|
-
else
|
200
|
-
# Scan one character
|
201
|
-
scanner.getch
|
202
|
-
end
|
203
|
-
end
|
204
192
|
|
205
|
-
|
193
|
+
string
|
194
|
+
.gsub(UCHAR) do
|
195
|
+
[($1 || $2).hex].pack('U*')
|
196
|
+
end
|
197
|
+
.gsub(ESCAPE_CHARS_ESCAPED_REGEXP, ESCAPE_CHARS_ESCAPED)
|
206
198
|
end
|
207
199
|
|
208
200
|
##
|
@@ -211,7 +203,7 @@ module RDF::NTriples
|
|
211
203
|
begin
|
212
204
|
read_statement
|
213
205
|
rescue RDF::ReaderError
|
214
|
-
value = read_uriref || read_node || read_literal || read_tripleTerm
|
206
|
+
value = read_uriref || read_node || read_literal || read_tripleTerm
|
215
207
|
log_recover
|
216
208
|
value
|
217
209
|
end
|
@@ -226,15 +218,21 @@ module RDF::NTriples
|
|
226
218
|
line = @line # for backtracking input in case of parse error
|
227
219
|
|
228
220
|
begin
|
229
|
-
|
230
|
-
|
221
|
+
if blank? || read_comment
|
222
|
+
# No-op
|
223
|
+
elsif version = read_version
|
224
|
+
@options[:version] = version
|
225
|
+
else
|
226
|
+
subject = read_uriref || read_node || fail_subject
|
231
227
|
predicate = read_uriref(intern: true) || fail_predicate
|
232
|
-
object = read_uriref || read_node || read_literal || read_tripleTerm ||
|
228
|
+
object = read_uriref || read_node || read_literal || read_tripleTerm || fail_object
|
233
229
|
|
234
230
|
if validate? && !read_eos
|
235
231
|
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
236
232
|
end
|
237
|
-
|
233
|
+
spo = [subject, predicate, object]
|
234
|
+
# Only return valid triples if validating
|
235
|
+
return spo if !validate? || spo.all?(&:valid?)
|
238
236
|
end
|
239
237
|
rescue RDF::ReaderError => e
|
240
238
|
@line = line # this allows #read_value to work
|
@@ -247,6 +245,9 @@ module RDF::NTriples
|
|
247
245
|
# @return [RDF::Statement]
|
248
246
|
def read_tripleTerm
|
249
247
|
if @options[:rdfstar] && match(TT_START)
|
248
|
+
if version && version != "1.2"
|
249
|
+
log_warn("Triple term used with version #{version}")
|
250
|
+
end
|
250
251
|
subject = read_uriref || read_node || fail_subject
|
251
252
|
predicate = read_uriref(intern: true) || fail_predicate
|
252
253
|
object = read_uriref || read_node || read_literal || read_tripleTerm || fail_object
|
@@ -257,23 +258,6 @@ module RDF::NTriples
|
|
257
258
|
end
|
258
259
|
end
|
259
260
|
|
260
|
-
##
|
261
|
-
# @return [RDF::Statement]
|
262
|
-
# @deprecated Quoted triples are now deprecated
|
263
|
-
def read_quotedTriple
|
264
|
-
if @options[:rdfstar] && !match(TT_START) && match(QT_START)
|
265
|
-
warn "[DEPRECATION] RDF-star quoted triples are deprecated and will be removed in a future version.\n" +
|
266
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
267
|
-
subject = read_uriref || read_node || read_quotedTriple || fail_subject
|
268
|
-
predicate = read_uriref(intern: true) || fail_predicate
|
269
|
-
object = read_uriref || read_node || read_literal || read_quotedTriple || fail_object
|
270
|
-
if !match(QT_END)
|
271
|
-
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
272
|
-
end
|
273
|
-
RDF::Statement.new(subject, predicate, object, quoted: true)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
261
|
##
|
278
262
|
# @return [Boolean]
|
279
263
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_grammar (comment)
|
@@ -288,9 +272,8 @@ module RDF::NTriples
|
|
288
272
|
def read_uriref(intern: false, **options)
|
289
273
|
if uri_str = match(URIREF)
|
290
274
|
uri_str = self.class.unescape(uri_str)
|
291
|
-
uri = RDF::URI.send(intern? && intern ? :intern : :new, uri_str)
|
275
|
+
uri = RDF::URI.send(intern? && intern ? :intern : :new, uri_str, canonicalize: canonicalize?)
|
292
276
|
uri.validate! if validate?
|
293
|
-
uri.canonicalize! if canonicalize?
|
294
277
|
uri
|
295
278
|
end
|
296
279
|
rescue ArgumentError
|
@@ -317,6 +300,7 @@ module RDF::NTriples
|
|
317
300
|
when lang_dir = match(LANG_DIR)
|
318
301
|
language, direction = lang_dir.split('--')
|
319
302
|
raise ArgumentError if direction && !@options[:rdfstar]
|
303
|
+
log_warn("Literal base direction used with version #{version}") if version && version == "1.1"
|
320
304
|
RDF::Literal.new(literal_str, language: language, direction: direction)
|
321
305
|
when datatype = match(/^(\^\^)/) # FIXME
|
322
306
|
RDF::Literal.new(literal_str, datatype: read_uriref || fail_object)
|
@@ -330,7 +314,19 @@ module RDF::NTriples
|
|
330
314
|
rescue ArgumentError
|
331
315
|
v = literal_str
|
332
316
|
v += "@#{lang_dir}" if lang_dir
|
333
|
-
log_error("Invalid Literal (found: \"#{v}\")", lineno: lineno, token:
|
317
|
+
log_error("Invalid Literal (found: \"#{v}\")", lineno: lineno, token: v, exception: RDF::ReaderError)
|
318
|
+
end
|
319
|
+
|
320
|
+
##
|
321
|
+
# @return [String]
|
322
|
+
def read_version
|
323
|
+
if match(RDF_VERSION)
|
324
|
+
ver_tok = match(LITERAL_PLAIN)
|
325
|
+
unless RDF::Format::VERSIONS.include?(ver_tok)
|
326
|
+
log_warn("Expected version to be one of #{RDF::Format::VERSIONS.join(', ')}, was #{ver_tok}")
|
327
|
+
end
|
328
|
+
ver_tok
|
329
|
+
end
|
334
330
|
end
|
335
331
|
|
336
332
|
##
|
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -72,6 +72,10 @@ module RDF::NTriples
|
|
72
72
|
buffer << case u.ord
|
73
73
|
when (0x00..0x7F)
|
74
74
|
escape_ascii(u, encoding)
|
75
|
+
when (0xFFFE..0xFFFF)
|
76
|
+
# NOT A CHARACTER
|
77
|
+
# @see https://corp.unicode.org/~asmus/proposed_faq/private_use.html#history1
|
78
|
+
escape_uchar(u)
|
75
79
|
else
|
76
80
|
u
|
77
81
|
end
|
@@ -100,12 +104,10 @@ module RDF::NTriples
|
|
100
104
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
|
101
105
|
def self.escape_unicode(u, encoding)
|
102
106
|
case (u = u.ord)
|
103
|
-
when (0x00..0x7F) #
|
107
|
+
when (0x00..0x7F) # ECHAR
|
104
108
|
escape_ascii(u, encoding)
|
105
|
-
when (0x80
|
106
|
-
|
107
|
-
when (0x10000..0x10FFFF) # Unicode
|
108
|
-
escape_utf32(u)
|
109
|
+
when (0x80...0x10FFFF) # UCHAR
|
110
|
+
escape_uchar(u)
|
109
111
|
else
|
110
112
|
raise ArgumentError.new("expected a Unicode codepoint in (0x00..0x10FFFF), but got 0x#{u.to_s(16)}")
|
111
113
|
end
|
@@ -132,18 +134,34 @@ module RDF::NTriples
|
|
132
134
|
when (0x0D) then "\\r"
|
133
135
|
when (0x22) then "\\\""
|
134
136
|
when (0x5C) then "\\\\"
|
135
|
-
when (0x00..0x1F) then
|
136
|
-
when (0x7F) then
|
137
|
+
when (0x00..0x1F) then escape_uchar(u)
|
138
|
+
when (0x7F) then escape_uchar(u) # DEL
|
137
139
|
when (0x20..0x7E) then u.chr
|
138
140
|
else
|
139
141
|
raise ArgumentError.new("expected an ASCII character in (0x00..0x7F), but got 0x#{u.to_s(16)}")
|
140
142
|
end
|
141
143
|
end
|
142
144
|
|
145
|
+
##
|
146
|
+
# @param [Integer, #ord] u
|
147
|
+
# @return [String]
|
148
|
+
# @see https://www.w3.org/TR/rdf12-concepts/#rdf-stringshttps://www.w3.org/TR/rdf12-concepts/#rdf-strings
|
149
|
+
# @since 3.4.4
|
150
|
+
def self.escape_uchar(u)
|
151
|
+
#require 'byebug'; byebug
|
152
|
+
case u.ord
|
153
|
+
when (0x00..0xFFFF)
|
154
|
+
sprintf("\\u%04X", u.ord)
|
155
|
+
else
|
156
|
+
sprintf("\\U%08X", u.ord)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
143
160
|
##
|
144
161
|
# @param [Integer, #ord] u
|
145
162
|
# @return [String]
|
146
163
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
|
164
|
+
# @deprecated use escape_uchar, this name is non-intuitive
|
147
165
|
def self.escape_utf16(u)
|
148
166
|
sprintf("\\u%04X", u.ord)
|
149
167
|
end
|
@@ -152,6 +170,7 @@ module RDF::NTriples
|
|
152
170
|
# @param [Integer, #ord] u
|
153
171
|
# @return [String]
|
154
172
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
|
173
|
+
# @deprecated use escape_uchar, this name is non-intuitive
|
155
174
|
def self.escape_utf32(u)
|
156
175
|
sprintf("\\U%08X", u.ord)
|
157
176
|
end
|
@@ -193,6 +212,16 @@ module RDF::NTriples
|
|
193
212
|
super
|
194
213
|
end
|
195
214
|
|
215
|
+
##
|
216
|
+
# Output VERSION directive, if specified and not canonicalizing
|
217
|
+
# @return [self]
|
218
|
+
# @abstract
|
219
|
+
def write_prologue
|
220
|
+
puts %(VERSION #{version.inspect}) if version && !canonicalize?
|
221
|
+
@logged_errors_at_prolog = log_statistics[:error].to_i
|
222
|
+
super
|
223
|
+
end
|
224
|
+
|
196
225
|
##
|
197
226
|
# Outputs an N-Triples comment line.
|
198
227
|
#
|
@@ -230,19 +259,7 @@ module RDF::NTriples
|
|
230
259
|
# @param [Hash{Symbol => Object}] options ({})
|
231
260
|
# @return [String]
|
232
261
|
def format_tripleTerm(statement, **options)
|
233
|
-
"<<(%s %s %s)>>" % statement.to_a.map { |value| format_term(value, **options) }
|
234
|
-
end
|
235
|
-
|
236
|
-
##
|
237
|
-
# Returns the N-Triples representation of an RDF-star quoted triple.
|
238
|
-
#
|
239
|
-
# @param [RDF::Statement] statement
|
240
|
-
# @param [Hash{Symbol => Object}] options ({})
|
241
|
-
# @return [String]
|
242
|
-
# @deprecated Quoted triples are now deprecated
|
243
|
-
def format_quotedTriple(statement, **options)
|
244
|
-
# FIXME: quoted triples are now deprecated
|
245
|
-
"<<%s %s %s>>" % statement.to_a.map { |value| format_term(value, **options) }
|
262
|
+
"<<( %s %s %s )>>" % statement.to_a.map { |value| format_term(value, **options) }
|
246
263
|
end
|
247
264
|
|
248
265
|
##
|
@@ -285,9 +302,9 @@ module RDF::NTriples
|
|
285
302
|
buffer.set_encoding(encoding)
|
286
303
|
string.each_char do |u|
|
287
304
|
buffer << case u.ord
|
288
|
-
when (0x00..0x20) then self.class.
|
305
|
+
when (0x00..0x20) then self.class.escape_uchar(u)
|
289
306
|
when 0x22, 0x3c, 0x3e, 0x5c, 0x5e, 0x60, 0x7b, 0x7c, 0x7d # "<>\^`{|}
|
290
|
-
self.class.
|
307
|
+
self.class.escape_uchar(u)
|
291
308
|
else u
|
292
309
|
end
|
293
310
|
end
|
@@ -299,11 +316,10 @@ module RDF::NTriples
|
|
299
316
|
buffer.set_encoding(Encoding::ASCII)
|
300
317
|
string.each_byte do |u|
|
301
318
|
buffer << case u
|
302
|
-
when (0x00..0x20) then self.class.
|
319
|
+
when (0x00..0x20) then self.class.escape_uchar(u)
|
303
320
|
when 0x22, 0x3c, 0x3e, 0x5c, 0x5e, 0x60, 0x7b, 0x7c, 0x7d # "<>\^`{|}
|
304
|
-
self.class.
|
305
|
-
when (0x80..
|
306
|
-
when (0x10000..0x10FFFF) then self.class.escape_utf32(u)
|
321
|
+
self.class.escape_uchar(u)
|
322
|
+
when (0x80..0x10FFFF) then self.class.escape_uchar(u)
|
307
323
|
else u
|
308
324
|
end
|
309
325
|
end
|
data/lib/rdf/ntriples.rb
CHANGED
@@ -17,11 +17,7 @@ module RDF
|
|
17
17
|
#
|
18
18
|
# ## Triple terms
|
19
19
|
#
|
20
|
-
# Supports statements as resources using `<<(s p o)>>`.
|
21
|
-
|
22
|
-
# ## Quoted Triples (Deprecated)
|
23
|
-
#
|
24
|
-
# Supports statements as resources using `<<s p o>>`.
|
20
|
+
# Supports statements as resources in the object postion using `<<(s p o)>>`.
|
25
21
|
#
|
26
22
|
# ## Installation
|
27
23
|
#
|
data/lib/rdf/reader.rb
CHANGED
@@ -168,15 +168,21 @@ module RDF
|
|
168
168
|
symbol: :validate,
|
169
169
|
datatype: TrueClass,
|
170
170
|
control: :checkbox,
|
171
|
-
on: ["--validate"],
|
172
|
-
description: "Validate input
|
171
|
+
on: ["--[no-]validate"],
|
172
|
+
description: "Validate on input and output."),
|
173
173
|
RDF::CLI::Option.new(
|
174
174
|
symbol: :verifySSL,
|
175
175
|
datatype: TrueClass,
|
176
176
|
default: true,
|
177
177
|
control: :checkbox,
|
178
178
|
on: ["--[no-]verifySSL"],
|
179
|
-
description: "Verify SSL results on HTTP GET")
|
179
|
+
description: "Verify SSL results on HTTP GET"),
|
180
|
+
RDF::CLI::Option.new(
|
181
|
+
symbol: :version,
|
182
|
+
control: :select,
|
183
|
+
datatype: RDF::Format::VERSIONS, # 1.1, 1.2, or 1.2-basic
|
184
|
+
on: ["--version VERSION"],
|
185
|
+
description: "RDF Version."),
|
180
186
|
]
|
181
187
|
end
|
182
188
|
|
@@ -284,6 +290,8 @@ module RDF
|
|
284
290
|
# any additional options
|
285
291
|
# @param [Boolean] validate (false)
|
286
292
|
# whether to validate the parsed statements and values
|
293
|
+
# @option options [String] :version
|
294
|
+
# Parse a specific version of RDF ("1.1', "1.2", or "1.2-basic"")
|
287
295
|
# @yield [reader] `self`
|
288
296
|
# @yieldparam [RDF::Reader] reader
|
289
297
|
# @yieldreturn [void] ignored
|
@@ -309,6 +317,13 @@ module RDF
|
|
309
317
|
validate: validate
|
310
318
|
})
|
311
319
|
|
320
|
+
# The rdfstar option implies version 1.2, but can be overridden
|
321
|
+
@options[:version] ||= "1.2" if @options[:rdfstar]
|
322
|
+
|
323
|
+
unless self.version.nil? || RDF::Format::VERSIONS.include?(self.version)
|
324
|
+
log_error("Expected version to be one of #{RDF::Format::VERSIONS.join(', ')}, was #{self.version}")
|
325
|
+
end
|
326
|
+
|
312
327
|
@input = case input
|
313
328
|
when String then StringIO.new(input)
|
314
329
|
else input
|
@@ -333,7 +348,7 @@ module RDF
|
|
333
348
|
# Returns the base URI determined by this reader.
|
334
349
|
#
|
335
350
|
# @example
|
336
|
-
# reader.
|
351
|
+
# reader.base_uri #=> RDF::URI('http://example.com/')
|
337
352
|
#
|
338
353
|
# @return [RDF::URI]
|
339
354
|
# @since 0.3.0
|
@@ -391,6 +406,18 @@ module RDF
|
|
391
406
|
end
|
392
407
|
alias_method :prefix!, :prefix
|
393
408
|
|
409
|
+
##
|
410
|
+
# Returns the RDF version determined by this reader.
|
411
|
+
#
|
412
|
+
# @example
|
413
|
+
# reader.version #=> "1.2"
|
414
|
+
#
|
415
|
+
# @return [String]
|
416
|
+
# @since 3.3.4
|
417
|
+
def version
|
418
|
+
@options[:version]
|
419
|
+
end
|
420
|
+
|
394
421
|
##
|
395
422
|
# Iterates the given block for each RDF statement.
|
396
423
|
#
|
@@ -417,7 +444,7 @@ module RDF
|
|
417
444
|
begin
|
418
445
|
loop do
|
419
446
|
st = read_statement
|
420
|
-
block.call(st)
|
447
|
+
block.call(st) unless st.nil?
|
421
448
|
end
|
422
449
|
rescue EOFError
|
423
450
|
rewind rescue nil
|
@@ -454,7 +481,7 @@ module RDF
|
|
454
481
|
begin
|
455
482
|
loop do
|
456
483
|
triple = read_triple
|
457
|
-
block.call(*triple)
|
484
|
+
block.call(*triple) unless triple.nil?
|
458
485
|
end
|
459
486
|
rescue EOFError
|
460
487
|
rewind rescue nil
|
@@ -513,7 +540,7 @@ module RDF
|
|
513
540
|
def valid?
|
514
541
|
super && !log_statistics[:error]
|
515
542
|
rescue ArgumentError, RDF::ReaderError => e
|
516
|
-
log_error(e.message)
|
543
|
+
log_error(e.message + " at #{e.backtrace.first}")
|
517
544
|
false
|
518
545
|
end
|
519
546
|
|
data/lib/rdf/repository.rb
CHANGED
@@ -183,8 +183,6 @@ module RDF
|
|
183
183
|
when :literal_equality then true
|
184
184
|
when :atomic_write then false
|
185
185
|
when :rdf_full then false
|
186
|
-
# FIXME: quoted triples are now deprecated
|
187
|
-
when :quoted_triples then false
|
188
186
|
when :base_direction then false
|
189
187
|
when :snapshots then false
|
190
188
|
else false
|
@@ -273,7 +271,6 @@ module RDF
|
|
273
271
|
when :literal_equality then true
|
274
272
|
when :atomic_write then true
|
275
273
|
when :rdf_full then true
|
276
|
-
when :quoted_triples then true
|
277
274
|
when :base_direction then true
|
278
275
|
when :snapshots then true
|
279
276
|
else false
|
data/lib/rdf/util/file.rb
CHANGED
@@ -297,7 +297,6 @@ module RDF; module Util
|
|
297
297
|
# @yieldreturn [Object] returned from open_file
|
298
298
|
# @raise [IOError] if not found
|
299
299
|
def self.open_file(filename_or_url, proxy: nil, headers: {}, verify_none: false, **options, &block)
|
300
|
-
filename_or_url = $1 if filename_or_url.to_s.match(/^file:(.*)$/)
|
301
300
|
remote_document = nil
|
302
301
|
|
303
302
|
if filename_or_url.to_s.match?(/^https?/)
|
@@ -319,6 +318,16 @@ module RDF; module Util
|
|
319
318
|
url_no_frag_or_query.query = nil
|
320
319
|
url_no_frag_or_query.fragment = nil
|
321
320
|
options[:encoding] ||= Encoding::UTF_8
|
321
|
+
|
322
|
+
# Just use path if there's a file scheme. This leaves out a potential host, which isn't supported anyway.
|
323
|
+
if url_no_frag_or_query.scheme == 'file'
|
324
|
+
url_no_frag_or_query = url_no_frag_or_query.path
|
325
|
+
if url_no_frag_or_query.match?(/^\/[A-Za-z]:/) && Gem.win_platform?
|
326
|
+
# Turns "/D:foo" into "D:foo"
|
327
|
+
url_no_frag_or_query = url_no_frag_or_query[1..-1]
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
322
331
|
Kernel.open(url_no_frag_or_query, "r", **options) do |file|
|
323
332
|
document_options = {
|
324
333
|
base_uri: filename_or_url.to_s,
|
data/lib/rdf/writer.rb
CHANGED
@@ -152,6 +152,12 @@ module RDF
|
|
152
152
|
control: :checkbox,
|
153
153
|
on: ["--unique-bnodes"],
|
154
154
|
description: "Use unique Node identifiers.") {true},
|
155
|
+
RDF::CLI::Option.new(
|
156
|
+
symbol: :version,
|
157
|
+
control: :select,
|
158
|
+
datatype: RDF::Format::VERSIONS, # 1.1, 1.2, or 1.2-basic
|
159
|
+
on: ["--version VERSION"],
|
160
|
+
description: "RDF Version."),
|
155
161
|
]
|
156
162
|
end
|
157
163
|
|
@@ -281,6 +287,8 @@ module RDF
|
|
281
287
|
# Use unique {Node} identifiers, defaults to using the identifier which the node was originall initialized with (if any). Implementations should ensure that Nodes are serialized using a unique representation independent of any identifier used when creating the node. See {NTriples::Writer#format_node}
|
282
288
|
# @option options [Hash{Symbol => String}] :accept_params
|
283
289
|
# Parameters from ACCEPT header entry for the media-range matching this writer.
|
290
|
+
# @option options [String] :version
|
291
|
+
# Parse a specific version of RDF ("1.1', "1.2", or "1.2-basic"")
|
284
292
|
# @yield [writer] `self`
|
285
293
|
# @yieldparam [RDF::Writer] writer
|
286
294
|
# @yieldreturn [void]
|
@@ -288,6 +296,13 @@ module RDF
|
|
288
296
|
@output, @options = output, options.dup
|
289
297
|
@nodes, @node_id, @node_id_map = {}, 0, {}
|
290
298
|
|
299
|
+
# The rdfstar option implies version 1.2, but can be overridden
|
300
|
+
@options[:version] ||= "1.2" if @options[:rdfstar]
|
301
|
+
|
302
|
+
unless self.version.nil? || RDF::Format::VERSIONS.include?(self.version)
|
303
|
+
log_warn("Expected version to be one of #{RDF::Format::VERSIONS.join(', ')}, was #{self.version}")
|
304
|
+
end
|
305
|
+
|
291
306
|
if block_given?
|
292
307
|
write_prologue
|
293
308
|
case block.arity
|
@@ -412,6 +427,18 @@ module RDF
|
|
412
427
|
end
|
413
428
|
alias_method :flush!, :flush
|
414
429
|
|
430
|
+
##
|
431
|
+
# Returns the RDF version determined by this reader.
|
432
|
+
#
|
433
|
+
# @example
|
434
|
+
# writer.version #=> "1.2"
|
435
|
+
#
|
436
|
+
# @return [String]
|
437
|
+
# @since 3.3.4
|
438
|
+
def version
|
439
|
+
@options[:version]
|
440
|
+
end
|
441
|
+
|
415
442
|
##
|
416
443
|
# @return [self]
|
417
444
|
# @abstract
|
@@ -482,7 +509,7 @@ module RDF
|
|
482
509
|
end
|
483
510
|
self
|
484
511
|
rescue ArgumentError => e
|
485
|
-
log_error e.message
|
512
|
+
log_error e.message + " at #{e.backtrace.first}"
|
486
513
|
end
|
487
514
|
alias_method :insert_statement, :write_statement # support the RDF::Writable interface
|
488
515
|
|
@@ -518,8 +545,7 @@ module RDF
|
|
518
545
|
when RDF::Literal then format_literal(term, **options)
|
519
546
|
when RDF::URI then format_uri(term, **options)
|
520
547
|
when RDF::Node then format_node(term, **options)
|
521
|
-
|
522
|
-
when RDF::Statement then term.tripleTerm? ? format_tripleTerm(term, **options) : format_quotedTriple(term, **options)
|
548
|
+
when RDF::Statement then format_tripleTerm(term, **options)
|
523
549
|
else nil
|
524
550
|
end
|
525
551
|
end
|
@@ -581,22 +607,6 @@ module RDF
|
|
581
607
|
raise NotImplementedError.new("#{self.class}#format_tripleTerm") # override in subclasses
|
582
608
|
end
|
583
609
|
|
584
|
-
##
|
585
|
-
# Formats a referenced quoted triple.
|
586
|
-
#
|
587
|
-
# @example
|
588
|
-
# <<<s> <p> <o>>> <p> <o> .
|
589
|
-
#
|
590
|
-
# @param [RDF::Statement] value
|
591
|
-
# @param [Hash{Symbol => Object}] options = ({})
|
592
|
-
# @return [String]
|
593
|
-
# @raise [NotImplementedError] unless implemented in subclass
|
594
|
-
# @abstract
|
595
|
-
# @deprecated Quoted Triples are now deprecated in favor of Triple Terms
|
596
|
-
def format_quotedTriple(value, **options)
|
597
|
-
raise NotImplementedError.new("#{self.class}#format_quotedTriple") # override in subclasses
|
598
|
-
end
|
599
|
-
|
600
610
|
protected
|
601
611
|
|
602
612
|
##
|
metadata
CHANGED
@@ -1,17 +1,50 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
8
8
|
- Ben Lavender
|
9
9
|
- Gregg Kellogg
|
10
|
-
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2025-07-13 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bcp47_spec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bigdecimal
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.1'
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.1.5
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '3.1'
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.5
|
15
48
|
- !ruby/object:Gem::Dependency
|
16
49
|
name: link_header
|
17
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -33,39 +66,47 @@ dependencies:
|
|
33
66
|
- !ruby/object:Gem::Version
|
34
67
|
version: 0.0.8
|
35
68
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
69
|
+
name: logger
|
37
70
|
requirement: !ruby/object:Gem::Requirement
|
38
71
|
requirements:
|
39
72
|
- - "~>"
|
40
73
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
74
|
+
version: '1.5'
|
42
75
|
type: :runtime
|
43
76
|
prerelease: false
|
44
77
|
version_requirements: !ruby/object:Gem::Requirement
|
45
78
|
requirements:
|
46
79
|
- - "~>"
|
47
80
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
81
|
+
version: '1.5'
|
49
82
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
83
|
+
name: ostruct
|
51
84
|
requirement: !ruby/object:Gem::Requirement
|
52
85
|
requirements:
|
53
86
|
- - "~>"
|
54
87
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: 3.1.5
|
88
|
+
version: '0.6'
|
59
89
|
type: :runtime
|
60
90
|
prerelease: false
|
61
91
|
version_requirements: !ruby/object:Gem::Requirement
|
62
92
|
requirements:
|
63
93
|
- - "~>"
|
64
94
|
- !ruby/object:Gem::Version
|
65
|
-
version: '
|
66
|
-
|
95
|
+
version: '0.6'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: readline
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
67
101
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
102
|
+
version: '0.0'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.0'
|
69
110
|
- !ruby/object:Gem::Dependency
|
70
111
|
name: base64
|
71
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -321,7 +362,6 @@ metadata:
|
|
321
362
|
homepage_uri: https://github.com/ruby-rdf/rdf
|
322
363
|
mailing_list_uri: https://lists.w3.org/Archives/Public/public-rdf-ruby/
|
323
364
|
source_code_uri: https://github.com/ruby-rdf/rdf
|
324
|
-
post_install_message:
|
325
365
|
rdoc_options: []
|
326
366
|
require_paths:
|
327
367
|
- lib
|
@@ -336,8 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
336
376
|
- !ruby/object:Gem::Version
|
337
377
|
version: '0'
|
338
378
|
requirements: []
|
339
|
-
rubygems_version: 3.
|
340
|
-
signing_key:
|
379
|
+
rubygems_version: 3.6.7
|
341
380
|
specification_version: 4
|
342
381
|
summary: A Ruby library for working with Resource Description Framework (RDF) data.
|
343
382
|
test_files: []
|