rdf-rdfxml 1.99.1 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 5a53c64ca08c4b1ba11a7bfd1a2e53e1150b4b1dc9adf6a006c409a09459f4d5
4
- data.tar.gz: da09af1c4ded29d47b46c0a8a2abf16f3f997625ef9c155c196ab9fbdc53a4f5
2
+ SHA1:
3
+ metadata.gz: a97e15f4b3060b84e86264e393b428fc6ed99206
4
+ data.tar.gz: 4816c1d928adb1d589306ee67a50410f43f3d4b0
5
5
  SHA512:
6
- metadata.gz: da1d0c673da3e3c2a3d36632e0f69886ce8d318fcb207dd61145798621b9cd8532d2dc920df08280a0b83cfd937506d5fa168574245c5fd65b6cb8792c631af1
7
- data.tar.gz: 93db4498130704ff853f9d9747fc01bb1db713e9d9d0c8e700e2b8ace1622787fa40058022e345fcc395bbdefc73726fc8a264c22b867c1f3091411e86af7afa
6
+ metadata.gz: c1951f8988b0e05bcdfe6edee336332286ba1aa93c6bbd70f51928305d895a001ba92b914b771e68f4e616e2fa65334bfd3fe7fbd9c3a7f64fc443b70a534a66
7
+ data.tar.gz: bccc43775383cf308f9aff69ec8b66089bcc6bb4fc6ed3079e820c5c36b6e64a9ef034165be6fc0d2b15063e8e8316ba3093a63b32d8b755d7cd2abaff8c2a27
data/README.md CHANGED
@@ -18,7 +18,7 @@ Install with `gem install rdf-rdfxml`
18
18
 
19
19
  * 100% free and unencumbered [public domain](http://unlicense.org/) software.
20
20
  * Implements a complete parser for [RDF/XML][].
21
- * Compatible with Ruby >= 1.9.2.
21
+ * Compatible with Ruby >= 2.0.
22
22
 
23
23
  ## Usage:
24
24
  Instantiate a parser and parse source, specifying type and base-URL
@@ -40,7 +40,7 @@ Write a graph to a file:
40
40
  end
41
41
 
42
42
  ## Dependencies
43
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.1)
43
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 2.0)
44
44
  * Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.6.0)
45
45
 
46
46
  ## Documentation
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.99.1
1
+ 2.0.0.beta1
@@ -6,21 +6,21 @@ module RDF::RDFXML
6
6
  # RDF::Format.for(:rdf) # RDF::RDFXML::Format
7
7
  # RDF::Format.for(:rdfxml) # RDF::RDFXML::Format
8
8
  # RDF::Format.for("etc/foaf.xml")
9
- # RDF::Format.for(:file_name => "etc/foaf.xml")
10
- # RDF::Format.for(:file_extension => "xml")
11
- # RDF::Format.for(:file_extension => "rdf")
12
- # RDF::Format.for(:content_type => "application/xml")
13
- # RDF::Format.for(:content_type => "application/rdf+xml")
9
+ # RDF::Format.for(file_name: "etc/foaf.xml")
10
+ # RDF::Format.for(file_extension: "xml")
11
+ # RDF::Format.for(file_extension: "rdf")
12
+ # RDF::Format.for(content_type: "application/xml")
13
+ # RDF::Format.for(content_type: "application/rdf+xml")
14
14
  #
15
15
  # @example Obtaining serialization format MIME types
16
16
  # RDF::Format.content_types #=> {"application/rdf+xml" => [RDF::RDFXML::Format]}
17
17
  #
18
18
  # @example Obtaining serialization format file extension mappings
19
- # RDF::Format.file_extensions #=> {:rdf => "application/rdf+xml"}
19
+ # RDF::Format.file_extensions #=> {rdf: "application/rdf+xml"}
20
20
  #
21
21
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
22
22
  class Format < RDF::Format
23
- content_type 'application/rdf+xml', :extension => :rdf
23
+ content_type 'application/rdf+xml', extensions: [:rdf, :owl]
24
24
  content_encoding 'utf-8'
25
25
 
26
26
  reader { RDF::RDFXML::Reader }
@@ -43,22 +43,9 @@ module RDF::RDFXML
43
43
  def self.name
44
44
  "RDF/XML"
45
45
  end
46
- end
47
46
 
48
- # Aliases for RDF::Format
49
- #
50
- # This allows the following:
51
- #
52
- # @example Obtaining an HTML format class
53
- # RDF::Format.for(:rdf) # RDF::RDFXML::Lite
54
- # RDF::Format.for(:rdf).reader # RDF::RDFXML::Reader
55
- # RDF::Format.for(:rdf).writer # RDF::RDFXML::Writer
56
- class RDFFormat < RDF::Format
57
- content_type 'application/rdf+xml'
58
- content_encoding 'utf-8'
59
- reader { RDF::RDFXML::Reader }
60
- writer { RDF::RDFXML::Writer }
61
-
62
- def self.to_sym; :rdf; end
47
+ def self.symbols
48
+ [:rdfxml, :rdf, :owl]
49
+ end
63
50
  end
64
51
  end
@@ -14,6 +14,7 @@ module RDF::RDFXML
14
14
  # @author [Gregg Kellogg](http://kellogg-assoc.com/)
15
15
  class Reader < RDF::Reader
16
16
  format Format
17
+ include RDF::Util::Logger
17
18
 
18
19
  CORE_SYNTAX_TERMS = %w(RDF ID about parseType resource nodeID datatype).map {|n| "http://www.w3.org/1999/02/22-rdf-syntax-ns##{n}"}
19
20
  OLD_TERMS = %w(aboutEach aboutEachPrefix bagID).map {|n| "http://www.w3.org/1999/02/22-rdf-syntax-ns##{n}"}
@@ -130,8 +131,6 @@ module RDF::RDFXML
130
131
  # the prefix mappings to use (not supported by all readers)
131
132
  # @option options [#to_s] :base_uri (nil)
132
133
  # the base URI to use when resolving relative URIs
133
- # @option options [Array] :debug
134
- # Array to place debug messages
135
134
  # @return [reader]
136
135
  # @yield [reader] `self`
137
136
  # @yieldparam [RDF::Reader] reader
@@ -139,16 +138,14 @@ module RDF::RDFXML
139
138
  # @raise [Error] Raises RDF::ReaderError if _validate_
140
139
  def initialize(input = $stdin, options = {}, &block)
141
140
  super do
142
- @debug = options[:debug]
143
-
144
141
  @library = case options[:library]
145
- when nil
146
- # Use Nokogiri when available, and REXML otherwise:
147
- defined?(::Nokogiri) ? :nokogiri : :rexml
148
- when :nokogiri, :rexml
149
- options[:library]
150
- else
151
- raise ArgumentError.new("expected :rexml or :nokogiri, but got #{options[:library].inspect}")
142
+ when nil
143
+ # Use Nokogiri when available, and REXML otherwise:
144
+ defined?(::Nokogiri) ? :nokogiri : :rexml
145
+ when :nokogiri, :rexml
146
+ options[:library]
147
+ else
148
+ log_fatal("expected :rexml or :nokogiri, but got #{options[:library].inspect}", exception: ArgumentError)
152
149
  end
153
150
 
154
151
  require "rdf/rdfxml/reader/#{@library}"
@@ -158,10 +155,11 @@ module RDF::RDFXML
158
155
  end
159
156
  self.extend(@implementation)
160
157
 
161
- initialize_xml(input, options) rescue raise RDF::ReaderError.new($!.message)
158
+ input.rewind if input.respond_to?(:rewind)
159
+ initialize_xml(input, options) rescue log_fatal($!.message)
162
160
 
163
- raise RDF::ReaderError, "Empty document" if root.nil? && validate?
164
- raise RDF::ReaderError, "Synax errors:\n#{doc_errors}" if !doc_errors.empty? && validate?
161
+ log_error("Empty document") if root.nil?
162
+ log_error("Synax errors") {doc_errors} if !doc_errors.empty?
165
163
 
166
164
  block.call(self) if block_given?
167
165
  end
@@ -183,8 +181,9 @@ module RDF::RDFXML
183
181
  if block_given?
184
182
  # Block called from add_statement
185
183
  @callback = block
184
+ return unless root
186
185
 
187
- raise "root must be a proxy not a #{root.class}" unless root.is_a?(@implementation::NodeProxy)
186
+ log_fatal "root must be a proxy not a #{root.class}" unless root.is_a?(@implementation::NodeProxy)
188
187
 
189
188
  add_debug(root, "base_uri: #{base_uri.inspect}")
190
189
 
@@ -199,7 +198,7 @@ module RDF::RDFXML
199
198
  nodeElement(root, ec)
200
199
  else
201
200
  rdf_nodes.each do |node|
202
- raise "node must be a proxy not a #{node.class}" unless node.is_a?(@implementation::NodeProxy)
201
+ log_fatal "node must be a proxy not a #{node.class}" unless node.is_a?(@implementation::NodeProxy)
203
202
  # XXX Skip this element if it's contained within another rdf:RDF element
204
203
 
205
204
  # Extract base, lang and namespaces from parents to create proper evaluation context
@@ -209,7 +208,7 @@ module RDF::RDFXML
209
208
  end
210
209
  node.children.each {|el|
211
210
  next unless el.element?
212
- raise "el must be a proxy not a #{el.class}" unless el.is_a?(@implementation::NodeProxy)
211
+ log_fatal "el must be a proxy not a #{el.class}" unless el.is_a?(@implementation::NodeProxy)
213
212
  new_ec = ec.clone(el) do |prefix, value|
214
213
  prefix(prefix, value)
215
214
  end
@@ -217,6 +216,10 @@ module RDF::RDFXML
217
216
  }
218
217
  end
219
218
  end
219
+
220
+ if validate? && log_statistics[:error]
221
+ raise RDF::ReaderError, "Errors found during processing"
222
+ end
220
223
  end
221
224
  enum_for(:each_statement)
222
225
  end
@@ -251,16 +254,22 @@ module RDF::RDFXML
251
254
  "<#{base_uri}>#{node.respond_to?(:display_path) ? node.display_path : node}"
252
255
  end
253
256
 
254
- # Add debug event to debug array, if specified
257
+ # Log a debug message
255
258
  #
256
259
  # @param [Nokogiri::XML::Node, #to_s] node XML Node or string for showing context
257
260
  # @param [String] message
258
261
  # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
259
- def add_debug(node, message = "")
260
- return unless ::RDF::RDFXML.debug? || @debug
261
- message = message + yield if block_given?
262
- puts "#{node_path(node)}: #{message}" if ::RDF::RDFXML::debug?
263
- @debug << "#{node_path(node)}: #{message}".force_encoding("utf-8") if @debug.is_a?(Array)
262
+ def add_debug(node, message = "", &block)
263
+ log_debug(node_path(node), message, &block)
264
+ end
265
+
266
+ # Log an error message
267
+ #
268
+ # @param [Nokogiri::XML::Node, #to_s] node XML Node or string for showing context
269
+ # @param [String] message
270
+ # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
271
+ def add_error(node, message = "", &block)
272
+ log_error(node_path(node), message, &block)
264
273
  end
265
274
 
266
275
  # add a statement, object can be literal or URI or bnode
@@ -272,7 +281,7 @@ module RDF::RDFXML
272
281
  # @return [Statement] Added statement
273
282
  # @raise [RDF::ReaderError] Checks parameter types and raises if they are incorrect if validating.
274
283
  def add_triple(node, subject, predicate, object)
275
- statement = RDF::Statement.new(subject, predicate, object)
284
+ statement = RDF::Statement(subject, predicate, object)
276
285
  add_debug(node) {"statement: #{statement}"}
277
286
  @callback.call(statement)
278
287
  end
@@ -284,7 +293,7 @@ module RDF::RDFXML
284
293
  # @return [RDF::URI] subject The subject found for the node
285
294
  # @raise [RDF::ReaderError] Raises Exception if validating
286
295
  def nodeElement(el, ec)
287
- raise "el must be a proxy not a #{el.class}" unless el.is_a?(@implementation::NodeProxy)
296
+ log_fatal "el must be a proxy not a #{el.class}" unless el.is_a?(@implementation::NodeProxy)
288
297
  # subject
289
298
  subject = ec.subject || parse_subject(el, ec)
290
299
 
@@ -308,7 +317,7 @@ module RDF::RDFXML
308
317
  elsif is_propertyAttr?(attr)
309
318
  # Attributes not RDF.type
310
319
  predicate = attr.uri
311
- lit = RDF::Literal.new(attr.value, :language => ec.language, :validate => validate?, :canonicalize => canonicalize?)
320
+ lit = RDF::Literal.new(attr.value, language: ec.language, validate: validate?, canonicalize: canonicalize?)
312
321
  add_triple(attr, subject, predicate, lit)
313
322
  end
314
323
  end
@@ -316,7 +325,7 @@ module RDF::RDFXML
316
325
  # Handle the propertyEltList children events in document order
317
326
  li_counter = 0 # this will increase for each li we iterate through
318
327
  el.children.each do |child|
319
- raise "child must be a proxy not a #{child.class}" unless child.is_a?(@implementation::NodeProxy)
328
+ log_fatal "child must be a proxy not a #{child.class}" unless child.is_a?(@implementation::NodeProxy)
320
329
  next unless child.element?
321
330
  child_ec = ec.clone(child) do |prefix, value|
322
331
  prefix(prefix, value)
@@ -326,17 +335,17 @@ module RDF::RDFXML
326
335
  propertyElementURI_check(child)
327
336
 
328
337
  # Determine the content type of this property element
329
- raise "child must be a proxy not a #{child.class}" unless child.is_a?(@implementation::NodeProxy)
338
+ log_fatal "child must be a proxy not a #{child.class}" unless child.is_a?(@implementation::NodeProxy)
330
339
 
331
340
  text_nodes = child.children.select {|e| e.text? && !e.blank?}
332
341
  element_nodes = child.children.select {|c| c.element? }
333
342
  add_debug(child) {"#{text_nodes.to_a.length} text nodes, #{element_nodes.to_a.length} element nodes"}
334
343
 
335
344
  text_nodes.each do |node|
336
- raise "text node must be a proxy not a #{node.class}" unless node.is_a?(@implementation::NodeProxy)
345
+ log_fatal "text node must be a proxy not a #{node.class}" unless node.is_a?(@implementation::NodeProxy)
337
346
  end
338
347
  element_nodes.each do |node|
339
- raise "element node must be a proxy not a #{node.class}" unless node.is_a?(@implementation::NodeProxy)
348
+ log_fatal "element node must be a proxy not a #{node.class}" unless node.is_a?(@implementation::NodeProxy)
340
349
  end
341
350
 
342
351
  if element_nodes.size > 1
@@ -383,10 +392,7 @@ module RDF::RDFXML
383
392
  end
384
393
  end
385
394
 
386
- if nodeID && resourceAttr
387
- add_debug(el, "Cannot have rdf:nodeID and rdf:resource.")
388
- raise RDF::ReaderError.new("Cannot have rdf:nodeID and rdf:resource.") if validate?
389
- end
395
+ add_error(el, "Cannot have rdf:nodeID and rdf:resource.") if nodeID && resourceAttr
390
396
 
391
397
  # Apply character transformations
392
398
  id = id_check(el, RDF::NTriples.unescape(id), nil) if id
@@ -407,7 +413,7 @@ module RDF::RDFXML
407
413
  prefix(prefix, value)
408
414
  end
409
415
  new_node_element = element_nodes.first
410
- raise "new_node_element must be a proxy not a #{new_node_element.class}" unless new_node_element.is_a?(@implementation::NodeProxy)
416
+ log_fatal "new_node_element must be a proxy not a #{new_node_element.class}" unless new_node_element.is_a?(@implementation::NodeProxy)
411
417
  add_debug(child) {"resourcePropertyElt: #{node_path(new_node_element)}"}
412
418
  new_subject = nodeElement(new_node_element, new_ec)
413
419
  add_triple(child, subject, predicate, new_subject)
@@ -415,7 +421,7 @@ module RDF::RDFXML
415
421
  # Production literalPropertyElt
416
422
  add_debug(child, "literalPropertyElt")
417
423
 
418
- literal_opts = {:validate => validate?, :canonicalize => canonicalize?}
424
+ literal_opts = {validate: validate?, canonicalize: canonicalize?}
419
425
  if datatype
420
426
  literal_opts[:datatype] = uri(datatype)
421
427
  else
@@ -429,9 +435,7 @@ module RDF::RDFXML
429
435
  add_debug(child, "parseTypeResourcePropertyElt")
430
436
 
431
437
  unless attrs.empty?
432
- warn = "Resource Property with extra attributes: '#{attrs.inspect}'"
433
- add_debug(child, warn)
434
- raise RDF::ReaderError.new(warn) if validate?
438
+ add_error(child, "Resource Property with extra attributes") {attrs.inspect}
435
439
  end
436
440
 
437
441
  # For element e with possibly empty element content c.
@@ -454,7 +458,7 @@ module RDF::RDFXML
454
458
  node = el.create_node("Description", child.children)
455
459
  node.add_namespace(nil, RDF.to_uri.to_s)
456
460
  add_debug(node) { "uri: #{node.uri}, namespace: #{node.namespace.inspect}"}
457
- new_ec = child_ec.clone(nil, :subject => n) do |prefix, value|
461
+ new_ec = child_ec.clone(nil, subject: n) do |prefix, value|
458
462
  prefix(prefix, value)
459
463
  end
460
464
  nodeElement(node, new_ec)
@@ -463,9 +467,7 @@ module RDF::RDFXML
463
467
  add_debug(child, "parseTypeCollectionPropertyElt")
464
468
 
465
469
  unless attrs.empty?
466
- warn = "Resource Property with extra attributes: '#{attrs.inspect}'"
467
- add_debug(child, warn)
468
- raise RDF::ReaderError.new(warn) if validate?
470
+ add_error(child, "Resource Property with extra attributes") {attrs.inspect}
469
471
  end
470
472
 
471
473
  # For element event e with possibly empty nodeElementList l. Set s:=list().
@@ -493,27 +495,23 @@ module RDF::RDFXML
493
495
  add_debug(child, parseType == "Literal" ? "parseTypeResourcePropertyElt" : "parseTypeOtherPropertyElt (#{parseType})")
494
496
 
495
497
  unless attrs.empty?
496
- warn = "Resource Property with extra attributes: '#{attrs.inspect}'"
497
- add_debug(child, warn)
498
- raise RDF::ReaderError.new(warn) if validate?
498
+ add_error(child, "Resource Property with extra attributes") {attrs.inspect}
499
499
  end
500
500
 
501
501
  if resourceAttr
502
- warn = "illegal rdf:resource"
503
- add_debug(child, warn)
504
- raise RDF::ReaderError.new(warn) if validate?
502
+ add_error(child, "illegal rdf:resource") {resourceAttr.inspect}
505
503
  end
506
504
 
507
505
  begin
508
506
  c14nxl = child.children.c14nxl(
509
- :library => @library,
510
- :language => ec.language,
511
- :namespaces => child_ec.uri_mappings)
507
+ library: @library,
508
+ language: ec.language,
509
+ namespaces: child_ec.uri_mappings)
512
510
  object = RDF::Literal.new(c14nxl,
513
- :library => @library,
514
- :datatype => RDF.XMLLiteral,
515
- :validate => validate?,
516
- :canonicalize => canonicalize?)
511
+ library: @library,
512
+ datatype: RDF.XMLLiteral,
513
+ validate: validate?,
514
+ canonicalize: canonicalize?)
517
515
 
518
516
  add_triple(child, subject, predicate, object)
519
517
  rescue ArgumentError => e
@@ -525,7 +523,7 @@ module RDF::RDFXML
525
523
 
526
524
  if attrs.empty? && resourceAttr.nil? && nodeID.nil?
527
525
 
528
- literal = RDF::Literal.new("", :language => ec.language)
526
+ literal = RDF::Literal.new("", language: ec.language)
529
527
  add_triple(child, subject, predicate, literal)
530
528
 
531
529
  # Reification
@@ -550,7 +548,7 @@ module RDF::RDFXML
550
548
  next unless is_propertyAttr?(attr)
551
549
 
552
550
  # Attributes not in RDF.type
553
- lit = RDF::Literal.new(val, :language => child_ec.language)
551
+ lit = RDF::Literal.new(val, language: child_ec.language)
554
552
  add_triple(child, resource, attr.uri, lit)
555
553
  end
556
554
  end
@@ -587,11 +585,9 @@ module RDF::RDFXML
587
585
  nodeID = el.attribute_with_ns("nodeID", RDF.to_uri.to_s)
588
586
 
589
587
  if nodeID && about
590
- add_debug(el, "Cannot have rdf:nodeID and rdf:about.")
591
- raise RDF::ReaderError.new("Cannot have rdf:nodeID and rdf:about.") if validate?
588
+ add_error(el, "Cannot have rdf:nodeID and rdf:about.")
592
589
  elsif nodeID && id
593
- add_debug(el, "Cannot have rdf:nodeID and rdf:ID.")
594
- raise RDF::ReaderError.new("Cannot have rdf:nodeID and rdf:ID.") if validate?
590
+ add_error(el, "Cannot have rdf:nodeID and rdf:ID.")
595
591
  end
596
592
 
597
593
  case
@@ -615,19 +611,12 @@ module RDF::RDFXML
615
611
 
616
612
  # ID attribute must be an NCName
617
613
  def id_check(el, id, base)
618
- unless NC_REGEXP.match(id)
619
- warn = "ID addtribute '#{id}' must be a NCName"
620
- add_debug(el, warn)
621
- raise RDF::ReaderError.new(warn) if validate?
622
- end
614
+ add_error(el, "ID addtribute '#{id}' must be a NCName") unless NC_REGEXP.match(id)
615
+
623
616
  # ID may only be specified once for the same URI
624
617
  if base
625
618
  uri = uri(base, "##{id}")
626
- if prefix(id) && RDF::URI(prefix(id)) == uri
627
- warn = "ID addtribute '#{id}' may only be defined once for the same URI"
628
- add_debug(el, warn)
629
- raise RDF::ReaderError.new(warn) if validate?
630
- end
619
+ add_error(el, "ID addtribute '#{id}' may only be defined once for the same URI") if prefix(id) && RDF::URI(prefix(id)) == uri
631
620
 
632
621
  RDF::URI(prefix(id, uri))
633
622
  # Returns URI, in this case
@@ -642,8 +631,7 @@ module RDF::RDFXML
642
631
  if NC_REGEXP.match(nodeID)
643
632
  nodeID
644
633
  else
645
- add_debug(el, "nodeID addtribute '#{nodeID}' must be an XML Name")
646
- raise RDF::ReaderError.new("nodeID addtribute '#{nodeID}' must be a NCName") if validate?
634
+ add_error(el, "nodeID addtribute '#{nodeID}' must be an XML Name")
647
635
  nil
648
636
  end
649
637
  end
@@ -651,9 +639,7 @@ module RDF::RDFXML
651
639
  # Is this attribute a Property Attribute?
652
640
  def is_propertyAttr?(attr)
653
641
  if ([RDF.Description.to_s, RDF.li.to_s] + OLD_TERMS).include?(attr.uri.to_s)
654
- warn = "Invalid use of rdf:#{attr.name}"
655
- add_debug(attr, warn)
656
- raise RDF::ReaderError.new(warn) if validate?
642
+ add_error(attr, "Invalid use of rdf:#{attr.name}")
657
643
  return false
658
644
  end
659
645
  !CORE_SYNTAX_TERMS.include?(attr.uri.to_s) && attr.namespace && attr.namespace.href != RDF::XML.to_s
@@ -662,18 +648,14 @@ module RDF::RDFXML
662
648
  # Check Node Element name
663
649
  def nodeElementURI_check(el)
664
650
  if (CORE_SYNTAX_TERMS + [RDF.li.to_s] + OLD_TERMS).include?(el.uri.to_s)
665
- warn = "Invalid use of rdf:#{el.name}"
666
- add_debug(el, warn)
667
- raise RDF::ReaderError.new(warn) if validate?
651
+ add_error(el, "Invalid use of rdf:#{el.name}")
668
652
  end
669
653
  end
670
654
 
671
655
  # Check Property Element name
672
656
  def propertyElementURI_check(el)
673
657
  if (CORE_SYNTAX_TERMS + [RDF.Description.to_s] + OLD_TERMS).include?(el.uri.to_s)
674
- warn = "Invalid use of rdf:#{el.name}"
675
- add_debug(el, warn)
676
- raise RDF::ReaderError.new(warn) if validate?
658
+ add_error(el, "Invalid use of rdf:#{el.name}")
677
659
  end
678
660
  end
679
661
 
@@ -681,8 +663,7 @@ module RDF::RDFXML
681
663
  def old_property_check(el)
682
664
  el.attribute_nodes.each do |attr|
683
665
  if OLD_TERMS.include?(attr.uri.to_s)
684
- add_debug(el) {"Obsolete attribute '#{attr.uri}'"}
685
- raise RDF::ReaderError.new("Obsolete attribute '#{attr.uri}'") if validate?
666
+ add_error(el) {"Obsolete attribute '#{attr.uri}'"}
686
667
  end
687
668
  end
688
669
  end
@@ -13,9 +13,9 @@ module RDF::RDFXML
13
13
  # @example Obtaining a RDF/XML writer class
14
14
  # RDF::Writer.for(:rdf) #=> RDF::RDFXML::Writer
15
15
  # RDF::Writer.for("etc/test.rdf")
16
- # RDF::Writer.for(:file_name => "etc/test.rdf")
17
- # RDF::Writer.for(:file_extension => "rdf")
18
- # RDF::Writer.for(:content_type => "application/rdf+xml")
16
+ # RDF::Writer.for(file_name: "etc/test.rdf")
17
+ # RDF::Writer.for(file_extension: "rdf")
18
+ # RDF::Writer.for(content_type: "application/rdf+xml")
19
19
  #
20
20
  # @example Serializing RDF graph into an RDF/XML file
21
21
  # RDF::RDFXML::Write.open("etc/test.rdf") do |writer|
@@ -37,9 +37,9 @@ module RDF::RDFXML
37
37
  # end
38
38
  #
39
39
  # @example Creating @base and @prefix definitions in output
40
- # RDF::RDFXML::Writer.buffer(:base_uri => "http://example.com/", :prefixes => {
40
+ # RDF::RDFXML::Writer.buffer(base_uri: "http://example.com/", prefixes: {
41
41
  # nil => "http://example.com/ns#",
42
- # :foaf => "http://xmlns.com/foaf/0.1/"}
42
+ # foaf: "http://xmlns.com/foaf/0.1/"}
43
43
  # ) do |writer|
44
44
  # graph.each_statement do |statement|
45
45
  # writer << statement
@@ -49,9 +49,43 @@ module RDF::RDFXML
49
49
  # @author [Gregg Kellogg](http://kellogg-assoc.com/)
50
50
  class Writer < RDF::RDFa::Writer
51
51
  format RDF::RDFXML::Format
52
+ include RDF::Util::Logger
52
53
 
53
54
  VALID_ATTRIBUTES = [:none, :untyped, :typed]
54
55
 
56
+ ##
57
+ # RDF/XML Writer options
58
+ # @see http://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Writer#options-class_method
59
+ def self.options
60
+ super + [
61
+ RDF::CLI::Option.new(
62
+ symbol: :attributes,
63
+ datatype: %w(none untyped typed),
64
+ on: ["--attributes ATTRIBUTES", %w(none untyped typed)],
65
+ description: "How to use XML attributes when serializing, one of :none, :untyped, :typed. The default is :none.") {|arg| arg.to_sym},
66
+ RDF::CLI::Option.new(
67
+ symbol: :default_namespace,
68
+ datatype: RDF::URI,
69
+ on: ["--default-namespace URI", :REQUIRED],
70
+ description: "URI to use as default namespace, same as prefixes.") {|arg| RDF::URI(arg)},
71
+ RDF::CLI::Option.new(
72
+ symbol: :lang,
73
+ datatype: String,
74
+ on: ["--lang"],
75
+ description: "Output as root @lang attribute, and avoid generation _@lang_ where possible."),
76
+ RDF::CLI::Option.new(
77
+ symbol: :max_depth,
78
+ datatype: Integer,
79
+ on: ["--max-depth"],
80
+ description: "Maximum depth for recursively defining resources, defaults to 3.") {|arg| arg.to_i},
81
+ RDF::CLI::Option.new(
82
+ symbol: :stylesheet,
83
+ datatype: RDF::URI,
84
+ on: ["--stylesheet URI", :REQUIRED],
85
+ description: "URI to use as @href for output stylesheet processing instruction.") {|arg| RDF::URI(arg)},
86
+ ]
87
+ end
88
+
55
89
  ##
56
90
  # Initializes the RDF/XML writer instance.
57
91
  #
@@ -155,7 +189,7 @@ module RDF::RDFXML
155
189
  end
156
190
 
157
191
  predicates -= attr_props.keys.map {|k| expand_curie(k).to_s}
158
- super(subject, predicates, options.merge(:attr_props => attr_props), &block)
192
+ super(subject, predicates, options.merge(attr_props: attr_props), &block)
159
193
  end
160
194
  # See if we can serialize as attribute.
161
195
  # * untyped attributes that aren't duplicated where xml:lang == @lang
@@ -195,7 +229,7 @@ module RDF::RDFXML
195
229
  # @return String
196
230
  # The rendered document is returned as a string
197
231
  def render_document(subjects, options = {}, &block)
198
- super(subjects, options.merge(:stylesheet => @options[:stylesheet]), &block)
232
+ super(subjects, options.merge(stylesheet: @options[:stylesheet]), &block)
199
233
  end
200
234
 
201
235
  # Render a single- or multi-valued predicate using `haml_template[:property_value]` or `haml_template[:property_values]`. Yields each object for optional rendering. The block should only render for recursive subject definitions (i.e., where the object is also a subject and is rendered underneath the first referencing subject).
@@ -223,7 +257,7 @@ module RDF::RDFXML
223
257
  # @return String
224
258
  # The rendered document is returned as a string
225
259
  def render_property(predicate, objects, options = {}, &block)
226
- add_debug {"render_property(#{predicate}): #{objects.inspect}, #{options.inspect}"}
260
+ log_debug {"render_property(#{predicate}): #{objects.inspect}, #{options.inspect}"}
227
261
  # If there are multiple objects, and no :property_values is defined, call recursively with
228
262
  # each object
229
263
 
@@ -233,19 +267,19 @@ module RDF::RDFXML
233
267
  # Separate out the objects which are lists and render separately
234
268
  lists = objects.
235
269
  select(&:node?).
236
- map {|o| RDF::List.new(o, @graph)}.
270
+ map {|o| RDF::List.new(subject: o, graph: @graph)}.
237
271
  select {|l| l.valid? && l.none?(&:literal?)}
238
272
 
239
273
  unless lists.empty?
240
274
  # Render non-list objects
241
- add_debug {"properties with lists: #{lists} non-lists: #{objects - lists.map(&:subject)}"}
242
- nl = depth {render_property(predicate, objects - lists.map(&:subject), options, &block)} unless objects == lists.map(&:subject)
275
+ log_debug {"properties with lists: #{lists} non-lists: #{objects - lists.map(&:subject)}"}
276
+ nl = log_depth {render_property(predicate, objects - lists.map(&:subject), options, &block)} unless objects == lists.map(&:subject)
243
277
  return nl.to_s + lists.map do |list|
244
278
  # Render each list as multiple properties and set :inlist to true
245
279
  list.each_statement {|st| subject_done(st.subject)}
246
280
 
247
- add_debug {"list: #{list.inspect} #{list.to_a}"}
248
- depth do
281
+ log_debug {"list: #{list.inspect} #{list.to_a}"}
282
+ log_depth do
249
283
  render_collection(predicate, list, options) do |object|
250
284
  yield(object, true) if block_given?
251
285
  end
@@ -256,16 +290,16 @@ module RDF::RDFXML
256
290
  if objects.length > 1
257
291
  # Render each property using property_value template
258
292
  objects.map do |object|
259
- depth {render_property(predicate, [object], options, &block)}
293
+ log_depth {render_property(predicate, [object], options, &block)}
260
294
  end.join(" ")
261
295
  else
262
- raise RDF::WriterError, "Missing property template" if template.nil?
296
+ log_fatal("Missing property template", exception: RDF::WriterError) if template.nil?
263
297
 
264
298
  options = {
265
299
  object: objects.first,
266
300
  predicate: predicate,
267
301
  property: get_qname(predicate),
268
- recurse: @depth <= @max_depth
302
+ recurse: log_depth <= @max_depth
269
303
  }.merge(options)
270
304
  hamlify(template, options, &block)
271
305
  end
@@ -292,7 +326,7 @@ module RDF::RDFXML
292
326
  list: list,
293
327
  predicate: predicate,
294
328
  property: get_qname(predicate),
295
- recurse: @depth <= @max_depth,
329
+ recurse: log_depth <= @max_depth,
296
330
  }.merge(options)
297
331
  hamlify(template, options) do |object|
298
332
  yield object
@@ -365,7 +399,7 @@ module RDF::RDFXML
365
399
  base_uri = uri.to_s[0..separation]
366
400
  suffix = uri.to_s[separation+1..-1]
367
401
  @gen_prefix = @gen_prefix ? @gen_prefix.succ : "ns0"
368
- add_debug {"ensure_curie: generated prefix #{@gen_prefix} for #{base_uri}"}
402
+ log_debug {"ensure_curie: generated prefix #{@gen_prefix} for #{base_uri}"}
369
403
  @uri_to_prefix[base_uri] = @gen_prefix
370
404
  @uri_to_term_or_curie[uri] = "#{@gen_prefix}:#{suffix}"
371
405
  prefix(@gen_prefix, base_uri)
@@ -3,11 +3,11 @@ module RDF::RDFXML
3
3
  class Writer
4
4
  # The default set of HAML templates used for RDFa code generation
5
5
  BASE_HAML = {
6
- :identifier => "base",
6
+ identifier: "base",
7
7
  # Document
8
8
  # Locals: lang, title, prefix, base, subjects
9
9
  # Yield: subjects.each
10
- :doc => %q(
10
+ doc: %q(
11
11
  = %(<?xml version='1.0' encoding='utf-8' ?>)
12
12
  - if stylesheet
13
13
  = %(<?xml-stylesheet type="text/xsl" href="#{stylesheet}"?>)
@@ -25,7 +25,7 @@ module RDF::RDFXML
25
25
  #
26
26
  # Locals: subject, typeof, predicates, rel, element, inlist, attr_props
27
27
  # Yield: predicates.each
28
- :subject => %q(
28
+ subject: %q(
29
29
  - first_type, *types = typeof.to_s.split(' ')
30
30
  - (types.unshift(first_type); first_type = nil) if first_type && (first_type.include?('/') || first_type.start_with?('_:'))
31
31
  - first_type ||= get_qname(RDF.Description)
@@ -38,8 +38,7 @@ module RDF::RDFXML
38
38
  - if expanded_type.start_with?('_:')
39
39
  - haml_tag(get_qname(RDF.type), "rdf:nodeID" => expanded_type[2..-1])
40
40
  -else
41
- - # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
42
- - haml_tag(get_qname(RDF.type), "", "rdf:resource" => expanded_type)
41
+ - haml_tag(get_qname(RDF.type), "rdf:resource" => expanded_type)
43
42
  - predicates.each do |p|
44
43
  = yield(p)
45
44
  ),
@@ -49,7 +48,7 @@ module RDF::RDFXML
49
48
  # Yields: object
50
49
  # If nil is returned, render as a leaf
51
50
  # Otherwise, render result
52
- :property_value => %q(
51
+ property_value: %q(
53
52
  - if recurse && res = yield(object)
54
53
  - haml_tag(property) do
55
54
  = res
@@ -60,11 +59,9 @@ module RDF::RDFXML
60
59
  - haml_tag(property, :"<", "xml:lang" => object.language, "rdf:datatype" => (object.datatype unless object.plain?)) do
61
60
  = object.value.to_s.encode(xml: :text)
62
61
  - elsif object.node?
63
- - # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
64
- - haml_tag(property, "", "rdf:nodeID" => object.id)
62
+ - haml_tag(property, :"/", "rdf:nodeID" => object.id)
65
63
  - else
66
- - # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
67
- - haml_tag(property, "", "rdf:resource" => relativize(object))
64
+ - haml_tag(property, :"/", "rdf:resource" => relativize(object))
68
65
  ),
69
66
 
70
67
  # Outpust for a list
@@ -72,20 +69,18 @@ module RDF::RDFXML
72
69
  # Yields: object
73
70
  # If nil is returned, render as a leaf
74
71
  # Otherwise, render result
75
- :collection => %q(
72
+ collection: %q(
76
73
  - haml_tag(property, get_qname(RDF.parseType) => "Collection") do
77
74
  - list.each do |object|
78
75
  - if recurse && res = yield(object)
79
76
  = res
80
77
  - elsif object.node?
81
- - # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
82
- - haml_tag(get_qname(RDF.Description), "", "rdf:nodeID" => (object.id if ref_count(object) > 1))
78
+ - haml_tag(get_qname(RDF.Description), :"/", "rdf:nodeID" => (object.id if ref_count(object) > 1))
83
79
  - else
84
- - # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
85
- - haml_tag(get_qname(RDF.Description), "", "rdf:about" => relativize(object))
80
+ - haml_tag(get_qname(RDF.Description), :"/", "rdf:about" => relativize(object))
86
81
  ),
87
82
  }
88
- HAML_TEMPLATES = {:base => BASE_HAML}
83
+ HAML_TEMPLATES = {base: BASE_HAML}
89
84
  DEFAULT_HAML = BASE_HAML
90
85
  end
91
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-rdfxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.99.1
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg
@@ -9,50 +9,68 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-04 00:00:00.000000000 Z
12
+ date: 2016-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.99'
20
+ version: 2.0.0.beta
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '3'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0.beta
31
+ - - "<"
26
32
  - !ruby/object:Gem::Version
27
- version: '1.99'
33
+ version: '3'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: rdf-rdfa
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
- - - "~>"
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0.beta
41
+ - - "<"
33
42
  - !ruby/object:Gem::Version
34
- version: '1.99'
43
+ version: '3'
35
44
  type: :runtime
36
45
  prerelease: false
37
46
  version_requirements: !ruby/object:Gem::Requirement
38
47
  requirements:
39
- - - "~>"
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0.beta
51
+ - - "<"
40
52
  - !ruby/object:Gem::Version
41
- version: '1.99'
53
+ version: '3'
42
54
  - !ruby/object:Gem::Dependency
43
55
  name: rdf-xsd
44
56
  requirement: !ruby/object:Gem::Requirement
45
57
  requirements:
46
- - - "~>"
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.0.0.beta
61
+ - - "<"
47
62
  - !ruby/object:Gem::Version
48
- version: '1.99'
63
+ version: '3'
49
64
  type: :runtime
50
65
  prerelease: false
51
66
  version_requirements: !ruby/object:Gem::Requirement
52
67
  requirements:
53
- - - "~>"
68
+ - - ">="
54
69
  - !ruby/object:Gem::Version
55
- version: '1.99'
70
+ version: 2.0.0.beta
71
+ - - "<"
72
+ - !ruby/object:Gem::Version
73
+ version: '3'
56
74
  - !ruby/object:Gem::Dependency
57
75
  name: htmlentities
58
76
  requirement: !ruby/object:Gem::Requirement
@@ -105,100 +123,130 @@ dependencies:
105
123
  name: json-ld
106
124
  requirement: !ruby/object:Gem::Requirement
107
125
  requirements:
108
- - - "~>"
126
+ - - ">="
109
127
  - !ruby/object:Gem::Version
110
- version: '1.99'
128
+ version: 2.0.0.beta
129
+ - - "<"
130
+ - !ruby/object:Gem::Version
131
+ version: '3'
111
132
  type: :development
112
133
  prerelease: false
113
134
  version_requirements: !ruby/object:Gem::Requirement
114
135
  requirements:
115
- - - "~>"
136
+ - - ">="
116
137
  - !ruby/object:Gem::Version
117
- version: '1.99'
138
+ version: 2.0.0.beta
139
+ - - "<"
140
+ - !ruby/object:Gem::Version
141
+ version: '3'
118
142
  - !ruby/object:Gem::Dependency
119
143
  name: rspec
120
144
  requirement: !ruby/object:Gem::Requirement
121
145
  requirements:
122
146
  - - "~>"
123
147
  - !ruby/object:Gem::Version
124
- version: '3.2'
148
+ version: '3.4'
125
149
  type: :development
126
150
  prerelease: false
127
151
  version_requirements: !ruby/object:Gem::Requirement
128
152
  requirements:
129
153
  - - "~>"
130
154
  - !ruby/object:Gem::Version
131
- version: '3.2'
155
+ version: '3.4'
132
156
  - !ruby/object:Gem::Dependency
133
157
  name: rspec-its
134
158
  requirement: !ruby/object:Gem::Requirement
135
159
  requirements:
136
160
  - - "~>"
137
161
  - !ruby/object:Gem::Version
138
- version: '1.0'
162
+ version: '1.2'
139
163
  type: :development
140
164
  prerelease: false
141
165
  version_requirements: !ruby/object:Gem::Requirement
142
166
  requirements:
143
167
  - - "~>"
144
168
  - !ruby/object:Gem::Version
145
- version: '1.0'
169
+ version: '1.2'
146
170
  - !ruby/object:Gem::Dependency
147
171
  name: rdf-isomorphic
148
172
  requirement: !ruby/object:Gem::Requirement
149
173
  requirements:
150
- - - "~>"
174
+ - - ">="
151
175
  - !ruby/object:Gem::Version
152
- version: '1.99'
176
+ version: 2.0.0.beta
177
+ - - "<"
178
+ - !ruby/object:Gem::Version
179
+ version: '3'
153
180
  type: :development
154
181
  prerelease: false
155
182
  version_requirements: !ruby/object:Gem::Requirement
156
183
  requirements:
157
- - - "~>"
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: 2.0.0.beta
187
+ - - "<"
158
188
  - !ruby/object:Gem::Version
159
- version: '1.99'
189
+ version: '3'
160
190
  - !ruby/object:Gem::Dependency
161
191
  name: rdf-turtle
162
192
  requirement: !ruby/object:Gem::Requirement
163
193
  requirements:
164
- - - "~>"
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: 2.0.0.beta
197
+ - - "<"
165
198
  - !ruby/object:Gem::Version
166
- version: '1.99'
199
+ version: '3'
167
200
  type: :development
168
201
  prerelease: false
169
202
  version_requirements: !ruby/object:Gem::Requirement
170
203
  requirements:
171
- - - "~>"
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: 2.0.0.beta
207
+ - - "<"
172
208
  - !ruby/object:Gem::Version
173
- version: '1.99'
209
+ version: '3'
174
210
  - !ruby/object:Gem::Dependency
175
211
  name: rdf-spec
176
212
  requirement: !ruby/object:Gem::Requirement
177
213
  requirements:
178
- - - "~>"
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: 2.0.0.beta
217
+ - - "<"
179
218
  - !ruby/object:Gem::Version
180
- version: '1.99'
219
+ version: '3'
181
220
  type: :development
182
221
  prerelease: false
183
222
  version_requirements: !ruby/object:Gem::Requirement
184
223
  requirements:
185
- - - "~>"
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 2.0.0.beta
227
+ - - "<"
186
228
  - !ruby/object:Gem::Version
187
- version: '1.99'
229
+ version: '3'
188
230
  - !ruby/object:Gem::Dependency
189
231
  name: rdf-vocab
190
232
  requirement: !ruby/object:Gem::Requirement
191
233
  requirements:
192
- - - "~>"
234
+ - - ">="
193
235
  - !ruby/object:Gem::Version
194
- version: '0.8'
236
+ version: 2.0.0.beta
237
+ - - "<"
238
+ - !ruby/object:Gem::Version
239
+ version: '3'
195
240
  type: :development
196
241
  prerelease: false
197
242
  version_requirements: !ruby/object:Gem::Requirement
198
243
  requirements:
199
- - - "~>"
244
+ - - ">="
200
245
  - !ruby/object:Gem::Version
201
- version: '0.8'
246
+ version: 2.0.0.beta
247
+ - - "<"
248
+ - !ruby/object:Gem::Version
249
+ version: '3'
202
250
  - !ruby/object:Gem::Dependency
203
251
  name: yard
204
252
  requirement: !ruby/object:Gem::Requirement
@@ -237,7 +285,7 @@ files:
237
285
  - lib/rdf/rdfxml/writer/haml_templates.rb
238
286
  homepage: http://ruby-rdf.github.com/rdf-rdfxml
239
287
  licenses:
240
- - Public Domain
288
+ - Unlicense
241
289
  metadata: {}
242
290
  post_install_message:
243
291
  rdoc_options: []
@@ -247,16 +295,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
247
295
  requirements:
248
296
  - - ">="
249
297
  - !ruby/object:Gem::Version
250
- version: 1.9.3
298
+ version: '2.0'
251
299
  required_rubygems_version: !ruby/object:Gem::Requirement
252
300
  requirements:
253
- - - ">="
301
+ - - ">"
254
302
  - !ruby/object:Gem::Version
255
- version: '0'
303
+ version: 1.3.1
256
304
  requirements: []
257
305
  rubyforge_project: rdf-rdfxml
258
- rubygems_version: 2.7.6
306
+ rubygems_version: 2.5.1
259
307
  signing_key:
260
308
  specification_version: 4
261
309
  summary: RDF/XML reader/writer for RDF.rb.
262
310
  test_files: []
311
+ has_rdoc: false