rdf-n3 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/VERSION +1 -1
- data/lib/rdf/n3.rb +1 -1
- data/lib/rdf/n3/patches/literal_normalization.rb +19 -8
- data/lib/rdf/n3/patches/qname_hacks.rb +1 -1
- data/lib/rdf/n3/patches/seq.rb +2 -2
- data/lib/rdf/n3/patches/uri_hacks.rb +10 -0
- data/lib/rdf/n3/reader.rb +29 -30
- data/lib/rdf/n3/version.rb +1 -1
- data/lib/rdf/n3/writer.rb +4 -2
- data/rdf-n3.gemspec +5 -4
- data/script/console +3 -1
- data/script/parse +1 -1
- data/script/tc +53 -0
- data/spec/cwm_spec.rb +1 -0
- data/spec/format_spec.rb +1 -0
- data/spec/literal_spec.rb +187 -3
- data/spec/matchers.rb +39 -10
- data/spec/n3reader_spec.rb +74 -47
- data/spec/spec_helper.rb +23 -0
- data/spec/swap_spec.rb +7 -0
- data/spec/turtle_spec.rb +1 -0
- data/spec/writer_spec.rb +12 -2
- metadata +24 -4
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 0.2.2
|
2
|
+
* Ruby 1.9.2 compatibility
|
3
|
+
* Added script/tc to run test cases
|
4
|
+
* Fixed RDF.to_s != RDF.to_uri.to_s in writer, it worke for every other vocabulary
|
5
|
+
* Handle XMLLiteral when value is a Nokogiri node set.
|
6
|
+
* Simplify process_uri by not having a special case for ^# type URIs.
|
7
|
+
* Unescape values when creating URIs.
|
8
|
+
* URI normalization isn't required for N3, so removed.
|
9
|
+
* Added Reader#rewind and #close as stubs because document is parsed on initialize and input is closed.
|
10
|
+
|
1
11
|
=== 0.2.1
|
2
12
|
* Compatible with RDF.rb 0.2.1
|
3
13
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/rdf/n3.rb
CHANGED
@@ -6,7 +6,7 @@ module RDF
|
|
6
6
|
# **`RDF::N3`** is an Notation-3 plugin for RDF.rb.
|
7
7
|
#
|
8
8
|
# @example Requiring the `RDF::N3` module
|
9
|
-
# require 'rdf/
|
9
|
+
# require 'rdf/n3'
|
10
10
|
#
|
11
11
|
# @example Parsing RDF statements from an N3 file
|
12
12
|
# RDF::N3::Reader.open("etc/foaf.n3") do |reader|
|
@@ -20,8 +20,7 @@ module RDF; class Literal
|
|
20
20
|
##
|
21
21
|
# @param [Object] value
|
22
22
|
# @option options [String] :lexical (nil)
|
23
|
-
# @option options [Hash] :namespaces (
|
24
|
-
# @option options [Hash] :namespaces ({})
|
23
|
+
# @option options [Hash] :namespaces ({}) Use :__default__ or "" to declare default namespace
|
25
24
|
# @option options [Symbol] :language (nil)
|
26
25
|
# @option options [Symbol] :library (:nokogiri, :libxml, or :rexml)
|
27
26
|
def initialize(value, options = {})
|
@@ -69,7 +68,8 @@ module RDF; class Literal
|
|
69
68
|
def parse_value(value, options)
|
70
69
|
ns_hash = {}
|
71
70
|
options[:namespaces].each_pair do |prefix, uri|
|
72
|
-
|
71
|
+
prefix = prefix == :__default__ ? "" : prefix.to_s
|
72
|
+
attr = prefix.empty? ? "xmlns" : "xmlns:#{prefix}"
|
73
73
|
ns_hash[attr] = uri.to_s
|
74
74
|
end
|
75
75
|
ns_strs = []
|
@@ -94,10 +94,18 @@ module RDF; class Literal
|
|
94
94
|
|
95
95
|
# Nokogiri implementations
|
96
96
|
if defined?(::Nokogiri)
|
97
|
+
# A somewhat half-hearted attempt at C14N.
|
98
|
+
# Main problem is that it promotes all namespaces to top element, instead of demoting them
|
99
|
+
# to the required element, and does not properly order either namespaces or attributes.
|
100
|
+
#
|
101
|
+
# An open-issue in Nokogiri is to add support for C14N from the underlying libxml2 libraries.
|
97
102
|
def parse_value_nokogiri(value, ns_strs, language)
|
98
|
-
|
99
|
-
|
100
|
-
|
103
|
+
elements = if value.is_a?(Nokogiri::XML::NodeSet)
|
104
|
+
value
|
105
|
+
else
|
106
|
+
# Add inherited namespaces to created root element so that they're inherited to sub-elements
|
107
|
+
Nokogiri::XML::Document.parse("<foo #{ns_strs.join(" ")}>#{value.to_s}</foo>").root.children
|
108
|
+
end
|
101
109
|
|
102
110
|
elements.map do |c|
|
103
111
|
if c.is_a?(Nokogiri::XML::Element)
|
@@ -110,9 +118,9 @@ module RDF; class Literal
|
|
110
118
|
c[prefix] = ns.href.to_s unless c.namespaces[prefix]
|
111
119
|
end
|
112
120
|
|
113
|
-
# Add
|
121
|
+
# Add language
|
114
122
|
if language && c["lang"].to_s.empty?
|
115
|
-
c["xml:lang"] = language
|
123
|
+
c["xml:lang"] = language.to_s
|
116
124
|
end
|
117
125
|
end
|
118
126
|
c
|
@@ -125,6 +133,7 @@ module RDF; class Literal
|
|
125
133
|
end # Nokogiri
|
126
134
|
|
127
135
|
if defined?(::LibXML)
|
136
|
+
# This should use Document#canonicalize if as and when it is available in libxml-ruby
|
128
137
|
def parse_value_libxml(value, ns_strs, language)
|
129
138
|
# Fixme
|
130
139
|
end
|
@@ -135,6 +144,8 @@ module RDF; class Literal
|
|
135
144
|
end # LibXML
|
136
145
|
|
137
146
|
# REXML
|
147
|
+
# This could make use of the XMLCanonicalizer gem (http://rubygems.org/gems/XMLCanonicalizer)
|
148
|
+
# But, it hasn't been touched since 2007 and relies on log4r.
|
138
149
|
def parse_value_rexml(value, ns_strs, language)
|
139
150
|
# Fixme
|
140
151
|
end
|
@@ -21,7 +21,7 @@ module RDF
|
|
21
21
|
raise "Vocab #{vocab.inspect} is not a Vocabulary!" if vocab.is_a?(Array)
|
22
22
|
vocab_name = vocab.__name__.to_s.split('::').last.downcase
|
23
23
|
local_name = to_s[vocab.to_uri.to_s.size..-1]
|
24
|
-
vocab_name && local_name && [vocab_name.to_sym, local_name.to_sym]
|
24
|
+
vocab_name && local_name && [vocab_name.to_sym, local_name.empty? ? nil : local_name.to_sym]
|
25
25
|
end
|
26
26
|
end
|
27
27
|
#end
|
data/lib/rdf/n3/patches/seq.rb
CHANGED
@@ -8,7 +8,7 @@ module RDF
|
|
8
8
|
|
9
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
|
-
props.keys.select {|k| k.match(/#{RDF.
|
11
|
+
props.keys.select {|k| k.match(/#{RDF._}(\d)$/)}.
|
12
12
|
sort_by {|i| i.sub(RDF._.to_s, "").to_i}.
|
13
13
|
map {|key| props[key]}.
|
14
14
|
flatten
|
@@ -31,4 +31,4 @@ module RDF
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
@@ -15,5 +15,15 @@ module RDF
|
|
15
15
|
end
|
16
16
|
self.class.new(result)
|
17
17
|
end
|
18
|
+
|
19
|
+
# From http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#section-Graph-URIref
|
20
|
+
#
|
21
|
+
# A URI Reference within an RDF graph is a Unicode string that:
|
22
|
+
# * does not contain any control characters ( #x00 - #x1F, #x7F-#x9F)
|
23
|
+
# * and would produce a valid URI character sequence (per RFC2396 [URI], sections 2.1) representing an absolute URI with optional fragment identifier when subjected to the encoding described below.
|
24
|
+
#
|
25
|
+
# The encoding consists of:
|
26
|
+
# 1. encoding the Unicode string as UTF-8 [RFC-2279], giving a sequence of octet values.
|
27
|
+
# 2. %-escaping octets that do not correspond to permitted US-ASCII characters.
|
18
28
|
end
|
19
29
|
end
|
data/lib/rdf/n3/reader.rb
CHANGED
@@ -41,7 +41,7 @@ module RDF::N3
|
|
41
41
|
@debug = options[:debug]
|
42
42
|
@strict = options[:strict]
|
43
43
|
@uri_mappings = {}
|
44
|
-
@uri = uri(options[:base_uri], nil,
|
44
|
+
@uri = uri(options[:base_uri], nil, false)
|
45
45
|
|
46
46
|
@doc = input.respond_to?(:read) ? (input.rewind; input.read) : input
|
47
47
|
@default_ns = uri("#{options[:base_uri]}#", nil, false) if @uri
|
@@ -51,6 +51,12 @@ module RDF::N3
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
# No need to rewind, as parsing is done in initialize
|
55
|
+
def rewind; end
|
56
|
+
|
57
|
+
# Document closed when read in initialize
|
58
|
+
def close; end
|
59
|
+
|
54
60
|
##
|
55
61
|
# Iterates the given block for each RDF statement in the input.
|
56
62
|
#
|
@@ -120,8 +126,6 @@ module RDF::N3
|
|
120
126
|
uri = uri.to_s
|
121
127
|
if uri == "#"
|
122
128
|
uri = @default_ns
|
123
|
-
elsif !uri.match(/[\/\#]$/)
|
124
|
-
uri += "#"
|
125
129
|
end
|
126
130
|
add_debug("namesspace", "'#{prefix}' <#{uri}>")
|
127
131
|
@uri_mappings[prefix] = RDF::URI.intern(uri)
|
@@ -157,16 +161,23 @@ module RDF::N3
|
|
157
161
|
if s.respond_to?(:nprefix)
|
158
162
|
add_debug(*s.info("process_statements(namespace)"))
|
159
163
|
keyword_check("prefix") if s.text_value.index("prefix") == 0
|
160
|
-
uri = process_uri(s.explicituri.uri
|
164
|
+
uri = process_uri(s.explicituri.uri)
|
161
165
|
namespace(uri, s.nprefix.text_value)
|
162
166
|
elsif s.respond_to?(:base)
|
163
167
|
add_debug(*s.info("process_statements(base)"))
|
164
168
|
keyword_check("base") if s.text_value.index("base") == 0
|
165
169
|
# Base, set or update document URI
|
166
170
|
uri = s.explicituri.uri.text_value
|
167
|
-
@default_ns = process_uri(uri, false) # Don't normalize
|
168
|
-
add_debug("@default_ns", "#{@default_ns.inspect}")
|
169
171
|
@uri = process_uri(uri)
|
172
|
+
|
173
|
+
# The empty prefix "" is by default , bound to "#" -- the local namespace of the file.
|
174
|
+
# The parser behaves as though there were a
|
175
|
+
# @prefix : <#>.
|
176
|
+
# just before the file.
|
177
|
+
# This means that <#foo> can be written :foo and using @keywords one can reduce that to foo.
|
178
|
+
|
179
|
+
@default_ns = uri.match(/[\/\#]$/) ? @uri : process_uri("#{uri}#")
|
180
|
+
add_debug("@default_ns", "#{@default_ns.inspect}")
|
170
181
|
add_debug("@base", "#{@uri}")
|
171
182
|
@uri
|
172
183
|
elsif s.respond_to?(:keywords)
|
@@ -276,7 +287,7 @@ module RDF::N3
|
|
276
287
|
if @keywords && !@keywords.include?(barename)
|
277
288
|
build_uri(barename)
|
278
289
|
else
|
279
|
-
RDF::Literal.new(barename.delete("@"), :datatype => RDF::XSD.boolean)
|
290
|
+
RDF::Literal.new(barename.delete("@"), :datatype => RDF::XSD.boolean, :validate => @strict, :canonicalize => true)
|
280
291
|
end
|
281
292
|
elsif expression.respond_to?(:barename)
|
282
293
|
add_debug(*expression.info("process_expression(barename)"))
|
@@ -341,14 +352,9 @@ module RDF::N3
|
|
341
352
|
end
|
342
353
|
end
|
343
354
|
|
344
|
-
def process_uri(uri
|
355
|
+
def process_uri(uri)
|
345
356
|
uri = uri.text_value if uri.respond_to?(:text_value)
|
346
|
-
|
347
|
-
uri(@uri, RDF::NTriples::Writer.escape(uri), false) # This is probably bogus, but allows tests to pass
|
348
|
-
else
|
349
|
-
uri = RDF::NTriples::Writer.escape(uri) unless normalize # Addressable does it's own escaping when normalizing
|
350
|
-
uri(@uri, uri, normalize)
|
351
|
-
end
|
357
|
+
uri(@uri, RDF::NTriples.unescape(uri))
|
352
358
|
end
|
353
359
|
|
354
360
|
def process_properties(properties)
|
@@ -392,15 +398,13 @@ module RDF::N3
|
|
392
398
|
|
393
399
|
# Evaluate text_value to remove redundant escapes
|
394
400
|
#puts string.elements[1].text_value.dump
|
395
|
-
|
396
|
-
raise RDF::ReaderError, %(Typed literal has an invalid lexical value: #{encoding.to_s} "#{lit.value}") if @strict && !lit.valid?
|
397
|
-
lit
|
401
|
+
RDF::Literal.new(RDF::NTriples.unescape(string.elements[1].text_value), :language => language, :validate => @strict, :datatype => encoding, :canonicalize => true)
|
398
402
|
end
|
399
403
|
|
400
404
|
def process_numeric_literal(object)
|
401
405
|
add_debug(*object.info("process_numeric_literal"))
|
402
406
|
|
403
|
-
RDF::Literal.new(RDF::NTriples
|
407
|
+
RDF::Literal.new(RDF::NTriples.unescape(object.text_value), :datatype => RDF::XSD[object.numericliteral], :validate => @strict, :canonicalize => true)
|
404
408
|
end
|
405
409
|
|
406
410
|
def build_uri(expression)
|
@@ -408,7 +412,7 @@ module RDF::N3
|
|
408
412
|
localname = expression.localname.text_value if expression.respond_to?(:localname)
|
409
413
|
localname ||= (expression.respond_to?(:text_value) ? expression.text_value : expression).to_s.sub(/^:/, "")
|
410
414
|
localname = nil if localname.empty? # In N3/Turtle "_:" is not named
|
411
|
-
escaped_localname = RDF::NTriples
|
415
|
+
escaped_localname = RDF::NTriples.escape(localname.to_s)
|
412
416
|
|
413
417
|
if expression.respond_to?(:info)
|
414
418
|
add_debug(*expression.info("build_uri(#{prefix.inspect}, #{localname.inspect})"))
|
@@ -418,7 +422,7 @@ module RDF::N3
|
|
418
422
|
|
419
423
|
uri = if @uri_mappings[prefix]
|
420
424
|
add_debug(*expression.info("build_uri: (ns): #{@uri_mappings[prefix]}, #{escaped_localname}")) if expression.respond_to?(:info)
|
421
|
-
ns(prefix, RDF::NTriples
|
425
|
+
ns(prefix, RDF::NTriples.escape(localname.to_s))
|
422
426
|
elsif prefix == '_'
|
423
427
|
add_debug(*expression.info("build_uri: (bnode)")) if expression.respond_to?(:info)
|
424
428
|
bnode(localname)
|
@@ -446,22 +450,17 @@ module RDF::N3
|
|
446
450
|
end
|
447
451
|
end
|
448
452
|
|
449
|
-
# Create
|
450
|
-
def uri(value, append, normalize =
|
451
|
-
value =
|
452
|
-
value = case value
|
453
|
-
when Addressable::URI then value
|
454
|
-
else Addressable::URI.parse(value.to_s)
|
455
|
-
end
|
456
|
-
|
453
|
+
# Create URIs
|
454
|
+
def uri(value, append, normalize = false)
|
455
|
+
value = RDF::URI.intern(value)
|
457
456
|
value = value.join(append) if append
|
458
|
-
value
|
459
|
-
RDF::URI.intern(value)
|
457
|
+
value
|
460
458
|
end
|
461
459
|
|
462
460
|
def ns(prefix, suffix)
|
463
461
|
prefix = prefix.nil? ? @default_ns.to_s : @uri_mappings[prefix].to_s
|
464
462
|
suffix = suffix.to_s.sub(/^\#/, "") if prefix.index("#")
|
463
|
+
add_debug("ns", "prefix: '#{prefix}', suffix: '#{suffix}'")
|
465
464
|
RDF::URI.intern(prefix + suffix)
|
466
465
|
end
|
467
466
|
end
|
data/lib/rdf/n3/version.rb
CHANGED
data/lib/rdf/n3/writer.rb
CHANGED
@@ -379,8 +379,9 @@ module RDF::N3
|
|
379
379
|
|
380
380
|
def add_namespace(prefix, ns)
|
381
381
|
return if @namespaces.has_key?(prefix.to_s)
|
382
|
-
|
383
|
-
|
382
|
+
uri = (ns.respond_to?(:to_uri) ? ns.to_uri : ns).to_s
|
383
|
+
add_debug "add_namespace: '#{prefix}', <#{uri}>"
|
384
|
+
@namespaces[prefix.to_s] = uri
|
384
385
|
end
|
385
386
|
|
386
387
|
def reset
|
@@ -428,6 +429,7 @@ module RDF::N3
|
|
428
429
|
#
|
429
430
|
# @param [String] message::
|
430
431
|
def add_debug(message)
|
432
|
+
STDERR.puts message if $DEBUG
|
431
433
|
@debug << message if @debug.is_a?(Array)
|
432
434
|
end
|
433
435
|
|
data/rdf-n3.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rdf-n3}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
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-
|
12
|
+
s.date = %q{2010-08-11}
|
13
13
|
s.description = %q{ RDF::N3 is an Notation-3 (n3-rdf) parser for Ruby using the RDF.rb library suite.
|
14
14
|
}
|
15
15
|
s.email = %q{gregg@kellogg-assoc.com}
|
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
"rdf-n3.gemspec",
|
45
45
|
"script/console",
|
46
46
|
"script/parse",
|
47
|
+
"script/tc",
|
47
48
|
"spec/cwm_spec.rb",
|
48
49
|
"spec/format_spec.rb",
|
49
50
|
"spec/literal_spec.rb",
|
@@ -608,7 +609,7 @@ Gem::Specification.new do |s|
|
|
608
609
|
s.homepage = %q{http://github.com/gkellogg/rdf-rdfa}
|
609
610
|
s.rdoc_options = ["--charset=UTF-8"]
|
610
611
|
s.require_paths = ["lib"]
|
611
|
-
s.rubygems_version = %q{1.3.
|
612
|
+
s.rubygems_version = %q{1.3.7}
|
612
613
|
s.summary = %q{Notation-3 (n3-rdf) and Turtle reader/writer for RDF.rb.}
|
613
614
|
s.test_files = [
|
614
615
|
"spec/cwm_spec.rb",
|
@@ -627,7 +628,7 @@ Gem::Specification.new do |s|
|
|
627
628
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
628
629
|
s.specification_version = 3
|
629
630
|
|
630
|
-
if Gem::Version.new(Gem::
|
631
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
631
632
|
s.add_runtime_dependency(%q<rdf>, [">= 0.2.1"])
|
632
633
|
s.add_runtime_dependency(%q<treetop>, [">= 1.4.0"])
|
633
634
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
data/script/console
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
4
|
|
5
5
|
libs = " -r irb/completion"
|
6
|
-
|
6
|
+
RDF = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "rdf", "lib"))
|
7
|
+
libs << " -I #{RDF}" if File.directory?(RDF)
|
8
|
+
libs << " -r #{File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "rdf", "n3.rb")}"
|
7
9
|
puts "Loading rdf-n3 gem"
|
8
10
|
exec "#{irb} #{libs} --simple-prompt"
|
data/script/parse
CHANGED
data/script/tc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby -s
|
2
|
+
require 'rubygems'
|
3
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
|
4
|
+
require 'rdf/n3'
|
5
|
+
require 'spec/rdf_helper'
|
6
|
+
require 'getoptlong'
|
7
|
+
|
8
|
+
def run_tc(tc)
|
9
|
+
puts "run #{tc.name}"
|
10
|
+
puts RDF::Writer.for($format.to_sym).buffer { |writer|
|
11
|
+
RDF::N3::Reader.new(tc.input, :base_uri => tc.about, :strict => $strict).each do |statement|
|
12
|
+
writer << statement
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
$verbose = false
|
18
|
+
$format = :ntriples
|
19
|
+
$strict = false
|
20
|
+
suite = "turtle"
|
21
|
+
opts = GetoptLong.new(
|
22
|
+
["--debug", GetoptLong::NO_ARGUMENT],
|
23
|
+
["--verbose", GetoptLong::NO_ARGUMENT],
|
24
|
+
["--quiet", GetoptLong::NO_ARGUMENT],
|
25
|
+
["--suite", GetoptLong::OPTIONAL_ARGUMENT],
|
26
|
+
["--strict", GetoptLong::NO_ARGUMENT],
|
27
|
+
["--format", GetoptLong::REQUIRED_ARGUMENT]
|
28
|
+
)
|
29
|
+
opts.each do |opt, arg|
|
30
|
+
case opt
|
31
|
+
when '--verbose' then $verbose = true
|
32
|
+
when '--quiet' then $quiet = true
|
33
|
+
when '--debug' then $DEBUG = true
|
34
|
+
when '--format' then $format = arg
|
35
|
+
when '--suite' then suite = arg
|
36
|
+
when '--strict' then $strict = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Test URI and directory for different suites
|
41
|
+
TEST_PARAMS = {
|
42
|
+
"rdfxml" => [RDFCORE_TEST, RDFCORE_DIR],
|
43
|
+
"cwm" => [CWM_TEST, SWAP_DIR],
|
44
|
+
"swap" => [SWAP_TEST, SWAP_DIR],
|
45
|
+
"turtle" => [TURTLE_TEST, TURTLE_DIR],
|
46
|
+
"turtlebad" => [TURTLE_BAD_TEST, TURTLE_DIR],
|
47
|
+
}
|
48
|
+
test_cases = RdfHelper::TestCase.test_cases(*TEST_PARAMS[suite])
|
49
|
+
|
50
|
+
test_cases = test_cases.detect do |tc|
|
51
|
+
next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)}
|
52
|
+
run_tc(tc)
|
53
|
+
end
|
data/spec/cwm_spec.rb
CHANGED
data/spec/format_spec.rb
CHANGED
data/spec/literal_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
$:.unshift "."
|
2
3
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
4
|
require 'nokogiri'
|
4
5
|
|
@@ -22,26 +23,64 @@ describe RDF::Literal do
|
|
22
23
|
describe "with a namespace" do
|
23
24
|
subject {
|
24
25
|
@new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
|
25
|
-
:namespaces => {
|
26
|
+
:namespaces => {:dc => RDF::DC.to_s})
|
26
27
|
}
|
27
28
|
|
28
29
|
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
30
|
|
31
|
+
describe "as string prefix" do
|
32
|
+
subject {
|
33
|
+
@new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
|
34
|
+
:namespaces => {"dc" => RDF::DC.to_s})
|
35
|
+
}
|
36
|
+
|
37
|
+
it "should add namespaces" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\">bar</dc:sup> baz!" end
|
38
|
+
end
|
39
|
+
|
30
40
|
describe "and language" do
|
31
41
|
subject {
|
32
42
|
@new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
|
33
|
-
:namespaces => {
|
43
|
+
:namespaces => {:dc => RDF::DC.to_s},
|
34
44
|
:language => :fr)
|
35
45
|
}
|
36
46
|
|
37
47
|
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
|
38
48
|
end
|
39
49
|
|
50
|
+
describe "and node set" do
|
51
|
+
subject {
|
52
|
+
root = Nokogiri::XML.parse(%(<?xml version="1.0" encoding="UTF-8"?>
|
53
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
54
|
+
<html xmlns="http://www.w3.org/1999/xhtml"
|
55
|
+
xmlns:dc="http://purl.org/dc/terms/"
|
56
|
+
xmlns:ex="http://example.org/rdf/"
|
57
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
58
|
+
xmlns:svg="http://www.w3.org/2000/svg">
|
59
|
+
<head profile="http://www.w3.org/1999/xhtml/vocab http://www.w3.org/2005/10/profile">
|
60
|
+
<title>Test 0100</title>
|
61
|
+
</head>
|
62
|
+
<body>
|
63
|
+
<div about="http://www.example.org">
|
64
|
+
<h2 property="ex:example" datatype="rdf:XMLLiteral"><svg:svg/></h2>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
68
|
+
), nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML).root
|
69
|
+
content = root.css("h2").children
|
70
|
+
@new.call(content, :datatype => RDF.XMLLiteral,
|
71
|
+
:namespaces => {
|
72
|
+
:svg => "http://www.w3.org/2000/svg",
|
73
|
+
:dc => "http://purl.org/dc/terms/",
|
74
|
+
})
|
75
|
+
}
|
76
|
+
it "should add namespace" do subject.to_s.should == "<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"></svg:svg>" end
|
77
|
+
end
|
78
|
+
|
40
79
|
describe "and language with an existing language embedded" do
|
41
80
|
subject {
|
42
81
|
@new.call("foo <dc:sup>bar</dc:sup><dc:sub xml:lang=\"en\">baz</dc:sub>",
|
43
82
|
:datatype => RDF.XMLLiteral,
|
44
|
-
:namespaces => {
|
83
|
+
:namespaces => {:dc => RDF::DC.to_s},
|
45
84
|
:language => :fr)
|
46
85
|
}
|
47
86
|
|
@@ -50,6 +89,15 @@ describe RDF::Literal do
|
|
50
89
|
end
|
51
90
|
|
52
91
|
describe "with a default namespace" do
|
92
|
+
subject {
|
93
|
+
@new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
|
94
|
+
:namespaces => {:__default__ => RDF::DC.to_s})
|
95
|
+
}
|
96
|
+
|
97
|
+
it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "with a default namespace (as empty string)" do
|
53
101
|
subject {
|
54
102
|
@new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
|
55
103
|
:namespaces => {"" => RDF::DC.to_s})
|
@@ -57,5 +105,141 @@ describe RDF::Literal do
|
|
57
105
|
|
58
106
|
it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
|
59
107
|
end
|
108
|
+
|
109
|
+
context "rdfcore tests" do
|
110
|
+
context "rdfms-xml-literal-namespaces" do
|
111
|
+
it "should reproduce test001" do
|
112
|
+
l = @new.call("
|
113
|
+
<html:h1>
|
114
|
+
<b>John</b>
|
115
|
+
</html:h1>
|
116
|
+
",
|
117
|
+
:datatype => RDF.XMLLiteral,
|
118
|
+
:namespaces => {
|
119
|
+
"" => "http://www.w3.org/1999/xhtml",
|
120
|
+
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
121
|
+
"html" => "http://NoHTML.example.org",
|
122
|
+
"my" => "http://my.example.org/",
|
123
|
+
})
|
124
|
+
|
125
|
+
pending do
|
126
|
+
l.to_s.should == "\n <html:h1 xmlns:html=\"http://NoHTML.example.org\">\n <b xmlns=\"http://www.w3.org/1999/xhtml\">John</b>\n </html:h1>\n "
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should reproduce test002" do
|
131
|
+
l = @new.call("
|
132
|
+
Ramifications of
|
133
|
+
<apply>
|
134
|
+
<power/>
|
135
|
+
<apply>
|
136
|
+
<plus/>
|
137
|
+
<ci>a</ci>
|
138
|
+
<ci>b</ci>
|
139
|
+
</apply>
|
140
|
+
<cn>2</cn>
|
141
|
+
</apply>
|
142
|
+
to World Peace
|
143
|
+
",
|
144
|
+
:datatype => RDF.XMLLiteral,
|
145
|
+
:namespaces => {
|
146
|
+
"" => "http://www.w3.org/TR/REC-mathml",
|
147
|
+
})
|
148
|
+
|
149
|
+
l.to_s.should == "\n Ramifications of\n <apply xmlns=\"http://www.w3.org/TR/REC-mathml\">\n <power></power>\n <apply>\n\t<plus></plus>\n\t<ci>a</ci>\n\t<ci>b</ci>\n </apply>\n <cn>2</cn>\n </apply>\n to World Peace\n "
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "rdfms-xmllang" do
|
154
|
+
it "should reproduce test001" do
|
155
|
+
l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => nil)
|
156
|
+
|
157
|
+
l.to_s.should == "chat"
|
158
|
+
end
|
159
|
+
it "should reproduce test002" do
|
160
|
+
l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => :fr)
|
161
|
+
|
162
|
+
l.to_s.should == "chat"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "xml-canon" do
|
167
|
+
it "should reproduce test001" do
|
168
|
+
l = @new.call("<br />", :datatype => RDF.XMLLiteral)
|
169
|
+
|
170
|
+
l.to_s.should == "<br></br>"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "rdfa tests" do
|
176
|
+
it "should reproduce test 0011: XMLLiteral" do
|
177
|
+
l = @new.call("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time",
|
178
|
+
:datatype => RDF.XMLLiteral,
|
179
|
+
:namespaces => {"" => "http://www.w3.org/1999/xhtml"})
|
180
|
+
|
181
|
+
l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should reproduce test 0092: Tests XMLLiteral content with explicit @datatype" do
|
185
|
+
l = @new.call(%(E = mc<sup>2</sup>: The Most Urgent Problem of Our Time<),
|
186
|
+
:datatype => RDF.XMLLiteral,
|
187
|
+
:namespaces => {"" => "http://www.w3.org/1999/xhtml"})
|
188
|
+
|
189
|
+
l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should reproduce test 0100: XMLLiteral with explicit namespace" do
|
193
|
+
l = @new.call(%(Some text here in <strong>bold</strong> and an svg rectangle: <svg:svg><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
|
194
|
+
:datatype => RDF.XMLLiteral,
|
195
|
+
:namespaces => {
|
196
|
+
"" => "http://www.w3.org/1999/xhtml",
|
197
|
+
"svg" => "http://www.w3.org/2000/svg",
|
198
|
+
})
|
199
|
+
|
200
|
+
pending do
|
201
|
+
l.to_s.should == "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should reproduce 0101: XMLLiteral with explicit namespace and xml:lang" do
|
206
|
+
l = @new.call(%(Du texte ici en <strong>gras</strong> et un rectangle en svg: <svg:svg><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
|
207
|
+
:datatype => RDF.XMLLiteral, :language => :fr,
|
208
|
+
:namespaces => {
|
209
|
+
"" => "http://www.w3.org/1999/xhtml",
|
210
|
+
"svg" => "http://www.w3.org/2000/svg",
|
211
|
+
})
|
212
|
+
|
213
|
+
pending do
|
214
|
+
l.to_s.should == "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should reproduce test 0102: XMLLiteral with explicit namespace and xml:lang; not overwriting existing langs" do
|
219
|
+
l = @new.call(%(Du texte ici en <strong>gras</strong> et un rectangle en svg: <svg:svg xml:lang="hu"><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
|
220
|
+
:datatype => RDF.XMLLiteral, :language => :fr,
|
221
|
+
:namespaces => {
|
222
|
+
"" => "http://www.w3.org/1999/xhtml",
|
223
|
+
"svg" => "http://www.w3.org/2000/svg",
|
224
|
+
})
|
225
|
+
|
226
|
+
pending do
|
227
|
+
l.to_s.should == "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"hu\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should reproduce test 0103: XMLLiteral with explicit namespace; not overwriting local namespaces" do
|
232
|
+
l = @new.call(%(Some text here in <strong>bold</strong> and an svg rectangle: <svg xmlns="http://www.w3.org/2000/svg"><rect width="200" height="100"/></svg>),
|
233
|
+
:datatype => RDF.XMLLiteral,
|
234
|
+
:namespaces => {
|
235
|
+
"" => "http://www.w3.org/1999/xhtml",
|
236
|
+
"svg" => "http://www.w3.org/2000/svg",
|
237
|
+
})
|
238
|
+
|
239
|
+
pending do
|
240
|
+
l.to_s.should == "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg xmlns=\"http://www.w3.org/2000/svg\"><rect height=\"100\" width=\"200\"></rect></svg>"
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
60
244
|
end if defined?(::Nokogiri)
|
61
245
|
end
|