rdf 3.3.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 061dd8c1cc1312a0637faec70a4aff5c8f6872e333c225563cd0f426e46b1021
4
- data.tar.gz: 1abd0cfb43de3db148b5930165c0fdf494e1313c577a14b93d8385def05885d0
3
+ metadata.gz: 0b4ec33ae5dd1070409bb56bf6391519dc56fe9e2455e0a9710ea7ec4cbb5308
4
+ data.tar.gz: 628f0e9bb2ad05d3889f1d9e0003c11fa11ec2e664dd762ccc3a0a75782782da
5
5
  SHA512:
6
- metadata.gz: 272d88f2911164ecc3a2fa71f485e4f6f789252b9f7f5d2c5b222e60dd65ebf5acf0843de3c68910e6e795ebe3003eca2f956ca309eff8afae13694fe5de94a5
7
- data.tar.gz: 385f3ff6159082e189d8cfb47bfe4c77243e7c5c18558e5d7a3cd5701d75cebab29f250d7ba28c1f4d7ba5e6564a51236ca367a832534d666c7fc4a4a831bb8a
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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.3.3
1
+ 3.3.4
data/lib/rdf/format.rb CHANGED
@@ -47,6 +47,10 @@ module RDF
47
47
  class Format
48
48
  extend ::Enumerable
49
49
 
50
+ ##
51
+ # RDF defines specific version strings, but does not define normative behavior
52
+ VERSIONS = %w{1.1 1.2-basic 1.2}.freeze
53
+
50
54
  ##
51
55
  # Enumerates known RDF serialization format classes.
52
56
  #
@@ -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. (DEPRECATED)
88
87
  # * `:base_direction` supports RDF 1.2 directional language-tagged strings.
89
88
  #
90
89
  # @param [Symbol, #to_sym] feature
@@ -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
- # FIXME: quoted triples are now deprecated
131
- if statement.embedded? && respond_to?(:supports?) && !(supports?(:quoted_triples) || supports?(:rdf_full))
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"
@@ -104,8 +104,7 @@ module RDF
104
104
  # @private
105
105
  # @see RDF::Enumerable#supports?
106
106
  def supports?(feature)
107
- # FIXME: quoted triples are now deprecated
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
 
@@ -335,8 +335,7 @@ module RDF
335
335
  # @private
336
336
  # @see RDF::Mutable#insert
337
337
  def insert_statement(statement)
338
- # FIXME: quoted triples are now deprecated
339
- if statement.embedded? && !(@data.supports?(:quoted_triples) || @data.supports?(:rdf_full))
338
+ if statement.embedded? && !@data.supports?(:rdf_full)
340
339
  raise ArgumentError, "Graph does not support the RDF Full profile"
341
340
  end
342
341
  if statement.object && statement.object.literal? && statement.object.direction? && !@data.supports?(:base_direction)
@@ -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
- subject && subject.statement? || object && object.statement?
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
- !quoted?
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?
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
- unless blank? || read_comment
74
- # FIXME: quoted triples are now deprecated
75
- subject = read_uriref || read_node || read_quotedTriple || fail_subject
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 || read_quotedTriple || fail_object
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)
@@ -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
- RDF::Literal.new(unescape($1), language: $4)
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
@@ -201,7 +203,7 @@ module RDF::NTriples
201
203
  begin
202
204
  read_statement
203
205
  rescue RDF::ReaderError
204
- value = read_uriref || read_node || read_literal || read_tripleTerm || read_quotedTriple
206
+ value = read_uriref || read_node || read_literal || read_tripleTerm
205
207
  log_recover
206
208
  value
207
209
  end
@@ -216,15 +218,21 @@ module RDF::NTriples
216
218
  line = @line # for backtracking input in case of parse error
217
219
 
218
220
  begin
219
- unless blank? || read_comment
220
- subject = read_uriref || read_node || read_quotedTriple || fail_subject
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
221
227
  predicate = read_uriref(intern: true) || fail_predicate
222
- object = read_uriref || read_node || read_literal || read_tripleTerm || read_quotedTriple || fail_object
228
+ object = read_uriref || read_node || read_literal || read_tripleTerm || fail_object
223
229
 
224
230
  if validate? && !read_eos
225
231
  log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
226
232
  end
227
- return [subject, predicate, object]
233
+ spo = [subject, predicate, object]
234
+ # Only return valid triples if validating
235
+ return spo if !validate? || spo.all?(&:valid?)
228
236
  end
229
237
  rescue RDF::ReaderError => e
230
238
  @line = line # this allows #read_value to work
@@ -237,6 +245,9 @@ module RDF::NTriples
237
245
  # @return [RDF::Statement]
238
246
  def read_tripleTerm
239
247
  if @options[:rdfstar] && match(TT_START)
248
+ if version && version != "1.2"
249
+ log_warn("Triple term used with version #{version}")
250
+ end
240
251
  subject = read_uriref || read_node || fail_subject
241
252
  predicate = read_uriref(intern: true) || fail_predicate
242
253
  object = read_uriref || read_node || read_literal || read_tripleTerm || fail_object
@@ -247,23 +258,6 @@ module RDF::NTriples
247
258
  end
248
259
  end
249
260
 
250
- ##
251
- # @return [RDF::Statement]
252
- # @deprecated Quoted triples are now deprecated (not supported when validating)
253
- def read_quotedTriple
254
- if @options[:rdfstar] && !match(TT_START) && match(QT_START) && !validate?
255
- warn "[DEPRECATION] RDF-star quoted triples are deprecated and will be removed in a future version.\n" +
256
- "Called from #{Gem.location_of_caller.join(':')}"
257
- subject = read_uriref || read_node || read_quotedTriple || fail_subject
258
- predicate = read_uriref(intern: true) || fail_predicate
259
- object = read_uriref || read_node || read_literal || read_quotedTriple || fail_object
260
- if !match(QT_END)
261
- log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
262
- end
263
- RDF::Statement.new(subject, predicate, object, quoted: true)
264
- end
265
- end
266
-
267
261
  ##
268
262
  # @return [Boolean]
269
263
  # @see http://www.w3.org/TR/rdf-testcases/#ntrip_grammar (comment)
@@ -278,9 +272,8 @@ module RDF::NTriples
278
272
  def read_uriref(intern: false, **options)
279
273
  if uri_str = match(URIREF)
280
274
  uri_str = self.class.unescape(uri_str)
281
- uri = RDF::URI.send(intern? && intern ? :intern : :new, uri_str)
275
+ uri = RDF::URI.send(intern? && intern ? :intern : :new, uri_str, canonicalize: canonicalize?)
282
276
  uri.validate! if validate?
283
- uri.canonicalize! if canonicalize?
284
277
  uri
285
278
  end
286
279
  rescue ArgumentError
@@ -307,6 +300,7 @@ module RDF::NTriples
307
300
  when lang_dir = match(LANG_DIR)
308
301
  language, direction = lang_dir.split('--')
309
302
  raise ArgumentError if direction && !@options[:rdfstar]
303
+ log_warn("Literal base direction used with version #{version}") if version && version == "1.1"
310
304
  RDF::Literal.new(literal_str, language: language, direction: direction)
311
305
  when datatype = match(/^(\^\^)/) # FIXME
312
306
  RDF::Literal.new(literal_str, datatype: read_uriref || fail_object)
@@ -320,7 +314,19 @@ module RDF::NTriples
320
314
  rescue ArgumentError
321
315
  v = literal_str
322
316
  v += "@#{lang_dir}" if lang_dir
323
- log_error("Invalid Literal (found: \"#{v}\")", lineno: lineno, token: "#v", exception: RDF::ReaderError)
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
324
330
  end
325
331
 
326
332
  ##
@@ -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) # ASCII 7-bit
107
+ when (0x00..0x7F) # ECHAR
104
108
  escape_ascii(u, encoding)
105
- when (0x80..0xFFFF) # Unicode BMP
106
- escape_utf16(u)
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 escape_utf16(u)
136
- when (0x7F) then escape_utf16(u)
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
  #
@@ -233,18 +262,6 @@ module RDF::NTriples
233
262
  "<<( %s %s %s )>>" % statement.to_a.map { |value| format_term(value, **options) }
234
263
  end
235
264
 
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) }
246
- end
247
-
248
265
  ##
249
266
  # Returns the N-Triples representation of a triple.
250
267
  #
@@ -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.escape_utf16(u)
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.escape_utf16(u)
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.escape_utf16(u)
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.escape_utf16(u)
305
- when (0x80..0xFFFF) then self.class.escape_utf16(u)
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 file."),
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
@@ -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
 
@@ -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 # DEPRECATED
277
274
  when :base_direction then true
278
275
  when :snapshots then true
279
276
  else false
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
- # FIXME: quoted triples are now deprecated
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,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.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: 2025-06-24 00:00:00.000000000 Z
12
+ date: 2025-07-13 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: bcp47_spec
@@ -94,6 +93,20 @@ dependencies:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0.6'
96
+ - !ruby/object:Gem::Dependency
97
+ name: readline
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::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'
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: base64
99
112
  requirement: !ruby/object:Gem::Requirement
@@ -349,7 +362,6 @@ metadata:
349
362
  homepage_uri: https://github.com/ruby-rdf/rdf
350
363
  mailing_list_uri: https://lists.w3.org/Archives/Public/public-rdf-ruby/
351
364
  source_code_uri: https://github.com/ruby-rdf/rdf
352
- post_install_message:
353
365
  rdoc_options: []
354
366
  require_paths:
355
367
  - lib
@@ -364,8 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
364
376
  - !ruby/object:Gem::Version
365
377
  version: '0'
366
378
  requirements: []
367
- rubygems_version: 3.2.33
368
- signing_key:
379
+ rubygems_version: 3.6.7
369
380
  specification_version: 4
370
381
  summary: A Ruby library for working with Resource Description Framework (RDF) data.
371
382
  test_files: []