rdf-rdfxml 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  .DS_Store
2
+ /doc
2
3
  /pkg
4
+ /.yardoc
data/History.txt CHANGED
@@ -1,7 +1,13 @@
1
+ === 0.2.1
2
+ * Update for RDF 0.2.1
3
+ * Writer bug fixes:
4
+ * RDF::Node#identifier => RDF::Node#id
5
+ * Vocabulary.new(uri) => Vocabulary(uri)
6
+
1
7
  === 0.2.0
2
8
  * Updates for RDF 0.2.0
3
9
  * Use URI#intern instead of URI#new
4
- * Change use of Graph#predicates and Graph#objects to use as enumberables
10
+ * Change use of Graph#predicates and Graph#objects to use as enumerables
5
11
 
6
12
  === 0.0.3
7
13
  * Added patches for the following:
data/README.rdoc CHANGED
@@ -23,7 +23,7 @@ Instantiate a parser and parse source, specifying type and base-URL
23
23
  end
24
24
 
25
25
  == Dependencies
26
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.1.6)
26
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.2.0)
27
27
  * [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.3.3)
28
28
 
29
29
  == TODO
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'yard'
2
3
 
3
4
  begin
4
5
  gem 'jeweler'
@@ -12,12 +13,13 @@ begin
12
13
  gemspec.email = "gregg@kellogg-assoc.com"
13
14
  gemspec.homepage = "http://github.com/gkellogg/rdf-rdfxml"
14
15
  gemspec.authors = ["Gregg Kellogg"]
15
- gemspec.add_dependency('rdf', '>= 0.2.0')
16
+ gemspec.add_dependency('rdf', '>= 0.2.1')
16
17
  gemspec.add_dependency('nokogiri', '>= 1.3.3')
17
18
  gemspec.add_development_dependency('rspec')
18
- gemspec.add_development_dependency('rdf-spec')
19
- gemspec.add_development_dependency('activesupport', '>= 2.3.0')
20
- gemspec.extra_rdoc_files = %w(README.rdoc History.txt AUTHORS)
19
+ gemspec.add_development_dependency('rdf-spec', '>= 0.2.1')
20
+ gemspec.add_development_dependency('rdf-isomorphic')
21
+ gemspec.add_development_dependency('yard')
22
+ gemspec.extra_rdoc_files = %w(README.rdoc History.txt AUTHORS CONTRIBUTORS)
21
23
  end
22
24
  Jeweler::GemcutterTasks.new
23
25
  rescue LoadError
@@ -44,6 +46,10 @@ Spec::Rake::SpecTask.new("doc:spec") do |spec|
44
46
  spec.spec_opts = ["--format", "html:doc/spec.html"]
45
47
  end
46
48
 
49
+ YARD::Rake::YardocTask.new do |t|
50
+ t.files = %w(lib/**/*.rb README.rdoc History.txt AUTHORS CONTRIBUTORS) # optional
51
+ end
52
+
47
53
  desc "Generate RDF Core Manifest.yml"
48
54
  namespace :spec do
49
55
  task :prepare do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/rdf/rdfxml.rb CHANGED
@@ -32,9 +32,5 @@ module RDF
32
32
  autoload :Writer, 'rdf/rdfxml/writer'
33
33
  autoload :VERSION, 'rdf/rdfxml/version'
34
34
  autoload :XML, 'rdf/rdfxml/vocab'
35
-
36
- # Fixme: RDF.to_s should generate this, but it doesn't
37
- RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
38
- XML_LITERAL = RDF['XMLLiteral']
39
35
  end
40
36
  end
@@ -1,66 +1,147 @@
1
- module RDF
2
- class Literal
3
- # Support for XML Literals
4
- # Is this an XMLLiteral?
5
- def xmlliteral?
6
- datatype == RDF['XMLLiteral']
1
+ # Use Nokogiri or LibXML when available, and REXML otherwise:
2
+ begin
3
+ require 'nokogiri'
4
+ rescue LoadError => e
5
+ begin
6
+ require 'libxml'
7
+ rescue LoadError => e
8
+ :rexml
9
+ end
10
+ end
11
+
12
+ module RDF; class Literal
13
+ ##
14
+ # An XML literal.
15
+ #
16
+ # @see http://www.w3.org/TR/rdf-concepts/#section-XMLLiteral
17
+ # @see http://www.w3.org/TR/rdfa-core/#s_xml_literals
18
+ # @since 0.2.1
19
+ class XML < Literal
20
+ ##
21
+ # @param [Object] value
22
+ # @option options [String] :lexical (nil)
23
+ # @option options [Hash] :namespaces (nil)
24
+ # @option options [Hash] :namespaces ({})
25
+ # @option options [Symbol] :language (nil)
26
+ # @option options [Symbol] :library (:nokogiri, :libxml, or :rexml)
27
+ def initialize(value, options = {})
28
+ options[:namespaces] ||= {}
29
+
30
+ @library = case options[:library]
31
+ when nil
32
+ case
33
+ when defined?(::Nokogiri) then :nokogiri
34
+ when defined?(::LibXML) then :libxml
35
+ else :rexml
36
+ end
37
+ when :nokogiri, :libxml, :rexml
38
+ options[:library]
39
+ else
40
+ raise ArgumentError.new("expected :rexml, :libxml or :nokogiri, but got #{options[:library].inspect}")
41
+ end
42
+
43
+ @datatype = options[:datatype] || DATATYPE
44
+ @string = options[:lexical] if options.has_key?(:lexical)
45
+ @object = parse_value(value, options)
46
+ @string = serialize_nodeset(@object)
7
47
  end
8
-
9
- def anonymous?; false; end unless respond_to?(:anonymous?)
10
-
48
+
11
49
  ##
12
- # Returns a string representation of this literal.
50
+ # Converts the literal into its canonical lexical representation.
51
+ #
52
+ # @return [Literal]
53
+ # @see http://www.w3.org/TR/xml-exc-c14n/
54
+ def canonicalize
55
+ # This is the opportunity to use exclusive canonicalization library
56
+ self
57
+ end
58
+
59
+ ##
60
+ # Returns the value as a string.
13
61
  #
14
62
  # @return [String]
15
63
  def to_s
16
- quoted = value # FIXME
17
- output = "\"#{quoted}\""
18
- output << "@#{language}" if has_language? && !has_datatype?
19
- output << "^^<#{datatype}>" if has_datatype?
20
- output
64
+ @string
21
65
  end
22
66
 
23
- # Normalize an XML Literal, by adding necessary namespaces.
24
- # This should be done as part of initialize
25
- #
26
- # namespaces is a hash of prefix => URIs
27
- def self.xmlliteral(contents, options = {})
28
- options[:namespaces] ||= {}
29
- l = new("", :datatype => RDF["XMLLiteral"])
30
-
31
- if contents.is_a?(String)
32
- ns_hash = {}
33
- options[:namespaces].each_pair do |prefix, uri|
34
- attr = prefix.to_s.empty? ? "xmlns" : "xmlns:#{prefix}"
35
- ns_hash[attr] = uri.to_s
36
- end
37
- ns_strs = []
38
- ns_hash.each_pair {|a, u| ns_strs << "#{a}=\"#{u}\""}
67
+ private
68
+
69
+ def parse_value(value, options)
70
+ ns_hash = {}
71
+ options[:namespaces].each_pair do |prefix, uri|
72
+ attr = prefix.to_s.empty? ? "xmlns" : "xmlns:#{prefix}"
73
+ ns_hash[attr] = uri.to_s
74
+ end
75
+ ns_strs = []
76
+ ns_hash.each_pair {|a, u| ns_strs << "#{a}=\"#{u}\""}
39
77
 
40
- # Add inherited namespaces to created root element so that they're inherited to sub-elements
41
- contents = Nokogiri::XML::Document.parse("<foo #{ns_strs.join(" ")}>#{contents}</foo>").root.children
78
+ case @library
79
+ when :nokogiri then parse_value_nokogiri(value, ns_strs, options[:language])
80
+ when :libxml then parse_value_libxml(value, ns_strs, options[:language])
81
+ when :rexml then parse_value_rexml(value, ns_strs, options[:language])
82
+ else value.to_s
83
+ end
84
+ end
85
+
86
+ def serialize_nodeset(object)
87
+ case @library
88
+ when :nokogiri then serialize_nodeset_nokogiri(object)
89
+ when :libxml then serialize_nodeset_libxml(object)
90
+ when :rexml then serialize_nodeset_rexml(object)
91
+ else object
42
92
  end
93
+ end
94
+
95
+ # Nokogiri implementations
96
+ if defined?(::Nokogiri)
97
+ def parse_value_nokogiri(value, ns_strs, language)
98
+ return value if value.is_a?(Nokogiri::XML::NodeSet)
99
+ # Add inherited namespaces to created root element so that they're inherited to sub-elements
100
+ elements = Nokogiri::XML::Document.parse("<foo #{ns_strs.join(" ")}>#{value.to_s}</foo>").root.children
43
101
 
44
- # Add already mapped namespaces and language
45
- l.value = contents.map do |c|
46
- if c.is_a?(Nokogiri::XML::Element)
47
- c = Nokogiri::XML.parse(c.dup.to_s).root
48
- # Gather namespaces from self and decendant nodes
49
- c.traverse do |n|
50
- ns = n.namespace
51
- next unless ns
52
- prefix = ns.prefix ? "xmlns:#{ns.prefix}" : "xmlns"
53
- c[prefix] = ns.href.to_s unless c.namespaces[prefix]
54
- end
55
-
56
- # Add lanuage
57
- if options[:language] && c["lang"].to_s.empty?
58
- c["xml:lang"] = options[:language]
102
+ elements.map do |c|
103
+ if c.is_a?(Nokogiri::XML::Element)
104
+ c = Nokogiri::XML.parse(c.dup.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS)).root
105
+ # Gather namespaces from self and decendant nodes
106
+ c.traverse do |n|
107
+ ns = n.namespace
108
+ next unless ns
109
+ prefix = ns.prefix ? "xmlns:#{ns.prefix}" : "xmlns"
110
+ c[prefix] = ns.href.to_s unless c.namespaces[prefix]
111
+ end
112
+
113
+ # Add lanuage
114
+ if language && c["lang"].to_s.empty?
115
+ c["xml:lang"] = language
116
+ end
59
117
  end
118
+ c
60
119
  end
61
- c.to_html(:save_with => Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS)
62
- end.join("")
63
- l
120
+ end
121
+
122
+ def serialize_nodeset_nokogiri(object)
123
+ object.map {|c| c.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS)}.join("")
124
+ end
125
+ end # Nokogiri
126
+
127
+ if defined?(::LibXML)
128
+ def parse_value_libxml(value, ns_strs, language)
129
+ # Fixme
130
+ end
131
+
132
+ def serialize_nodeset_libxml(object)
133
+ # Fixme
134
+ end
135
+ end # LibXML
136
+
137
+ # REXML
138
+ def parse_value_rexml(value, ns_strs, language)
139
+ # Fixme
64
140
  end
65
- end
66
- end
141
+
142
+ def serialize_nodeset_rexml(object)
143
+ # Fixme
144
+ end
145
+
146
+ end # class XML
147
+ end; end
@@ -6,7 +6,7 @@ module RDF
6
6
  props = properties(subject)
7
7
  rdf_type = (props[RDF.type.to_s] || []).map {|t| t.to_s}
8
8
 
9
- #puts "seq; #{rdf_type} #{rdf_type - [RDF_NS.Seq, RDF_NS.Bag, RDF_NS.Alt]}"
9
+ #puts "seq; #{rdf_type} #{rdf_type - [RDF.Seq, RDF.Bag, RDF.Alt]}"
10
10
  if !(rdf_type - [RDF.Seq, RDF.Bag, RDF.Alt]).empty?
11
11
  props.keys.select {|k| k.match(/#{RDF.to_s}_(\d)$/)}.
12
12
  sort_by {|i| i.sub(RDF._.to_s, "").to_i}.
@@ -15,7 +15,7 @@ module RDF
15
15
  elsif !self.query(:subject => subject, :predicate => RDF.first).empty?
16
16
  # N3-style first/rest chain
17
17
  list = []
18
- while subject != RDF_NS.nil
18
+ while subject != RDF.nil
19
19
  props = properties(subject)
20
20
  f = props[RDF.first.to_s]
21
21
  if f.to_s.empty? || f.first == RDF.nil
@@ -10,7 +10,6 @@ module RDF
10
10
  def join(*uris)
11
11
  result = @uri
12
12
  uris.each do |uri|
13
- # result.path += '/' unless result.path.match(/[\#\/]$/) || uri.to_s[0..0] == "#"
14
13
  result = result.join(uri)
15
14
  end
16
15
  self.class.new(result)
@@ -113,11 +113,11 @@ module RDF::RDFXML
113
113
  ##
114
114
  # Initializes the RDF/XML reader instance.
115
115
  #
116
- # @param [IO, File, String]:: input
117
- # @param [Hash{Symbol => Object}]:: options
118
- # <em>options[:debug]</em>:: Array to place debug messages
119
- # <em>options[:strict]</em>:: Raise Error if true, continue with lax parsing, otherwise
120
- # <em>options[:base_uri]</em>:: Base URI to use for relative URIs.
116
+ # @param [IO, File, String] input
117
+ # @option options [Array] :debug (nil) Array to place debug messages
118
+ # @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
119
+ # @option options [Boolean] :base_uri (nil) Base URI to use for relative URIs.
120
+ # @return [reader]
121
121
  # @yield [reader]
122
122
  # @yieldparam [Reader] reader
123
123
  # @raise [Error]:: Raises RDF::ReaderError if _strict_
@@ -141,7 +141,6 @@ module RDF::RDFXML
141
141
  end
142
142
  end
143
143
 
144
- # XXX Invoke the parser, and allow add_triple to make the callback?
145
144
  ##
146
145
  # Iterates the given block for each RDF statement in the input.
147
146
  #
@@ -156,7 +155,7 @@ module RDF::RDFXML
156
155
 
157
156
  add_debug(root, "base_uri: #{@base_uri || 'nil'}")
158
157
 
159
- rdf_nodes = root.xpath("//rdf:RDF", "rdf" => RDF_NS)
158
+ rdf_nodes = root.xpath("//rdf:RDF", "rdf" => RDF.to_uri.to_s)
160
159
  if rdf_nodes.length == 0
161
160
  # If none found, root element may be processed as an RDF Node
162
161
 
@@ -196,12 +195,8 @@ module RDF::RDFXML
196
195
 
197
196
  # Keep track of allocated BNodes
198
197
  def bnode(value = nil)
199
- if value
200
- @bnode_cache ||= {}
201
- @bnode_cache[value.to_s] ||= RDF::Node.new(value)
202
- else
203
- RDF::Node.new
204
- end
198
+ @bnode_cache ||= {}
199
+ @bnode_cache[value.to_s] ||= RDF::Node.new(value)
205
200
  end
206
201
 
207
202
  # Figure out the document path, if it is a Nokogiri::XML::Element or Attribute
@@ -314,7 +309,7 @@ module RDF::RDFXML
314
309
  #attrs[attr.to_s] = attr.value unless attr.to_s.match?(/^xml/)
315
310
  elsif attr.namespace.href == RDF::XML.to_s
316
311
  # No production. Lang and base elements already extracted
317
- elsif attr.namespace.href == RDF_NS
312
+ elsif attr.namespace.href == RDF.to_uri.to_s
318
313
  case attr.name
319
314
  when "ID" then id = attr.value
320
315
  when "datatype" then datatype = attr.value
@@ -377,7 +372,7 @@ module RDF::RDFXML
377
372
  end
378
373
 
379
374
  # For element e with possibly empty element content c.
380
- n = bnode
375
+ n = RDF::Node.new
381
376
  add_triple(child, subject, predicate, n)
382
377
 
383
378
  # Reification
@@ -442,7 +437,7 @@ module RDF::RDFXML
442
437
  raise RDF::ReaderError.new(warn) if @strict
443
438
  end
444
439
 
445
- object = RDF::Literal.xmlliteral(child.children, :namespaces => child_ec.uri_mappings)
440
+ object = RDF::Literal.new(child.children, :datatype => RDF.XMLLiteral, :namespaces => child_ec.uri_mappings, :language => ec.language)
446
441
  add_triple(child, subject, predicate, object)
447
442
  elsif text_nodes.length == 0 && element_nodes.length == 0
448
443
  # Production emptyPropertyElt
@@ -460,7 +455,7 @@ module RDF::RDFXML
460
455
  elsif nodeID
461
456
  resource = bnode(nodeID)
462
457
  else
463
- resource = bnode
458
+ resource = RDF::Node.new
464
459
  end
465
460
 
466
461
  # produce triples for attributes
@@ -533,7 +528,7 @@ module RDF::RDFXML
533
528
  ec.base.join(about)
534
529
  else
535
530
  add_debug(el, "parse_subject, BNode")
536
- bnode
531
+ RDF::Node.new
537
532
  end
538
533
  end
539
534
 
@@ -1,7 +1,7 @@
1
1
  module RDF::RDFXML::VERSION
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- TINY = 0
4
+ TINY = 1
5
5
  EXTRA = nil
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -10,7 +10,7 @@ module RDF::RDFXML
10
10
  # and then serialize the graph.
11
11
  #
12
12
  # @example Obtaining a RDF/XML writer class
13
- # RDF::Writer.for(:rdf) #=> RDF::TriX::Writer
13
+ # RDF::Writer.for(:rdf) #=> RDF::RDFXML::Writer
14
14
  # RDF::Writer.for("etc/test.rdf")
15
15
  # RDF::Writer.for(:file_name => "etc/test.rdf")
16
16
  # RDF::Writer.for(:file_extension => "rdf")
@@ -51,7 +51,7 @@ module RDF::RDFXML
51
51
  # base_uri:: Base URI of graph, used to shorting URI references
52
52
  # lang:: Output as root xml:lang attribute, and avoid generation _xml:lang_ where possible
53
53
  # attributes:: How to use XML attributes when serializing, one of :none, :untyped, :typed. The default is :none.
54
- # defafult_ns:: URI to use as default namespace
54
+ # default_namespace:: URI to use as default namespace
55
55
  #
56
56
  # @param [IO, File] output
57
57
  # @param [Hash{Symbol => Object}] options
@@ -119,7 +119,7 @@ module RDF::RDFXML
119
119
  # Get QNames and necessary namespaces from predicates and objects
120
120
  @graph.predicates.each {|pred| add_debug("serialize pred: #{pred.inspect}"); get_qname(pred)}
121
121
  @graph.objects.each {|obj| add_debug("serialize obj: #{obj.inspect}"); get_qname(obj)}
122
- add_namespace(:rdf, RDF_NS)
122
+ add_namespace(:rdf, RDF.to_uri)
123
123
  add_namespace(:xml, RDF::XML) if @base_uri || @lang
124
124
 
125
125
  if @default_namespace
@@ -174,7 +174,7 @@ module RDF::RDFXML
174
174
  end
175
175
  element ||= "rdf:Description"
176
176
 
177
- node = Nokogiri::XML::Element.new(element, parent_node.document)
177
+ node = Nokogiri::XML::Element.new(element.to_s, parent_node.document)
178
178
 
179
179
  if subject.is_a?(RDF::Node)
180
180
  # Only need nodeID if it's referenced elsewhere
@@ -234,7 +234,7 @@ module RDF::RDFXML
234
234
  as_attr = false
235
235
  end
236
236
  else
237
- qname = prop.qname.last
237
+ qname = prop.qname.last.to_s
238
238
  end
239
239
  end
240
240
 
@@ -264,8 +264,8 @@ module RDF::RDFXML
264
264
  add_debug " elt attr #{a}=#{av}"
265
265
  pred_node[a] = av.to_s
266
266
  end
267
- add_debug " elt #{'xmllit ' if object.is_a?(RDF::Literal) && object.xmlliteral?}content=#{args.first}" if !args.empty?
268
- if object.is_a?(RDF::Literal) && object.xmlliteral?
267
+ add_debug " elt #{'xmllit ' if object.is_a?(RDF::Literal) && object.datatype == RDF.XMLLiteral}content=#{args.first}" if !args.empty?
268
+ if object.is_a?(RDF::Literal) && object.datatype == RDF.XMLLiteral
269
269
  pred_node.add_child(Nokogiri::XML::CharacterData.new(args.first, node.document))
270
270
  elsif args.first
271
271
  pred_node.content = args.first unless args.empty?
@@ -295,7 +295,7 @@ module RDF::RDFXML
295
295
  subject(object, pred_node)
296
296
  @depth -= 1
297
297
  elsif object.is_a?(RDF::Node)
298
- pred_node["rdf:nodeID"] = object.identifier
298
+ pred_node["rdf:nodeID"] = object.id
299
299
  else
300
300
  pred_node["rdf:resource"] = relativize(object)
301
301
  end
@@ -410,7 +410,7 @@ module RDF::RDFXML
410
410
  base_uri = uri.to_s[0..-(local_name.length + 1)]
411
411
  @tmp_ns = @tmp_ns ? @tmp_ns.succ : "ns0"
412
412
  add_debug "create namespace definition for #{uri}"
413
- uri.vocab = RDF::Vocabulary.new(base_uri)
413
+ uri.vocab = RDF::Vocabulary(base_uri)
414
414
  add_namespace(@tmp_ns.to_sym, uri.vocab)
415
415
  add_debug "get_qname(tmp_ns): #{@tmp_ns}:#{local_name}"
416
416
  return "#{@tmp_ns}:#{local_name}"
@@ -419,7 +419,7 @@ module RDF::RDFXML
419
419
 
420
420
  def add_namespace(prefix, ns)
421
421
  add_debug "add_namespace: '#{prefix}', <#{ns}>"
422
- @namespaces[prefix.to_sym] = ns.to_s
422
+ @namespaces[prefix.to_s] = ns.to_s
423
423
  end
424
424
 
425
425
  def reset
@@ -470,7 +470,7 @@ module RDF::RDFXML
470
470
  [object.value, {}]
471
471
  elsif object.has_language?
472
472
  [object.value, {"xml:lang" => object.language}]
473
- elsif object.xmlliteral?
473
+ elsif object.datatype == RDF.XMLLiteral
474
474
  [object.value, {"rdf:parseType" => "Literal"}]
475
475
  else
476
476
  [object.value, {"rdf:datatype" => object.datatype.to_s}]
data/rdf-rdfxml.gemspec CHANGED
@@ -5,16 +5,17 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rdf-rdfxml}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gregg Kellogg"]
12
- s.date = %q{2010-06-17}
12
+ s.date = %q{2010-06-28}
13
13
  s.description = %q{ RDF::RDFXML is an RDF/XML reader and writer for Ruby using the RDF.rb library suite.
14
14
  }
15
15
  s.email = %q{gregg@kellogg-assoc.com}
16
16
  s.extra_rdoc_files = [
17
17
  "AUTHORS",
18
+ "CONTRIBUTORS",
18
19
  "History.txt",
19
20
  "README.rdoc"
20
21
  ]
@@ -418,7 +419,7 @@ Gem::Specification.new do |s|
418
419
  s.homepage = %q{http://github.com/gkellogg/rdf-rdfxml}
419
420
  s.rdoc_options = ["--charset=UTF-8"]
420
421
  s.require_paths = ["lib"]
421
- s.rubygems_version = %q{1.3.7}
422
+ s.rubygems_version = %q{1.3.6}
422
423
  s.summary = %q{RDF/XML reader/writer for RDF.rb.}
423
424
  s.test_files = [
424
425
  "spec/format_spec.rb",
@@ -437,25 +438,28 @@ Gem::Specification.new do |s|
437
438
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
438
439
  s.specification_version = 3
439
440
 
440
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
441
- s.add_runtime_dependency(%q<rdf>, [">= 0.2.0"])
441
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
442
+ s.add_runtime_dependency(%q<rdf>, [">= 0.2.1"])
442
443
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.3.3"])
443
444
  s.add_development_dependency(%q<rspec>, [">= 0"])
444
- s.add_development_dependency(%q<rdf-spec>, [">= 0"])
445
- s.add_development_dependency(%q<activesupport>, [">= 2.3.0"])
445
+ s.add_development_dependency(%q<rdf-spec>, [">= 0.2.1"])
446
+ s.add_development_dependency(%q<rdf-isomorphic>, [">= 0"])
447
+ s.add_development_dependency(%q<yard>, [">= 0"])
446
448
  else
447
- s.add_dependency(%q<rdf>, [">= 0.2.0"])
449
+ s.add_dependency(%q<rdf>, [">= 0.2.1"])
448
450
  s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
449
451
  s.add_dependency(%q<rspec>, [">= 0"])
450
- s.add_dependency(%q<rdf-spec>, [">= 0"])
451
- s.add_dependency(%q<activesupport>, [">= 2.3.0"])
452
+ s.add_dependency(%q<rdf-spec>, [">= 0.2.1"])
453
+ s.add_dependency(%q<rdf-isomorphic>, [">= 0"])
454
+ s.add_dependency(%q<yard>, [">= 0"])
452
455
  end
453
456
  else
454
- s.add_dependency(%q<rdf>, [">= 0.2.0"])
457
+ s.add_dependency(%q<rdf>, [">= 0.2.1"])
455
458
  s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
456
459
  s.add_dependency(%q<rspec>, [">= 0"])
457
- s.add_dependency(%q<rdf-spec>, [">= 0"])
458
- s.add_dependency(%q<activesupport>, [">= 2.3.0"])
460
+ s.add_dependency(%q<rdf-spec>, [">= 0.2.1"])
461
+ s.add_dependency(%q<rdf-isomorphic>, [">= 0"])
462
+ s.add_dependency(%q<yard>, [">= 0"])
459
463
  end
460
464
  end
461
465
 
data/spec/format_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe RDF::RDFXML::Format do
4
- context "descovery" do
4
+ context "discovery" do
5
5
  {
6
6
  "rdf" => RDF::Format.for(:rdf),
7
7
  "rdfxml" => RDF::Format.for(:rdfxml),
data/spec/literal_spec.rb CHANGED
@@ -1,86 +1,61 @@
1
+ # coding: utf-8
1
2
  require File.join(File.dirname(__FILE__), 'spec_helper')
3
+ require 'nokogiri'
2
4
 
3
5
  describe RDF::Literal do
6
+ require 'nokogiri' rescue nil
7
+
8
+ before :each do
9
+ @new = Proc.new { |*args| RDF::Literal.new(*args) }
10
+ end
11
+
4
12
  describe "XML Literal" do
5
13
  describe "with no namespace" do
6
- subject { RDF::Literal.new("foo <sup>bar</sup> baz!", :datatype => RDF["XMLLiteral"]) }
7
- it "should indicate xmlliteral?" do
8
- subject.xmlliteral?.should == true
14
+ subject { @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral) }
15
+ it "should return input" do subject.to_s.should == "foo <sup>bar</sup> baz!" end
16
+
17
+ it "should be equal if they have the same contents" do
18
+ should == @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral)
9
19
  end
10
-
11
- it "should return normalized literal" do subject.value.should == "foo <sup>bar</sup> baz!" end
12
20
  end
13
-
21
+
14
22
  describe "with a namespace" do
15
23
  subject {
16
- RDF::Literal.xmlliteral("foo <sup>bar</sup> baz!", :namespaces => {"dc" => "http://purl.org/dc/terms/"})
24
+ @new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
25
+ :namespaces => {"dc" => RDF::DC.to_s})
17
26
  }
18
-
19
- it "should return normalized literal" do subject.value.should == "foo <sup>bar</sup> baz!" end
20
-
27
+
28
+ it "should add namespaces" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\">bar</dc:sup> baz!" end
29
+
21
30
  describe "and language" do
22
31
  subject {
23
- RDF::Literal.xmlliteral("foo <sup>bar</sup> baz!", :namespaces => {"dc" => "http://purl.org/dc/terms/"}, :language => "fr")
32
+ @new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
33
+ :namespaces => {"dc" => RDF::DC.to_s},
34
+ :language => :fr)
24
35
  }
25
36
 
26
- it "should return normalized literal" do subject.value.should == "foo <sup xml:lang=\"fr\">bar</sup> baz!" end
37
+ it "should add namespaces and language" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"fr\">bar</dc:sup> baz!" end
27
38
  end
28
-
39
+
29
40
  describe "and language with an existing language embedded" do
30
41
  subject {
31
- RDF::Literal.xmlliteral("foo <sup>bar</sup><sub xml:lang=\"en\">baz</sub>", :namespaces => {}, :language => "fr")
42
+ @new.call("foo <dc:sup>bar</dc:sup><dc:sub xml:lang=\"en\">baz</dc:sub>",
43
+ :datatype => RDF.XMLLiteral,
44
+ :namespaces => {"dc" => RDF::DC.to_s},
45
+ :language => :fr)
32
46
  }
33
47
 
34
- it "should return normalized literal" do subject.value.should == "foo <sup xml:lang=\"fr\">bar</sup><sub xml:lang=\"en\">baz</sub>" end
35
- end
36
-
37
- describe "and namespaced element" do
38
- subject {
39
- root = Nokogiri::XML.parse(%(
40
- <?xml version="1.0" encoding="UTF-8"?>
41
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
42
- <html xmlns="http://www.w3.org/1999/xhtml"
43
- xmlns:dc="http://purl.org/dc/terms/"
44
- xmlns:ex="http://example.org/rdf/"
45
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
46
- xmlns:svg="http://www.w3.org/2000/svg">
47
- <head profile="http://www.w3.org/1999/xhtml/vocab http://www.w3.org/2005/10/profile">
48
- <title>Test 0100</title>
49
- </head>
50
- <body>
51
- <div about="http://www.example.org">
52
- <h2 property="ex:example" datatype="rdf:XMLLiteral"><svg:svg/></h2>
53
- </div>
54
- </body>
55
- </html>
56
- ), nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML).root
57
- content = root.css("h2").children
58
- RDF::Literal.xmlliteral(content, :namespaces => {:svg => "http://www.w3.org/2000/svg", :dc => "http://purl.org/dc/terms"})
59
- }
60
- it "should add namespace" do subject.value.should == "<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"></svg:svg>" end
61
- end
62
-
63
- describe "and existing namespace definition" do
64
- subject {
65
- RDF::Literal.xmlliteral("<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"/>", :namespaces => {"svg" => "http://www.w3.org/2000/svg"})
66
- }
67
- it "should add namespace" do subject.value.should == "<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"></svg:svg>" end
48
+ it "should add namespaces and language" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"fr\">bar</dc:sup><dc:sub xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"en\">baz</dc:sub>" end
68
49
  end
69
50
  end
70
-
51
+
71
52
  describe "with a default namespace" do
72
53
  subject {
73
- RDF::Literal.xmlliteral("foo <sup>bar</sup> baz!", :namespaces => {"" => "http://purl.org/dc/terms/"})
54
+ @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
55
+ :namespaces => {"" => RDF::DC.to_s})
74
56
  }
75
-
76
- it "should return normalized literal foo" do subject.value.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
77
- end
78
-
79
- describe "with <br/>" do
80
- subject {
81
- RDF::Literal.xmlliteral("<br/>")
82
- }
83
- it "should add namespace" do subject.value.should == "<br></br>" end
57
+
58
+ it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
84
59
  end
85
- end
86
- end
60
+ end if defined?(::Nokogiri)
61
+ end
data/spec/matchers.rb CHANGED
@@ -58,64 +58,4 @@ module Matchers
58
58
  def be_equivalent_graph(expected, info = nil)
59
59
  BeEquivalentGraph.new(expected, info)
60
60
  end
61
-
62
- class BeValidXML
63
- def initialize(info)
64
- @info = info
65
- end
66
- def matches?(actual)
67
- @actual = actual
68
- @doc = Nokogiri::XML.parse(actual)
69
- @results = @doc.validate
70
- @results.nil?
71
- rescue
72
- false
73
- end
74
- def failure_message_for_should
75
- "#{@info + "\n" unless @info.empty?}" +
76
- if @doc.nil?
77
- "did not parse"
78
- else
79
- "\n#{@results}" +
80
- "\nParsed:\n#{@doc}"
81
- end +
82
- "\nActual:\n#{@actual}"
83
- end
84
- end
85
-
86
- def be_valid_xml(info = "")
87
- BeValidXML.new(info)
88
- end
89
-
90
- class BeEquivalentXML
91
- def initialize(expected, info)
92
- @expected = expected
93
- @info = info
94
- end
95
-
96
- def matches?(actual)
97
- @actual = actual
98
-
99
- a = @actual.index("<") == 0 ? @actual : "<foo>#{@actual}</foo>"
100
- e = @expected.index("<") == 0 ? @expected : "<foo>#{@expected}</foo>"
101
- a_hash = ActiveSupport::XmlMini.parse(a)
102
- e_hash = ActiveSupport::XmlMini.parse(e)
103
- a_hash == e_hash
104
- rescue
105
- puts $!
106
- @fault = $!.message
107
- false
108
- end
109
-
110
- def failure_message_for_should
111
- "#{@info + "\n" unless @info.empty?}" +
112
- "Fault: #{@fault + "\n" if @fault}" +
113
- "Expected:#{@expected}\n" +
114
- "Actual:#{@actual}"
115
- end
116
- end
117
-
118
- def be_equivalent_xml(expected, info = "")
119
- BeEquivalentXML.new(expected, info)
120
- end
121
61
  end
data/spec/rdf_helper.rb CHANGED
@@ -119,9 +119,7 @@ module RdfHelper
119
119
  @negative_entailment_tests = []
120
120
 
121
121
  unless File.file?(File.join(test_dir, test.sub("rdf", "yml")))
122
- puts "parse #{File.join(test_dir, test)} @#{Time.now}"
123
122
  graph = RDF::Graph.load(File.join(test_dir, test), :base_uri => test_uri)
124
- puts "parsed #{graph.size} statements @#{Time.now}"
125
123
  uri_base = Addressable::URI.join(test_uri, ".").to_s
126
124
 
127
125
  # One of:
@@ -140,18 +138,16 @@ module RdfHelper
140
138
  self.from_yaml(File.join(test_dir, test.sub("rdf", "yml")))
141
139
  end
142
140
 
143
- puts "identified #{@test_cases.size} test cases @#{Time.now}"
144
-
145
- @test_cases.each do |tc|
146
- next if tc.status && tc.status != "APPROVED"
147
- case tc.rdf_type
148
- when "PositiveParserTest" then @positive_parser_tests << tc
149
- when "NegativeParserTest" then @negative_parser_tests << tc
150
- when "PositiveEntailmentTest" then @positive_entailment_tests << tc
151
- when "NegativeEntailmentTest" then @negative_entailment_tests << tc
152
- else puts "Unknown test type: #{tc.rdf_type}"
153
- end
154
- end
141
+ @test_cases.each do |tc|
142
+ next if tc.status && tc.status != "APPROVED"
143
+ case tc.rdf_type
144
+ when "PositiveParserTest" then @positive_parser_tests << tc
145
+ when "NegativeParserTest" then @negative_parser_tests << tc
146
+ when "PositiveEntailmentTest" then @positive_entailment_tests << tc
147
+ when "NegativeEntailmentTest" then @negative_entailment_tests << tc
148
+ else puts "Unknown test type: #{tc.rdf_type}"
149
+ end
150
+ end
155
151
  end
156
152
  def self.test_cases(test_uri = nil, test_dir = nil); parse_test_cases(test_uri, test_dir); @test_cases; end
157
153
  def self.positive_parser_tests(test_uri = nil, test_dir = nil); parse_test_cases(test_uri, test_dir); @positive_parser_tests; end
data/spec/reader_spec.rb CHANGED
@@ -329,7 +329,7 @@ EOF
329
329
  end
330
330
 
331
331
  def self.negative_tests
332
- [] #RdfHelper::TestCase.negative_parser_tests(RDFCORE_TEST, RDFCORE_DIR) rescue []
332
+ RdfHelper::TestCase.negative_parser_tests(RDFCORE_TEST, RDFCORE_DIR) rescue []
333
333
  end
334
334
 
335
335
  it "should parse testcase" do
@@ -387,7 +387,10 @@ EOF
387
387
  t.run_test do |rdf_string|
388
388
  t.debug = []
389
389
  g = RDF::Graph.new
390
- RDF::RDFXML::Reader.new(rdf_string, :base_uri => t.about, :strict => true, :debug => t.debug).each do |statement|
390
+ RDF::RDFXML::Reader.new(rdf_string,
391
+ :base_uri => t.about,
392
+ :strict => true,
393
+ :debug => t.debug).each do |statement|
391
394
  g << statement
392
395
  end
393
396
  g
@@ -404,8 +407,13 @@ EOF
404
407
  specify "test #{t.name}: " + (t.description || t.inputDocument) do
405
408
  t.run_test do |rdf_string, parser|
406
409
  lambda do
407
- parser.parse(rdf_string, :base_uri => t.about, :strict => true, :debug => [])
408
- parser.graph.should be_empty
410
+ g = RDF::Graph.new
411
+ RDF::RDFXML::Reader.new(rdf_string,
412
+ :base_uri => t.about,
413
+ :strict => true).each do |statement|
414
+ g << statement
415
+ end
416
+ g.should be_empty
409
417
  end.should raise_error(RDF::ReaderError)
410
418
  end
411
419
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ $:.unshift File.dirname(__FILE__)
4
4
  require 'rubygems'
5
5
  require 'spec'
6
6
  require 'matchers'
7
+ require 'bigdecimal' # XXX Remove Me
7
8
  require 'rdf/rdfxml'
8
9
  require 'rdf/ntriples'
9
10
  require 'rdf/spec'
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-rdfxml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 0
10
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Gregg Kellogg
@@ -15,34 +14,30 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-06-17 00:00:00 -07:00
17
+ date: 2010-06-28 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rdf
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 23
30
27
  segments:
31
28
  - 0
32
29
  - 2
33
- - 0
34
- version: 0.2.0
30
+ - 1
31
+ version: 0.2.1
35
32
  type: :runtime
36
33
  version_requirements: *id001
37
34
  - !ruby/object:Gem::Dependency
38
35
  name: nokogiri
39
36
  prerelease: false
40
37
  requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
39
  - - ">="
44
40
  - !ruby/object:Gem::Version
45
- hash: 29
46
41
  segments:
47
42
  - 1
48
43
  - 3
@@ -54,11 +49,9 @@ dependencies:
54
49
  name: rspec
55
50
  prerelease: false
56
51
  requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
53
  - - ">="
60
54
  - !ruby/object:Gem::Version
61
- hash: 3
62
55
  segments:
63
56
  - 0
64
57
  version: "0"
@@ -68,32 +61,40 @@ dependencies:
68
61
  name: rdf-spec
69
62
  prerelease: false
70
63
  requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
64
  requirements:
73
65
  - - ">="
74
66
  - !ruby/object:Gem::Version
75
- hash: 3
76
67
  segments:
77
68
  - 0
78
- version: "0"
69
+ - 2
70
+ - 1
71
+ version: 0.2.1
79
72
  type: :development
80
73
  version_requirements: *id004
81
74
  - !ruby/object:Gem::Dependency
82
- name: activesupport
75
+ name: rdf-isomorphic
83
76
  prerelease: false
84
77
  requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
78
  requirements:
87
79
  - - ">="
88
80
  - !ruby/object:Gem::Version
89
- hash: 3
90
81
  segments:
91
- - 2
92
- - 3
93
82
  - 0
94
- version: 2.3.0
83
+ version: "0"
95
84
  type: :development
96
85
  version_requirements: *id005
86
+ - !ruby/object:Gem::Dependency
87
+ name: yard
88
+ prerelease: false
89
+ requirement: &id006 !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ type: :development
97
+ version_requirements: *id006
97
98
  description: " RDF::RDFXML is an RDF/XML reader and writer for Ruby using the RDF.rb library suite.\n"
98
99
  email: gregg@kellogg-assoc.com
99
100
  executables: []
@@ -102,6 +103,7 @@ extensions: []
102
103
 
103
104
  extra_rdoc_files:
104
105
  - AUTHORS
106
+ - CONTRIBUTORS
105
107
  - History.txt
106
108
  - README.rdoc
107
109
  files:
@@ -510,27 +512,23 @@ rdoc_options:
510
512
  require_paths:
511
513
  - lib
512
514
  required_ruby_version: !ruby/object:Gem::Requirement
513
- none: false
514
515
  requirements:
515
516
  - - ">="
516
517
  - !ruby/object:Gem::Version
517
- hash: 3
518
518
  segments:
519
519
  - 0
520
520
  version: "0"
521
521
  required_rubygems_version: !ruby/object:Gem::Requirement
522
- none: false
523
522
  requirements:
524
523
  - - ">="
525
524
  - !ruby/object:Gem::Version
526
- hash: 3
527
525
  segments:
528
526
  - 0
529
527
  version: "0"
530
528
  requirements: []
531
529
 
532
530
  rubyforge_project:
533
- rubygems_version: 1.3.7
531
+ rubygems_version: 1.3.6
534
532
  signing_key:
535
533
  specification_version: 3
536
534
  summary: RDF/XML reader/writer for RDF.rb.