rdf-n3 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/History.txt +9 -0
- data/README.rdoc +4 -2
- data/Rakefile +37 -2
- data/VERSION +1 -1
- data/example.rb +1 -1
- data/lib/rdf/n3.rb +12 -5
- data/lib/rdf/n3/format.rb +0 -1
- data/lib/rdf/n3/patches/array_hacks.rb +46 -124
- data/lib/rdf/n3/patches/graph_properties.rb +34 -0
- data/lib/rdf/n3/patches/literal_hacks.rb +23 -0
- data/lib/rdf/n3/patches/literal_normalization.rb +120 -0
- data/lib/rdf/n3/patches/qname_hacks.rb +57 -0
- data/lib/rdf/n3/patches/rdf_escape.rb +3 -3
- data/lib/rdf/n3/patches/seq.rb +34 -0
- data/lib/rdf/n3/patches/uri_hacks.rb +19 -0
- data/lib/rdf/n3/reader.rb +110 -68
- data/lib/rdf/n3/reader/n3_grammar.rb +3876 -0
- data/lib/rdf/n3/{vocabulary.rb → vocab.rb} +0 -0
- data/lib/rdf/n3/writer.rb +444 -0
- data/rdf-n3.gemspec +38 -15
- data/script/console +8 -0
- data/script/parse +49 -0
- data/spec/cwm_spec.rb +13 -5
- data/spec/format_spec.rb +21 -0
- data/spec/literal_spec.rb +382 -0
- data/spec/matchers.rb +101 -0
- data/spec/n3reader_spec.rb +253 -185
- data/spec/rdf_helper.rb +115 -89
- data/spec/spec_helper.rb +39 -0
- data/spec/swap_spec.rb +24 -10
- data/spec/swap_test/n3parser.yml +193 -0
- data/spec/swap_test/regression.yml +226 -0
- data/spec/turtle_spec.rb +23 -8
- data/spec/writer_spec.rb +250 -0
- metadata +80 -22
- data/spec/swap_helper.rb +0 -136
- data/spec/triple_spec.rb +0 -236
data/spec/matchers.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
module Matchers
|
2
|
+
class BeEquivalentGraph
|
3
|
+
Info = Struct.new(:about, :information, :trace, :compare, :inputDocument, :outputDocument)
|
4
|
+
def normalize(graph)
|
5
|
+
case graph
|
6
|
+
when RDF::Graph then graph
|
7
|
+
when IO, StringIO
|
8
|
+
RDF::Graph.new.load(graph, :base_uri => @info.about)
|
9
|
+
else
|
10
|
+
# Figure out which parser to use
|
11
|
+
g = RDF::Graph.new
|
12
|
+
reader_class = RDF::Reader.for(detect_format(graph))
|
13
|
+
reader_class.new(graph, :base_uri => @info.about).each {|s| g << s}
|
14
|
+
g
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(expected, info)
|
19
|
+
@info = if info.respond_to?(:about)
|
20
|
+
info
|
21
|
+
elsif info.is_a?(Hash)
|
22
|
+
identifier = info[:identifier] || expected.is_a?(RDF::Graph) ? expected.context : info[:about]
|
23
|
+
trace = info[:trace]
|
24
|
+
trace = trace.join("\n") if trace.is_a?(Array)
|
25
|
+
Info.new(identifier, info[:information] || "", trace, info[:compare])
|
26
|
+
else
|
27
|
+
Info.new(expected.is_a?(RDF::Graph) ? expected.context : info, info.to_s)
|
28
|
+
end
|
29
|
+
@expected = normalize(expected)
|
30
|
+
end
|
31
|
+
|
32
|
+
def matches?(actual)
|
33
|
+
@actual = normalize(actual)
|
34
|
+
@actual == @expected
|
35
|
+
end
|
36
|
+
|
37
|
+
def failure_message_for_should
|
38
|
+
info = @info.respond_to?(:information) ? @info.information : @info.inspect
|
39
|
+
if @expected.is_a?(RDF::Graph) && @actual.size != @expected.size
|
40
|
+
"Graph entry count differs:\nexpected: #{@expected.size}\nactual: #{@actual.size}"
|
41
|
+
elsif @expected.is_a?(Array) && @actual.size != @expected.length
|
42
|
+
"Graph entry count differs:\nexpected: #{@expected.length}\nactual: #{@actual.size}"
|
43
|
+
else
|
44
|
+
"Graph differs"
|
45
|
+
end +
|
46
|
+
"\n#{info + "\n" unless info.empty?}" +
|
47
|
+
(@info.inputDocument ? "Input file: #{@info.inputDocument}\n" : "") +
|
48
|
+
(@info.outputDocument ? "Output file: #{@info.outputDocument}\n" : "") +
|
49
|
+
"Unsorted Expected:\n#{@expected.to_ntriples}" +
|
50
|
+
"Unsorted Results:\n#{@actual.to_ntriples}" +
|
51
|
+
(@info.trace ? "\nDebug:\n#{@info.trace}" : "")
|
52
|
+
end
|
53
|
+
def negative_failure_message
|
54
|
+
"Graphs do not differ\n"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def be_equivalent_graph(expected, info = nil)
|
59
|
+
BeEquivalentGraph.new(expected, info)
|
60
|
+
end
|
61
|
+
|
62
|
+
class MatchRE
|
63
|
+
Info = Struct.new(:about, :information, :trace, :inputDocument, :outputDocument)
|
64
|
+
def initialize(expected, info)
|
65
|
+
@info = if info.respond_to?(:about)
|
66
|
+
info
|
67
|
+
elsif info.is_a?(Hash)
|
68
|
+
identifier = info[:identifier] || info[:about]
|
69
|
+
trace = info[:trace]
|
70
|
+
trace = trace.join("\n") if trace.is_a?(Array)
|
71
|
+
Info.new(identifier, info[:information] || "", trace, info[:inputDocument], info[:outputDocument])
|
72
|
+
else
|
73
|
+
Info.new(info, info.to_s)
|
74
|
+
end
|
75
|
+
@expected = expected
|
76
|
+
end
|
77
|
+
|
78
|
+
def matches?(actual)
|
79
|
+
@actual = actual
|
80
|
+
@actual.to_s.match(@expected)
|
81
|
+
end
|
82
|
+
|
83
|
+
def failure_message_for_should
|
84
|
+
info = @info.respond_to?(:information) ? @info.information : @info.inspect
|
85
|
+
"Match failed"
|
86
|
+
"\n#{info + "\n" unless info.empty?}" +
|
87
|
+
(@info.inputDocument ? "Input file: #{@info.inputDocument}\n" : "") +
|
88
|
+
(@info.outputDocument ? "Output file: #{@info.outputDocument}\n" : "") +
|
89
|
+
"Expression: #{@expected}\n" +
|
90
|
+
"Unsorted Results:\n#{@actual}" +
|
91
|
+
(@info.trace ? "\nDebug:\n#{@info.trace}" : "")
|
92
|
+
end
|
93
|
+
def negative_failure_message
|
94
|
+
"Match succeeded\n"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def match_re(expected, info = nil)
|
99
|
+
MatchRE.new(expected, info)
|
100
|
+
end
|
101
|
+
end
|
data/spec/n3reader_spec.rb
CHANGED
@@ -1,29 +1,113 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
|
-
include RdfContext
|
4
3
|
|
5
4
|
describe "RDF::N3::Reader" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
context "discovery" do
|
6
|
+
{
|
7
|
+
"n3" => RDF::Reader.for(:n3),
|
8
|
+
"etc/foaf.n3" => RDF::Reader.for("etc/foaf.n3"),
|
9
|
+
"etc/foaf.ttl" => RDF::Reader.for("etc/foaf.ttl"),
|
10
|
+
"foaf.n3" => RDF::Reader.for(:file_name => "foaf.n3"),
|
11
|
+
"foaf.ttl" => RDF::Reader.for(:file_name => "foaf.ttl"),
|
12
|
+
".n3" => RDF::Reader.for(:file_extension => "n3"),
|
13
|
+
".ttl" => RDF::Reader.for(:file_extension => "ttl"),
|
14
|
+
"text/n3" => RDF::Reader.for(:content_type => "text/n3"),
|
15
|
+
"text/turtle" => RDF::Reader.for(:content_type => "text/turtle"),
|
16
|
+
}.each_pair do |label, format|
|
17
|
+
it "should discover '#{label}'" do
|
18
|
+
format.should == RDF::N3::Reader
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context :interface do
|
24
|
+
before(:each) do
|
25
|
+
@sampledoc = <<-EOF;
|
26
|
+
@prefix dc: <http://purl.org/dc/elements/1.1/>.
|
27
|
+
@prefix po: <http://purl.org/ontology/po/>.
|
28
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
|
29
|
+
_:broadcast
|
30
|
+
a po:Broadcast;
|
31
|
+
po:schedule_date """2008-06-24T12:00:00Z""";
|
32
|
+
po:broadcast_of _:version;
|
33
|
+
po:broadcast_on <http://www.bbc.co.uk/programmes/service/6music>;
|
34
|
+
.
|
35
|
+
_:version
|
36
|
+
a po:Version;
|
37
|
+
.
|
38
|
+
<http://www.bbc.co.uk/programmes/b0072l93>
|
39
|
+
dc:title """Nemone""";
|
40
|
+
a po:Brand;
|
41
|
+
.
|
42
|
+
<http://www.bbc.co.uk/programmes/b00c735d>
|
43
|
+
a po:Episode;
|
44
|
+
po:episode <http://www.bbc.co.uk/programmes/b0072l93>;
|
45
|
+
po:version _:version;
|
46
|
+
po:long_synopsis """Actor and comedian Rhys Darby chats to Nemone.""";
|
47
|
+
dc:title """Nemone""";
|
48
|
+
po:synopsis """Actor and comedian Rhys Darby chats to Nemone.""";
|
49
|
+
.
|
50
|
+
<http://www.bbc.co.uk/programmes/service/6music>
|
51
|
+
a po:Service;
|
52
|
+
dc:title """BBC 6 Music""";
|
53
|
+
.
|
54
|
+
|
55
|
+
#_:abcd a po:Episode.
|
56
|
+
EOF
|
16
57
|
end
|
17
58
|
|
18
|
-
it "should
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
59
|
+
it "should yield reader" do
|
60
|
+
inner = mock("inner")
|
61
|
+
inner.should_receive(:called).with(RDF::N3::Reader)
|
62
|
+
RDF::N3::Reader.new(@sampledoc) do |reader|
|
63
|
+
inner.called(reader.class)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return reader" do
|
68
|
+
RDF::N3::Reader.new(@sampledoc).should be_a(RDF::N3::Reader)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should yield statements" do
|
72
|
+
inner = mock("inner")
|
73
|
+
inner.should_receive(:called).with(RDF::Statement).exactly(15)
|
74
|
+
RDF::N3::Reader.new(@sampledoc).each_statement do |statement|
|
75
|
+
inner.called(statement.class)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should yield triples" do
|
80
|
+
inner = mock("inner")
|
81
|
+
inner.should_receive(:called).exactly(15)
|
82
|
+
RDF::N3::Reader.new(@sampledoc).each_triple do |subject, predicate, object|
|
83
|
+
inner.called(subject.class, predicate.class, object.class)
|
84
|
+
end
|
25
85
|
end
|
86
|
+
end
|
26
87
|
|
88
|
+
describe "with simple ntriples" do
|
89
|
+
context "simple triple" do
|
90
|
+
before(:each) do
|
91
|
+
n3_string = %(<http://example.org/> <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" .)
|
92
|
+
@graph = parse(n3_string)
|
93
|
+
@statement = @graph.statements.first
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should have a single triple" do
|
97
|
+
@graph.size.should == 1
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should have subject" do
|
101
|
+
@statement.subject.to_s.should == "http://example.org/"
|
102
|
+
end
|
103
|
+
it "should have predicate" do
|
104
|
+
@statement.predicate.to_s.should == "http://xmlns.com/foaf/0.1/name"
|
105
|
+
end
|
106
|
+
it "should have object" do
|
107
|
+
@statement.object.to_s.should == '"Gregg Kellogg"'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
27
111
|
# NTriple tests from http://www.w3.org/2000/10/rdf-tests/rdfcore/ntriples/test.nt
|
28
112
|
describe "with blank lines" do
|
29
113
|
{
|
@@ -33,8 +117,7 @@ describe "RDF::N3::Reader" do
|
|
33
117
|
"line with spaces" => " "
|
34
118
|
}.each_pair do |name, statement|
|
35
119
|
specify "test #{name}" do
|
36
|
-
|
37
|
-
@parser.graph.size.should == 0
|
120
|
+
parse(statement).size.should == 0
|
38
121
|
end
|
39
122
|
end
|
40
123
|
end
|
@@ -52,26 +135,26 @@ describe "RDF::N3::Reader" do
|
|
52
135
|
"€" => ':a :b "\u20AC" .',
|
53
136
|
}.each_pair do |contents, triple|
|
54
137
|
specify "test #{contents}" do
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
138
|
+
graph = parse(triple, :base_uri => "http://a/b")
|
139
|
+
statement = graph.statements.first
|
140
|
+
graph.size.should == 1
|
141
|
+
statement.object.value.should == contents
|
59
142
|
end
|
60
143
|
end
|
61
144
|
|
62
145
|
it "should parse long literal with escape" do
|
63
146
|
n3 = %(@prefix : <http://example.org/foo#> . :a :b "\\U00015678another" .)
|
64
147
|
if defined?(::Encoding)
|
65
|
-
|
66
|
-
|
148
|
+
statement = parse(n3).statements.first
|
149
|
+
statement.object.value.should == "\u{15678}another"
|
67
150
|
else
|
68
|
-
lambda {
|
151
|
+
lambda { parse(n3) }.should raise_error(RDF::ReaderError, "Long Unicode escapes no supported in Ruby 1.8")
|
69
152
|
pending("Not supported in Ruby 1.8")
|
70
153
|
end
|
71
154
|
end
|
72
155
|
|
73
156
|
it "should parse multi-line literal" do
|
74
|
-
|
157
|
+
graph = parse(%(
|
75
158
|
<http://www.example.com/books#book12345> <http://purl.org/dc/terms/title> """
|
76
159
|
Foo
|
77
160
|
<html:b xmlns:html="http://www.w3.org/1999/xhtml" html:a="b">bar<rdf:Thing xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><a:b xmlns:a="foo:"></a:b>here<a:c xmlns:a="foo:"></a:c></rd
|
@@ -81,9 +164,8 @@ describe "RDF::N3::Reader" do
|
|
81
164
|
""" .
|
82
165
|
))
|
83
166
|
|
84
|
-
|
85
|
-
|
86
|
-
@parser.graph[0].object.contents.should == %(
|
167
|
+
graph.size.should == 1
|
168
|
+
graph.statements.first.object.value.should == %(
|
87
169
|
Foo
|
88
170
|
<html:b xmlns:html="http://www.w3.org/1999/xhtml" html:a="b">bar<rdf:Thing xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><a:b xmlns:a="foo:"></a:b>here<a:c xmlns:a="foo:"></a:c></rd
|
89
171
|
f:Thing></html:b>
|
@@ -93,43 +175,40 @@ describe "RDF::N3::Reader" do
|
|
93
175
|
end
|
94
176
|
|
95
177
|
it "should parse long literal ending in double quote" do
|
96
|
-
|
97
|
-
|
98
|
-
|
178
|
+
graph = parse(%(:a :b """ \\"""" .), :base_uri => "http://a/b")
|
179
|
+
graph.size.should == 1
|
180
|
+
graph.statements.first.object.value.should == ' "'
|
99
181
|
end
|
100
182
|
end
|
101
183
|
|
102
184
|
it "should create named subject bnode" do
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
triple.object.should == "http://example.org/resource2"
|
185
|
+
graph = parse("_:anon <http://example.org/property> <http://example.org/resource2> .")
|
186
|
+
graph.size.should == 1
|
187
|
+
statement = graph.statements.first
|
188
|
+
statement.subject.should be_a(RDF::Node)
|
189
|
+
statement.subject.id.should =~ /anon/
|
190
|
+
statement.predicate.to_s.should == "http://example.org/property"
|
191
|
+
statement.object.to_s.should == "http://example.org/resource2"
|
111
192
|
end
|
112
193
|
|
113
194
|
it "should create named predicate bnode" do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
triple.object.should == "http://example.org/object"
|
195
|
+
graph = parse("<http://example.org/resource2> _:anon <http://example.org/object> .")
|
196
|
+
graph.size.should == 1
|
197
|
+
statement = graph.statements.first
|
198
|
+
statement.subject.to_s.should == "http://example.org/resource2"
|
199
|
+
statement.predicate.should be_a(RDF::Node)
|
200
|
+
statement.predicate.id.should =~ /anon/
|
201
|
+
statement.object.to_s.should == "http://example.org/object"
|
122
202
|
end
|
123
203
|
|
124
204
|
it "should create named object bnode" do
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
triple.object.identifier.should =~ /anon/
|
205
|
+
graph = parse("<http://example.org/resource2> <http://example.org/property> _:anon .")
|
206
|
+
graph.size.should == 1
|
207
|
+
statement = graph.statements.first
|
208
|
+
statement.subject.to_s.should == "http://example.org/resource2"
|
209
|
+
statement.predicate.to_s.should == "http://example.org/property"
|
210
|
+
statement.object.should be_a(RDF::Node)
|
211
|
+
statement.object.id.should =~ /anon/
|
133
212
|
end
|
134
213
|
|
135
214
|
{
|
@@ -161,28 +240,26 @@ describe "RDF::N3::Reader" do
|
|
161
240
|
"Typed Literals" => '<http://example.org/resource32> <http://example.org/property> "abc"^^<http://example.org/datatype1> .',
|
162
241
|
}.each_pair do |name, statement|
|
163
242
|
specify "test #{name}" do
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
#puts @parser.graph[0].to_ntriples
|
168
|
-
@parser.graph[0].to_ntriples.should == [statement].flatten.last.gsub(/\s+/, " ").strip
|
243
|
+
graph = parse([statement].flatten.first)
|
244
|
+
graph.size.should == 1
|
245
|
+
graph.to_ntriples.chomp.should == [statement].flatten.last.gsub(/\s+/, " ").strip
|
169
246
|
end
|
170
247
|
end
|
171
248
|
|
172
249
|
it "should create typed literals" do
|
173
250
|
n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/name> \"Joe\"^^<http://www.w3.org/2001/XMLSchema#string> ."
|
174
|
-
|
175
|
-
|
251
|
+
statement = parse(n3doc).statements.first
|
252
|
+
statement.object.class.should == RDF::Literal
|
176
253
|
end
|
177
254
|
|
178
255
|
it "should create BNodes" do
|
179
256
|
n3doc = "_:a a _:c ."
|
180
|
-
|
181
|
-
|
182
|
-
|
257
|
+
statement = parse(n3doc).statements.first
|
258
|
+
statement.subject.class.should == RDF::Node
|
259
|
+
statement.object.class.should == RDF::Node
|
183
260
|
end
|
184
261
|
|
185
|
-
describe "should create
|
262
|
+
describe "should create URIs" do
|
186
263
|
{
|
187
264
|
%(<http://example.org/joe> <http://xmlns.com/foaf/0.1/knows> <http://example.org/jane> .) => %(<http://example.org/joe> <http://xmlns.com/foaf/0.1/knows> <http://example.org/jane> .),
|
188
265
|
%(<joe> <knows> <jane> .) => %(<http://a/joe> <http://a/knows> <http://a/jane> .),
|
@@ -190,7 +267,7 @@ describe "RDF::N3::Reader" do
|
|
190
267
|
%(<#D%C3%BCrst> a "URI percent ^encoded as C3, BC".) => %(<http://a/b#D%C3%BCrst> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "URI percent ^encoded as C3, BC" .),
|
191
268
|
}.each_pair do |n3, nt|
|
192
269
|
it "for '#{n3}'" do
|
193
|
-
|
270
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
194
271
|
end
|
195
272
|
end
|
196
273
|
|
@@ -200,7 +277,7 @@ describe "RDF::N3::Reader" do
|
|
200
277
|
}.each_pair do |n3, nt|
|
201
278
|
it "for '#{n3}'" do
|
202
279
|
begin
|
203
|
-
|
280
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
204
281
|
rescue
|
205
282
|
if defined?(::Encoding)
|
206
283
|
raise
|
@@ -214,15 +291,15 @@ describe "RDF::N3::Reader" do
|
|
214
291
|
|
215
292
|
it "should create URIRefs" do
|
216
293
|
n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/knows> <http://example.org/jane> ."
|
217
|
-
|
218
|
-
|
219
|
-
|
294
|
+
statement = parse(n3doc).statements.first
|
295
|
+
statement.subject.class.should == RDF::URI
|
296
|
+
statement.object.class.should == RDF::URI
|
220
297
|
end
|
221
298
|
|
222
299
|
it "should create literals" do
|
223
300
|
n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/name> \"Joe\"."
|
224
|
-
|
225
|
-
|
301
|
+
statement = parse(n3doc).statements.first
|
302
|
+
statement.object.class.should == RDF::Literal
|
226
303
|
end
|
227
304
|
end
|
228
305
|
|
@@ -233,13 +310,13 @@ describe "RDF::N3::Reader" do
|
|
233
310
|
%(:y :p1 "xy.z"^^xsd:double .) => %r(Typed literal has an invalid lexical value: .* "xy\.z"),
|
234
311
|
%(:y :p1 "+1.0z"^^xsd:double .) => %r(Typed literal has an invalid lexical value: .* "\+1.0z"),
|
235
312
|
%(:a :b .) => %r(Illegal statment: ".*" missing object),
|
236
|
-
%(:a :b 'single quote' .) =>
|
237
|
-
%(:a "literal value" :b .) =>
|
313
|
+
%(:a :b 'single quote' .) => RDF::ReaderError,
|
314
|
+
%(:a "literal value" :b .) => RDF::ReaderError,
|
238
315
|
%(@keywords prefix. :e prefix :f .) => %r(Keyword ".*" used as expression)
|
239
316
|
}.each_pair do |n3, error|
|
240
317
|
it "should raise error for '#{n3}'" do
|
241
318
|
lambda {
|
242
|
-
|
319
|
+
parse("@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{n3}", :base_uri => "http://a/b")
|
243
320
|
}.should raise_error(error)
|
244
321
|
end
|
245
322
|
end
|
@@ -254,14 +331,8 @@ describe "RDF::N3::Reader" do
|
|
254
331
|
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>
|
255
332
|
<http://example.org/joe> foaf:name \"Joe\"^^xsd:string .
|
256
333
|
)
|
257
|
-
|
258
|
-
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should map <> to document uri" do
|
262
|
-
n3doc = "@prefix : <> ."
|
263
|
-
@parser.parse(n3doc, "http://the.document.itself")
|
264
|
-
@parser.graph.nsbinding.should == {"" => Namespace.new("http://the.document.itself#", "")}
|
334
|
+
statement = parse(n3doc).statements.first
|
335
|
+
statement.object.class.should == RDF::Literal
|
265
336
|
end
|
266
337
|
|
267
338
|
it "should use <> as a prefix and as a triple node" do
|
@@ -269,7 +340,7 @@ describe "RDF::N3::Reader" do
|
|
269
340
|
nt = %(
|
270
341
|
<http://a/b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#a> .
|
271
342
|
)
|
272
|
-
|
343
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
273
344
|
end
|
274
345
|
|
275
346
|
it "should use <#> as a prefix and as a triple node" do
|
@@ -277,31 +348,31 @@ describe "RDF::N3::Reader" do
|
|
277
348
|
nt = %(
|
278
349
|
<http://a/b#> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#a> .
|
279
350
|
)
|
280
|
-
|
351
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
281
352
|
end
|
282
353
|
|
283
354
|
it "should generate rdf:type for 'a'" do
|
284
355
|
n3 = %(@prefix a: <http://foo/a#> . a:b a <http://www.w3.org/2000/01/rdf-schema#resource> .)
|
285
356
|
nt = %(<http://foo/a#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#resource> .)
|
286
|
-
|
357
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
287
358
|
end
|
288
359
|
|
289
360
|
it "should generate rdf:type for '@a'" do
|
290
361
|
n3 = %(@prefix a: <http://foo/a#> . a:b @a <http://www.w3.org/2000/01/rdf-schema#resource> .)
|
291
362
|
nt = %(<http://foo/a#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#resource> .)
|
292
|
-
|
363
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
293
364
|
end
|
294
365
|
|
295
366
|
it "should generate inverse predicate for 'is xxx of'" do
|
296
367
|
n3 = %("value" is :prop of :b . :b :prop "value" .)
|
297
368
|
nt = %(<http://a/b#b> <http://a/b#prop> "value" .)
|
298
|
-
|
369
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
299
370
|
end
|
300
371
|
|
301
372
|
it "should generate inverse predicate for '@is xxx @of'" do
|
302
373
|
n3 = %("value" @is :prop @of :b . :b :prop "value" .)
|
303
374
|
nt = %(<http://a/b#b> <http://a/b#prop> "value" .)
|
304
|
-
|
375
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
305
376
|
end
|
306
377
|
|
307
378
|
it "should generate inverse predicate for 'is xxx of' with object list" do
|
@@ -310,37 +381,37 @@ describe "RDF::N3::Reader" do
|
|
310
381
|
<http://a/b#b> <http://a/b#prop> "value" .
|
311
382
|
<http://a/b#c> <http://a/b#prop> "value" .
|
312
383
|
)
|
313
|
-
|
384
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
314
385
|
end
|
315
386
|
|
316
387
|
it "should generate predicate for 'has xxx'" do
|
317
388
|
n3 = %(@prefix a: <http://foo/a#> . a:b has :pred a:c .)
|
318
389
|
nt = %(<http://foo/a#b> <http://a/b#pred> <http://foo/a#c> .)
|
319
|
-
|
390
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
320
391
|
end
|
321
392
|
|
322
393
|
it "should generate predicate for '@has xxx'" do
|
323
394
|
n3 = %(@prefix a: <http://foo/a#> . a:b @has :pred a:c .)
|
324
395
|
nt = %(<http://foo/a#b> <http://a/b#pred> <http://foo/a#c> .)
|
325
|
-
|
396
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
326
397
|
end
|
327
398
|
|
328
399
|
it "should create log:implies predicate for '=>'" do
|
329
400
|
n3 = %(@prefix a: <http://foo/a#> . _:a => a:something .)
|
330
401
|
nt = %(_:a <http://www.w3.org/2000/10/swap/log#implies> <http://foo/a#something> .)
|
331
|
-
|
402
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
332
403
|
end
|
333
404
|
|
334
405
|
it "should create log:implies inverse predicate for '<='" do
|
335
406
|
n3 = %(@prefix a: <http://foo/a#> . _:a <= a:something .)
|
336
407
|
nt = %(<http://foo/a#something> <http://www.w3.org/2000/10/swap/log#implies> _:a .)
|
337
|
-
|
408
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
338
409
|
end
|
339
410
|
|
340
411
|
it "should create owl:sameAs predicate for '='" do
|
341
412
|
n3 = %(@prefix a: <http://foo/a#> . _:a = a:something .)
|
342
413
|
nt = %(_:a <http://www.w3.org/2002/07/owl#sameAs> <http://foo/a#something> .)
|
343
|
-
|
414
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
344
415
|
end
|
345
416
|
|
346
417
|
{
|
@@ -355,20 +426,20 @@ describe "RDF::N3::Reader" do
|
|
355
426
|
%(:a :b 1.0e+1) => %(<http://a/b#a> <http://a/b#b> "1.0e+1"^^<http://www.w3.org/2001/XMLSchema#double> .),
|
356
427
|
}.each_pair do |n3, nt|
|
357
428
|
it "should create typed literal for '#{n3}'" do
|
358
|
-
|
429
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
359
430
|
end
|
360
431
|
end
|
361
432
|
|
362
433
|
it "should accept empty localname" do
|
363
434
|
n3 = %(: : : .)
|
364
435
|
nt = %(<http://a/b#> <http://a/b#> <http://a/b#> .)
|
365
|
-
|
436
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
366
437
|
end
|
367
438
|
|
368
439
|
it "should accept prefix with empty local name" do
|
369
440
|
n3 = %(@prefix foo: <http://foo/bar#> . foo: foo: foo: .)
|
370
441
|
nt = %(<http://foo/bar#> <http://foo/bar#> <http://foo/bar#> .)
|
371
|
-
|
442
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
372
443
|
end
|
373
444
|
|
374
445
|
it "should do something for @forAll"
|
@@ -383,7 +454,7 @@ describe "RDF::N3::Reader" do
|
|
383
454
|
<http://foo/bar> <http://foo/bara> <http://foo/b> .
|
384
455
|
<http://foo/bar#c> <http://foo/bard> <http://foo/e> .
|
385
456
|
)
|
386
|
-
|
457
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
387
458
|
end
|
388
459
|
|
389
460
|
it "should set absolute base (trailing /)" do
|
@@ -392,7 +463,7 @@ describe "RDF::N3::Reader" do
|
|
392
463
|
<http://foo/bar/> <http://foo/bar/a> <http://foo/bar/b> .
|
393
464
|
<http://foo/bar/#c> <http://foo/bar/d> <http://foo/e> .
|
394
465
|
)
|
395
|
-
|
466
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
396
467
|
end
|
397
468
|
|
398
469
|
it "should set absolute base (trailing #)" do
|
@@ -401,7 +472,7 @@ describe "RDF::N3::Reader" do
|
|
401
472
|
<http://foo/bar> <http://foo/bar#a> <http://foo/b> .
|
402
473
|
<http://foo/bar#c> <http://foo/bar#d> <http://foo/e> .
|
403
474
|
)
|
404
|
-
|
475
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
405
476
|
end
|
406
477
|
|
407
478
|
it "should set relative base" do
|
@@ -421,25 +492,7 @@ describe "RDF::N3::Reader" do
|
|
421
492
|
<http://example.org/products/> <http://example.org/products/a> <http://example.org/products/d> .
|
422
493
|
<http://example.org/products/> <http://example.org/products/a> <http://example.org/products/#e> .
|
423
494
|
)
|
424
|
-
|
425
|
-
end
|
426
|
-
|
427
|
-
it "should bind named namespace" do
|
428
|
-
n3doc = "@prefix ns: <http://the/namespace#> ."
|
429
|
-
@parser.parse(n3doc, "http://a/b")
|
430
|
-
@parser.graph.nsbinding.should == {"ns" => Namespace.new("http://the/namespace#", "ns")}
|
431
|
-
end
|
432
|
-
|
433
|
-
it "should bind empty prefix to <%> by default" do
|
434
|
-
n3doc = "@prefix : <#> ."
|
435
|
-
@parser.parse(n3doc, "http://the.document.itself")
|
436
|
-
@parser.graph.nsbinding.should == {"" => Namespace.new("http://the.document.itself#", "")}
|
437
|
-
end
|
438
|
-
|
439
|
-
it "should be able to bind _ as namespace" do
|
440
|
-
n3 = %(@prefix _: <http://underscore/> . _:a a _:p.)
|
441
|
-
nt = %(<http://underscore/a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://underscore/p> .)
|
442
|
-
@parser.parse(n3, "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @parser.debug, :compare => :array)
|
495
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
443
496
|
end
|
444
497
|
end
|
445
498
|
|
@@ -455,7 +508,7 @@ describe "RDF::N3::Reader" do
|
|
455
508
|
].each do |n3|
|
456
509
|
it "should require @ if keywords set to empty for '#{n3}'" do
|
457
510
|
lambda do
|
458
|
-
|
511
|
+
parse("@keywords . #{n3}", :base_uri => "http://a/b")
|
459
512
|
end.should raise_error(/unqualified keyword '\w+' used without @keyword directive/)
|
460
513
|
end
|
461
514
|
end
|
@@ -469,7 +522,7 @@ describe "RDF::N3::Reader" do
|
|
469
522
|
%(:c :a t) => %(<http://a/b#c> <http://a/b#a> <http://a/b#t> .),
|
470
523
|
}.each_pair do |n3, nt|
|
471
524
|
it "should use default_ns for '#{n3}'" do
|
472
|
-
|
525
|
+
parse("@keywords . #{n3}", :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
473
526
|
end
|
474
527
|
end
|
475
528
|
|
@@ -482,15 +535,15 @@ describe "RDF::N3::Reader" do
|
|
482
535
|
%(@keywords has. :a has :b :c.) => %(<http://a/b#a> <http://a/b#b> <http://a/b#c> .),
|
483
536
|
} .each_pair do |n3, nt|
|
484
537
|
it "should use keyword for '#{n3}'" do
|
485
|
-
|
538
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
486
539
|
end
|
487
540
|
end
|
488
541
|
|
489
542
|
it "should raise error if unknown keyword set" do
|
490
543
|
n3 = %(@keywords foo.)
|
491
544
|
lambda do
|
492
|
-
|
493
|
-
end.should raise_error(
|
545
|
+
parse(n3, :base_uri => "http://a/b")
|
546
|
+
end.should raise_error(RDF::ReaderError, "undefined keywords used: foo")
|
494
547
|
end
|
495
548
|
end
|
496
549
|
|
@@ -502,10 +555,10 @@ describe "RDF::N3::Reader" do
|
|
502
555
|
_:a a :p.
|
503
556
|
)
|
504
557
|
nt = %(
|
505
|
-
<http://underscore/a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
|
506
|
-
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
|
558
|
+
<http://underscore/a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#p> .
|
559
|
+
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://a/b#p> .
|
507
560
|
)
|
508
|
-
|
561
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
509
562
|
end
|
510
563
|
|
511
564
|
it "should allow a prefix to be redefined" do
|
@@ -520,7 +573,7 @@ describe "RDF::N3::Reader" do
|
|
520
573
|
<http://host/A#b> <http://host/A#p> <http://host/A#v> .
|
521
574
|
<http://host/Z#b> <http://host/Z#p> <http://host/Z#v> .
|
522
575
|
)
|
523
|
-
|
576
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
524
577
|
end
|
525
578
|
|
526
579
|
it "should process sequential @base declarations (swap base.n3)" do
|
@@ -534,7 +587,7 @@ describe "RDF::N3::Reader" do
|
|
534
587
|
<http://example.com/path/DFFERENT/a2> <http://example.com/path/DFFERENT/b2> <http://example.com/path/DFFERENT/foo/bar#baz2> .
|
535
588
|
<http://example.com/path/DFFERENT/d3> <http://example.com/path/DFFERENT/#b3> <http://example.com/path/DFFERENT/e3> .
|
536
589
|
)
|
537
|
-
|
590
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
538
591
|
end
|
539
592
|
end
|
540
593
|
|
@@ -547,31 +600,31 @@ describe "RDF::N3::Reader" do
|
|
547
600
|
it "should create BNode for [] as subject" do
|
548
601
|
n3 = %(@prefix a: <http://foo/a#> . [] a:p a:v .)
|
549
602
|
nt = %(_:bnode0 <http://foo/a#p> <http://foo/a#v> .)
|
550
|
-
|
603
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
551
604
|
end
|
552
605
|
|
553
606
|
it "should create BNode for [] as predicate" do
|
554
607
|
n3 = %(@prefix a: <http://foo/a#> . a:s [] a:o .)
|
555
608
|
nt = %(<http://foo/a#s> _:bnode0 <http://foo/a#o> .)
|
556
|
-
|
609
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
557
610
|
end
|
558
611
|
|
559
612
|
it "should create BNode for [] as object" do
|
560
613
|
n3 = %(@prefix a: <http://foo/a#> . a:s a:p [] .)
|
561
614
|
nt = %(<http://foo/a#s> <http://foo/a#p> _:bnode0 .)
|
562
|
-
|
615
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
563
616
|
end
|
564
617
|
|
565
618
|
it "should create BNode for [] as statement" do
|
566
619
|
n3 = %([:a :b] .)
|
567
620
|
nt = %(_:bnode0 <http://a/b#a> <http://a/b#b> .)
|
568
|
-
|
621
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
569
622
|
end
|
570
623
|
|
571
624
|
it "should create statements with BNode subjects using [ pref obj]" do
|
572
625
|
n3 = %(@prefix a: <http://foo/a#> . [ a:p a:v ] .)
|
573
626
|
nt = %(_:bnode0 <http://foo/a#p> <http://foo/a#v> .)
|
574
|
-
|
627
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
575
628
|
end
|
576
629
|
|
577
630
|
it "should create BNode as a single object" do
|
@@ -581,7 +634,7 @@ describe "RDF::N3::Reader" do
|
|
581
634
|
_:bnode0 <http://foo/a#qq> "2" .
|
582
635
|
<http://foo/a#b> <http://foo/a#oneRef> _:bnode0 .
|
583
636
|
)
|
584
|
-
|
637
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
585
638
|
end
|
586
639
|
|
587
640
|
it "should create a shared BNode" do
|
@@ -600,7 +653,7 @@ describe "RDF::N3::Reader" do
|
|
600
653
|
_:bnode0 <http://foo/a#qq> "2" .
|
601
654
|
_:a :pred _:bnode0 .
|
602
655
|
)
|
603
|
-
|
656
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
604
657
|
end
|
605
658
|
|
606
659
|
it "should create nested BNodes" do
|
@@ -617,26 +670,26 @@ describe "RDF::N3::Reader" do
|
|
617
670
|
_:bnode1 <http://foo/a#p5> "v4" .
|
618
671
|
<http://foo/a#a> <http://foo/a#p> _:bnode1 .
|
619
672
|
)
|
620
|
-
|
673
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
621
674
|
end
|
622
675
|
|
623
676
|
describe "from paths" do
|
624
677
|
it "should create bnode for path x.p" do
|
625
678
|
n3 = %(:x2.:y2 :p2 "3" .)
|
626
679
|
nt = %(:x2 :y2 _:bnode0 . _:bnode0 :p2 "3" .)
|
627
|
-
|
680
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
628
681
|
end
|
629
682
|
|
630
683
|
it "should create bnode for path x!p" do
|
631
684
|
n3 = %(:x2!:y2 :p2 "3" .)
|
632
685
|
nt = %(:x2 :y2 _:bnode0 . _:bnode0 :p2 "3" .)
|
633
|
-
|
686
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
634
687
|
end
|
635
688
|
|
636
689
|
it "should create bnode for path x^p" do
|
637
690
|
n3 = %(:x2^:y2 :p2 "3" .)
|
638
691
|
nt = %(_:bnode0 :y2 :x2 . _:bnode0 :p2 "3" .)
|
639
|
-
|
692
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
640
693
|
end
|
641
694
|
|
642
695
|
it "should decode :joe!fam:mother!loc:office!loc:zip as Joe's mother's office's zipcode" do
|
@@ -651,7 +704,7 @@ describe "RDF::N3::Reader" do
|
|
651
704
|
_:bnode0 <http://foo/loc#office> _:bnode1 .
|
652
705
|
_:bnode1 <http://foo/loc#zip> _:bnode2 .
|
653
706
|
)
|
654
|
-
|
707
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
655
708
|
end
|
656
709
|
|
657
710
|
it "should decode :joe!fam:mother^fam:mother Anyone whose mother is Joe's mother." do
|
@@ -665,7 +718,7 @@ describe "RDF::N3::Reader" do
|
|
665
718
|
:joe <http://foo/fam#mother> _:bnode0 .
|
666
719
|
_:bnode1 <http://foo/fam#mother> _:bnode0 .
|
667
720
|
)
|
668
|
-
|
721
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
669
722
|
end
|
670
723
|
|
671
724
|
it "should decode path with property list." do
|
@@ -680,7 +733,7 @@ describe "RDF::N3::Reader" do
|
|
680
733
|
_:bnode1 :q2 "4" .
|
681
734
|
_:bnode1 :q2 "5" .
|
682
735
|
)
|
683
|
-
|
736
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
684
737
|
end
|
685
738
|
|
686
739
|
it "should decode path as object(1)" do
|
@@ -689,7 +742,7 @@ describe "RDF::N3::Reader" do
|
|
689
742
|
:a :b _:bnode .
|
690
743
|
_:bnode :c "lit" .
|
691
744
|
)
|
692
|
-
|
745
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
693
746
|
end
|
694
747
|
|
695
748
|
it "should decode path as object(2)" do
|
@@ -699,7 +752,7 @@ describe "RDF::N3::Reader" do
|
|
699
752
|
_:bnode0 <http://a/ns#p2> _:bnode1 .
|
700
753
|
:r :p _:bnode1 .
|
701
754
|
)
|
702
|
-
|
755
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
703
756
|
end
|
704
757
|
end
|
705
758
|
end
|
@@ -714,7 +767,7 @@ describe "RDF::N3::Reader" do
|
|
714
767
|
it "should create 2 statements for simple list" do
|
715
768
|
n3 = %(:a :b :c, :d)
|
716
769
|
nt = %(<http://a/b#a> <http://a/b#b> <http://a/b#c> . <http://a/b#a> <http://a/b#b> <http://a/b#d> .)
|
717
|
-
|
770
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
718
771
|
end
|
719
772
|
end
|
720
773
|
|
@@ -732,7 +785,7 @@ describe "RDF::N3::Reader" do
|
|
732
785
|
<http://foo/a#b> <http://foo/a#p2> <http://foo/a#v1> .
|
733
786
|
<http://foo/a#b> <http://foo/a#p3> <http://foo/a#v2> .
|
734
787
|
)
|
735
|
-
|
788
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
736
789
|
end
|
737
790
|
end
|
738
791
|
|
@@ -741,7 +794,7 @@ describe "RDF::N3::Reader" do
|
|
741
794
|
n3 = %(@prefix :<http://example.com/>. :empty :set ().)
|
742
795
|
nt = %(
|
743
796
|
<http://example.com/empty> <http://example.com/set> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .)
|
744
|
-
|
797
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
745
798
|
end
|
746
799
|
|
747
800
|
it "should parse list with single element" do
|
@@ -751,7 +804,7 @@ describe "RDF::N3::Reader" do
|
|
751
804
|
_:bnode0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
752
805
|
<http://example.com/gregg> <http://example.com/wrote> _:bnode0 .
|
753
806
|
)
|
754
|
-
|
807
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
755
808
|
end
|
756
809
|
|
757
810
|
it "should parse list with multiple elements" do
|
@@ -765,7 +818,7 @@ describe "RDF::N3::Reader" do
|
|
765
818
|
_:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
766
819
|
<http://example.com/gregg> <http://example.com/name> _:bnode0 .
|
767
820
|
)
|
768
|
-
|
821
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
769
822
|
end
|
770
823
|
|
771
824
|
it "should parse unattached lists" do
|
@@ -784,13 +837,13 @@ describe "RDF::N3::Reader" do
|
|
784
837
|
_:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "3" .
|
785
838
|
_:bnode2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
786
839
|
)
|
787
|
-
|
840
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
788
841
|
end
|
789
842
|
|
790
843
|
it "should add property to nil list" do
|
791
844
|
n3 = %(@prefix a: <http://foo/a#> . () a:prop "nilProp" .)
|
792
845
|
nt = %(<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> <http://foo/a#prop> "nilProp" .)
|
793
|
-
|
846
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug, :compare => :array)
|
794
847
|
end
|
795
848
|
it "should parse with compound items" do
|
796
849
|
n3 = %(
|
@@ -818,7 +871,7 @@ describe "RDF::N3::Reader" do
|
|
818
871
|
<http://foo/a#a> <http://foo/a#p> _:bnode1 .
|
819
872
|
<http://resource1> <http://foo/a#p> "value" .
|
820
873
|
)
|
821
|
-
|
874
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
822
875
|
end
|
823
876
|
|
824
877
|
end
|
@@ -837,28 +890,28 @@ describe "RDF::N3::Reader" do
|
|
837
890
|
end
|
838
891
|
|
839
892
|
describe "with AggregateGraph tests" do
|
840
|
-
subject { Graph.new }
|
841
|
-
|
842
893
|
describe "with a type" do
|
843
|
-
|
844
|
-
|
894
|
+
it "should have 3 namespaces" do
|
895
|
+
n3 = %(
|
845
896
|
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
846
897
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
847
898
|
@prefix : <http://test/> .
|
848
899
|
:foo a rdfs:Class.
|
849
900
|
:bar :d :c.
|
850
901
|
:a :d :c.
|
851
|
-
)
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
902
|
+
)
|
903
|
+
nt = %(
|
904
|
+
<http://test/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
|
905
|
+
<http://test/bar> <http://test/d> <http://test/c> .
|
906
|
+
<http://test/a> <http://test/d> <http://test/c> .
|
907
|
+
)
|
908
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
856
909
|
end
|
857
910
|
end
|
858
911
|
|
859
912
|
describe "with blank clause" do
|
860
|
-
|
861
|
-
|
913
|
+
it "should have 4 namespaces" do
|
914
|
+
n3 = %(
|
862
915
|
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
863
916
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
864
917
|
@prefix : <http://test/> .
|
@@ -866,32 +919,38 @@ describe "RDF::N3::Reader" do
|
|
866
919
|
:foo a rdfs:Resource.
|
867
920
|
:bar rdfs:isDefinedBy [ a log:Formula ].
|
868
921
|
:a :d :e.
|
869
|
-
)
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
922
|
+
)
|
923
|
+
nt = %(
|
924
|
+
<http://test/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
925
|
+
_:g2160128180 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/10/swap/log#Formula> .
|
926
|
+
<http://test/bar> <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> _:g2160128180 .
|
927
|
+
<http://test/a> <http://test/d> <http://test/e> .
|
928
|
+
)
|
929
|
+
parse(n3, :base_uri => "http://a/b").should be_equivalent_graph(nt, :about => "http://a/b", :trace => @debug)
|
874
930
|
end
|
875
931
|
end
|
876
932
|
|
877
933
|
describe "with empty subject" do
|
878
934
|
before(:each) do
|
879
|
-
|
935
|
+
@graph = parse(%(
|
880
936
|
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
881
937
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
882
938
|
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
|
883
939
|
@prefix : <http://test/> .
|
884
940
|
<> a log:N3Document.
|
885
|
-
), "http://test/")
|
941
|
+
), :base_uri => "http://test/")
|
886
942
|
end
|
887
943
|
|
888
944
|
it "should have 4 namespaces" do
|
889
|
-
|
945
|
+
nt = %(
|
946
|
+
<http://test/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/10/swap/log#N3Document> .
|
947
|
+
)
|
948
|
+
@graph.should be_equivalent_graph(nt, :about => "http://test/", :trace => @debug)
|
890
949
|
end
|
891
950
|
|
892
951
|
it "should have default subject" do
|
893
|
-
|
894
|
-
|
952
|
+
@graph.size.should == 1
|
953
|
+
@graph.statements.first.subject.to_s.should == "http://test/"
|
895
954
|
end
|
896
955
|
end
|
897
956
|
end
|
@@ -908,21 +967,30 @@ describe "RDF::N3::Reader" do
|
|
908
967
|
<http://www.w3.org/2000/10/rdf-tests/rdfcore/xmlbase/test001.nt> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#NT-Document> .
|
909
968
|
<http://www.w3.org/2000/10/rdf-tests/rdfcore/xmlbase/test001.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#RDF-XML-Document> .
|
910
969
|
EOF
|
911
|
-
|
970
|
+
graph = parse(sampledoc, :base_uri => "http://www.w3.org/2000/10/rdf-tests/rdfcore/amp-in-url/Manifest.rdf")
|
912
971
|
|
913
|
-
|
972
|
+
graph.should be_equivalent_graph(sampledoc,
|
914
973
|
:about => "http://www.w3.org/2000/10/rdf-tests/rdfcore/amp-in-url/Manifest.rdf",
|
915
|
-
:trace => @
|
974
|
+
:trace => @debug, :compare => :array
|
916
975
|
)
|
917
976
|
end
|
977
|
+
|
978
|
+
def parse(input, options = {})
|
979
|
+
@debug = []
|
980
|
+
graph = RDF::Graph.new
|
981
|
+
RDF::N3::Reader.new(input, options.merge(:debug => @debug, :strict => true)).each do |statement|
|
982
|
+
graph << statement
|
983
|
+
end
|
984
|
+
graph
|
985
|
+
end
|
918
986
|
|
919
987
|
def test_file(filepath)
|
920
988
|
n3_string = File.read(filepath)
|
921
|
-
@
|
989
|
+
@graph = parse(File.open(filepath), :base_uri => "file:#{filepath}")
|
922
990
|
|
923
991
|
nt_string = File.read(filepath.sub('.n3', '.nt'))
|
924
|
-
@
|
992
|
+
@graph.should be_equivalent_graph(nt_string,
|
925
993
|
:about => "file:#{filepath}",
|
926
|
-
:trace => @
|
994
|
+
:trace => @debug)
|
927
995
|
end
|
928
996
|
end
|