reddy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HACKNOTES +2 -0
- data/History.txt +3 -0
- data/Manifest.txt +80 -0
- data/README.rdoc +48 -0
- data/README.txt +62 -0
- data/Rakefile +67 -0
- data/lib/reddy.rb +8 -0
- data/lib/reddy/bnode.rb +70 -0
- data/lib/reddy/exceptions/about_each_exception.rb +2 -0
- data/lib/reddy/exceptions/uri_relative_exception.rb +2 -0
- data/lib/reddy/graph.rb +182 -0
- data/lib/reddy/libxml_hacks.rb +6 -0
- data/lib/reddy/literal.rb +211 -0
- data/lib/reddy/n3_grammar.treetop +129 -0
- data/lib/reddy/n3parser.rb +145 -0
- data/lib/reddy/namespace.rb +73 -0
- data/lib/reddy/rdfaparser.rb +63 -0
- data/lib/reddy/rdfxmlparser.rb +254 -0
- data/lib/reddy/rexml_hacks.rb +97 -0
- data/lib/reddy/triple.rb +95 -0
- data/lib/reddy/uriref.rb +66 -0
- data/reddy.gemspec +50 -0
- data/spec/bnode_spec.rb +29 -0
- data/spec/graph_spec.rb +138 -0
- data/spec/literal_spec.rb +142 -0
- data/spec/n3parser_spec.rb +86 -0
- data/spec/namespaces_spec.rb +44 -0
- data/spec/parser_spec.rb +391 -0
- data/spec/rdfa_parser_spec.rb +28 -0
- data/spec/rexml_hacks_spec.rb +99 -0
- data/spec/triple_spec.rb +108 -0
- data/spec/uriref_spec.rb +96 -0
- data/test/longtests_spec.rb +25 -0
- data/test/n3_tests/lcsh/sh85062913.n3 +41 -0
- data/test/n3_tests/lcsh/sh85062913.nt +21 -0
- data/test/n3_tests/lcsh/sh85082139.n3 +157 -0
- data/test/n3_tests/lcsh/sh85082139.nt +79 -0
- data/test/n3_tests/lcsh/sh85118553.n3 +123 -0
- data/test/n3_tests/lcsh/sh85118553.nt +63 -0
- data/test/n3_tests/misc/on_now-01.n3 +30 -0
- data/test/n3_tests/misc/on_now-01.nt +15 -0
- data/test/n3_tests/n3p/simple-01.n3 +1 -0
- data/test/n3_tests/n3p/simple-01.nt +0 -0
- data/test/n3_tests/n3p/simple-02.n3 +4 -0
- data/test/n3_tests/n3p/simple-02.nt +0 -0
- data/test/n3_tests/n3p/simple-03.n3 +5 -0
- data/test/n3_tests/n3p/simple-03.nt +1 -0
- data/test/n3_tests/n3p/simple-04.n3 +6 -0
- data/test/n3_tests/n3p/simple-04.nt +3 -0
- data/test/n3_tests/n3p/simple-05.n3 +7 -0
- data/test/n3_tests/n3p/simple-05.nt +2 -0
- data/test/n3_tests/n3p/simple-06.n3 +6 -0
- data/test/n3_tests/n3p/simple-06.nt +4 -0
- data/test/n3_tests/n3p/simple-07.n3 +7 -0
- data/test/n3_tests/n3p/simple-07.nt +6 -0
- data/test/perf_test/test.rb +11 -0
- data/test/perf_test/tommorris.rdf +2267 -0
- data/test/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.nt +24 -0
- data/test/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.rdf +46 -0
- data/test/rdf_tests/tm_001.nt +1 -0
- data/test/rdf_tests/tm_001.rdf +7 -0
- data/test/rdf_tests/xml-literal-mixed.nt +7 -0
- data/test/rdf_tests/xml-literal-mixed.rdf +15 -0
- data/test/ruby_fundamentals.spec.rb +17 -0
- data/test/test_helper.rb +2 -0
- data/test/test_reddy.rb +11 -0
- data/test/test_uris.rb +13 -0
- data/test/xml.rdf +6 -0
- metadata +198 -0
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'lib/reddy'
|
2
|
+
include Reddy
|
3
|
+
|
4
|
+
describe "N3 parser" do
|
5
|
+
|
6
|
+
describe "parse simple ntriples" do
|
7
|
+
n3_string = "<http://example.org/> <http://xmlns.com/foaf/0.1/name> \"Tom Morris\" . "
|
8
|
+
parser = Reddy::N3Parser.new(n3_string)
|
9
|
+
parser.graph[0].subject.to_s.should == "http://example.org/"
|
10
|
+
parser.graph[0].predicate.to_s.should == "http://xmlns.com/foaf/0.1/name"
|
11
|
+
parser.graph[0].object.to_s.should == "Tom Morris"
|
12
|
+
parser.graph.size.should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
# n3p tests taken from http://inamidst.com/n3p/test/
|
16
|
+
describe "parsing n3p test" do
|
17
|
+
dir_name = File.join(File.dirname(__FILE__), '..', 'test', 'n3_tests', 'n3p', '*.n3')
|
18
|
+
Dir.glob(dir_name).each do |n3|
|
19
|
+
it n3 do
|
20
|
+
test_file(n3)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "parsing real data tests" do
|
26
|
+
dirs = [ 'misc', 'lcsh' ]
|
27
|
+
dirs.each do |dir|
|
28
|
+
dir_name = File.join(File.dirname(__FILE__), '..', 'test', 'n3_tests', dir, '*.n3')
|
29
|
+
Dir.glob(dir_name).each do |n3|
|
30
|
+
it "#{dir} #{n3}" do
|
31
|
+
test_file(n3)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should throw an exception when presented with a BNode as a predicate" do
|
38
|
+
n3doc = "_:a _:b _:c ."
|
39
|
+
lambda do parser = N3Parser.new(n3doc) end.should raise_error(Reddy::Triple::InvalidPredicate)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create BNodes" do
|
43
|
+
n3doc = "_:a a _:c ."
|
44
|
+
parser = N3Parser.new(n3doc)
|
45
|
+
parser.graph[0].subject.class.should == Reddy::BNode
|
46
|
+
parser.graph[0].object.class.should == Reddy::BNode
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should create URIRefs" do
|
50
|
+
n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/knows> <http://example.org/jane> ."
|
51
|
+
parser = N3Parser.new(n3doc)
|
52
|
+
parser.graph[0].subject.class.should == Reddy::URIRef
|
53
|
+
parser.graph[0].object.class.should == Reddy::URIRef
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should create literals" do
|
57
|
+
n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/name> \"Joe\"."
|
58
|
+
parser = N3Parser.new(n3doc)
|
59
|
+
parser.graph[0].object.class.should == Reddy::Literal
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should create typed literals" do
|
63
|
+
# n3doc = "<http://example.org/joe> <http://xmlns.com/foaf/0.1/name> \"Joe\"^^<http://www.w3.org/2001/XMLSchema#string> ."
|
64
|
+
# parser = N3Parser.new(n3doc)
|
65
|
+
# parser.graph[0].object.classs.should == Reddy::Literal
|
66
|
+
pending
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_file(filepath)
|
70
|
+
n3_string = File.read(filepath)
|
71
|
+
parser = N3Parser.new(n3_string)
|
72
|
+
ntriples = parser.graph.to_ntriples
|
73
|
+
ntriples.gsub!(/_\:bn[\d|\-]+/, '_:node1')
|
74
|
+
ntriples = sort_ntriples(ntriples)
|
75
|
+
|
76
|
+
nt_string = File.read(filepath.sub('.n3', '.nt'))
|
77
|
+
nt_string = sort_ntriples(nt_string)
|
78
|
+
|
79
|
+
ntriples.should == nt_string
|
80
|
+
end
|
81
|
+
|
82
|
+
def sort_ntriples(string)
|
83
|
+
string.split("\n").sort.join("\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'lib/reddy'
|
2
|
+
|
3
|
+
describe "Namespaces" do
|
4
|
+
it "should use method_missing to create URIRefs on the fly" do
|
5
|
+
foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
|
6
|
+
foaf.knows.to_s.should == "http://xmlns.com/foaf/0.1/knows"
|
7
|
+
|
8
|
+
foaf_frag = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf", true)
|
9
|
+
foaf_frag.knows.to_s.should == "http://xmlns.com/foaf/0.1/#knows"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a URI" do
|
13
|
+
lambda do
|
14
|
+
test = Namespace.new(short='foaf')
|
15
|
+
end.should raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have equality with URIRefs" do
|
19
|
+
foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
|
20
|
+
foaf_name = URIRef.new("http://xmlns.com/foaf/0.1/name")
|
21
|
+
foaf.name.should == foaf_name
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have an XML and N3-friendly prefix" do
|
25
|
+
lambda do
|
26
|
+
test = Namespace.new('http://xmlns.com/foaf/0.1/', '*~{')
|
27
|
+
end.should raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to attach to the graph for substitution" do
|
31
|
+
# rdflib does this using graph.bind('prefix', namespace)
|
32
|
+
g = Graph.new
|
33
|
+
foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
|
34
|
+
foaf.bind(g)
|
35
|
+
g.nsbinding["foaf"].should == foaf
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not allow you to attach to non-graphs" do
|
39
|
+
lambda do
|
40
|
+
foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
|
41
|
+
foaf.bind("cheese")
|
42
|
+
end.should raise_error
|
43
|
+
end
|
44
|
+
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,391 @@
|
|
1
|
+
require 'lib/reddy'
|
2
|
+
require 'ruby-debug'
|
3
|
+
include Reddy
|
4
|
+
|
5
|
+
# w3c test suite: http://www.w3.org/TR/rdf-testcases/
|
6
|
+
|
7
|
+
describe "RDF/XML Parser" do
|
8
|
+
it "should recognise and do nothing for an RDF-less document" do
|
9
|
+
sampledoc = <<-EOF;
|
10
|
+
<?xml version="1.0" ?>
|
11
|
+
<NotRDF />
|
12
|
+
EOF
|
13
|
+
graph = RdfXmlParser.new(sampledoc)
|
14
|
+
graph.graph.size.should == 0
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should trigger parsing on XMl documents with multiple RDF nodes" do
|
18
|
+
sampledoc = <<-EOF;
|
19
|
+
<?xml version="1.0" ?>
|
20
|
+
<GenericXML xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://example.org/">
|
21
|
+
<rdf:RDF>
|
22
|
+
<rdf:Description rdf:about="http://example.org/one">
|
23
|
+
<ex:name>Foo</ex:name>
|
24
|
+
</rdf:Description>
|
25
|
+
</rdf:RDF>
|
26
|
+
<blablabla />
|
27
|
+
<rdf:RDF>
|
28
|
+
<rdf:Description rdf:about="http://example.org/two">
|
29
|
+
<ex:name>Bar</ex:name>
|
30
|
+
</rdf:Description>
|
31
|
+
</rdf:RDF>
|
32
|
+
</GenericXML>
|
33
|
+
EOF
|
34
|
+
graph = RdfXmlParser.new(sampledoc)
|
35
|
+
[graph.graph[0].object.to_s, graph.graph[1].object.to_s].sort.should == ["Bar", "Foo"].sort
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to parse a simple single-triple document" do
|
39
|
+
sampledoc = <<-EOF;
|
40
|
+
<?xml version="1.0" ?>
|
41
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
42
|
+
xmlns:ex="http://www.example.org/" xml:lang="en" xml:base="http://www.example.org/foo">
|
43
|
+
<ex:Thing rdf:about="http://example.org/joe" ex:name="bar">
|
44
|
+
<ex:belongsTo rdf:resource="http://tommorris.org/" />
|
45
|
+
<ex:sampleText rdf:datatype="http://www.w3.org/2001/XMLSchema#string">foo</ex:sampleText>
|
46
|
+
<ex:hadADodgyRelationshipWith>
|
47
|
+
<rdf:Description>
|
48
|
+
<ex:name>Tom</ex:name>
|
49
|
+
<ex:hadADodgyRelationshipWith>
|
50
|
+
<rdf:Description>
|
51
|
+
<ex:name>Rob</ex:name>
|
52
|
+
<ex:hadADodgyRelationshipWith>
|
53
|
+
<rdf:Description>
|
54
|
+
<ex:name>Mary</ex:name>
|
55
|
+
</rdf:Description>
|
56
|
+
</ex:hadADodgyRelationshipWith>
|
57
|
+
</rdf:Description>
|
58
|
+
</ex:hadADodgyRelationshipWith>
|
59
|
+
</rdf:Description>
|
60
|
+
</ex:hadADodgyRelationshipWith>
|
61
|
+
</ex:Thing>
|
62
|
+
</rdf:RDF>
|
63
|
+
EOF
|
64
|
+
|
65
|
+
graph = RdfXmlParser.new(sampledoc)
|
66
|
+
graph.graph.size.should == 10
|
67
|
+
# print graph.graph.to_ntriples
|
68
|
+
# TODO: add datatype parsing
|
69
|
+
# TODO: make sure the BNode forging is done correctly - an internal element->nodeID mapping
|
70
|
+
# TODO: proper test
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise an error if rdf:aboutEach is used, as per the negative parser test rdfms-abouteach-error001 (rdf:aboutEach attribute)" do
|
74
|
+
sampledoc = <<-EOF;
|
75
|
+
<?xml version="1.0" ?>
|
76
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
77
|
+
xmlns:eg="http://example.org/">
|
78
|
+
|
79
|
+
<rdf:Bag rdf:ID="node">
|
80
|
+
<rdf:li rdf:resource="http://example.org/node2"/>
|
81
|
+
</rdf:Bag>
|
82
|
+
|
83
|
+
<rdf:Description rdf:aboutEach="#node">
|
84
|
+
<dc:rights xmlns:dc="http://purl.org/dc/elements/1.1/">me</dc:rights>
|
85
|
+
|
86
|
+
</rdf:Description>
|
87
|
+
|
88
|
+
</rdf:RDF>
|
89
|
+
EOF
|
90
|
+
|
91
|
+
lambda do
|
92
|
+
graph = RdfXmlParser.new(sampledoc)
|
93
|
+
end.should raise_error
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should raise an error if rdf:aboutEachPrefix is used, as per the negative parser test rdfms-abouteach-error002 (rdf:aboutEachPrefix attribute)" do
|
97
|
+
sampledoc = <<-EOF;
|
98
|
+
<?xml version="1.0" ?>
|
99
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
100
|
+
xmlns:eg="http://example.org/">
|
101
|
+
|
102
|
+
<rdf:Description rdf:about="http://example.org/node">
|
103
|
+
<eg:property>foo</eg:property>
|
104
|
+
</rdf:Description>
|
105
|
+
|
106
|
+
<rdf:Description rdf:aboutEachPrefix="http://example.org/">
|
107
|
+
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">me</dc:creator>
|
108
|
+
|
109
|
+
</rdf:Description>
|
110
|
+
|
111
|
+
</rdf:RDF>
|
112
|
+
EOF
|
113
|
+
|
114
|
+
lambda do
|
115
|
+
graph = RdfXmlParser.new(sampledoc)
|
116
|
+
end.should raise_error
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should fail if given a non-ID as an ID (as per rdfcore-rdfms-rdf-id-error001)" do
|
120
|
+
sampledoc = <<-EOF;
|
121
|
+
<?xml version="1.0"?>
|
122
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
123
|
+
<rdf:Description rdf:ID='333-555-666' />
|
124
|
+
</rdf:RDF>
|
125
|
+
EOF
|
126
|
+
|
127
|
+
lambda do
|
128
|
+
graph = RdfXmlParser.new(sampledoc)
|
129
|
+
end.should raise_error
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should make sure that the value of rdf:ID attributes match the XML Name production (child-element version)" do
|
133
|
+
sampledoc = <<-EOF;
|
134
|
+
<?xml version="1.0" ?>
|
135
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
136
|
+
xmlns:eg="http://example.org/">
|
137
|
+
<rdf:Description>
|
138
|
+
<eg:prop rdf:ID="q:name" />
|
139
|
+
</rdf:Description>
|
140
|
+
</rdf:RDF>
|
141
|
+
EOF
|
142
|
+
|
143
|
+
lambda do
|
144
|
+
graph = RdfXmlParser.new(sampledoc)
|
145
|
+
end.should raise_error
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should be able to reify according to §2.17 of RDF/XML Syntax Specification" do
|
149
|
+
sampledoc = <<-EOF;
|
150
|
+
<?xml version="1.0"?>
|
151
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
152
|
+
xmlns:ex="http://example.org/stuff/1.0/"
|
153
|
+
xml:base="http://example.org/triples/">
|
154
|
+
<rdf:Description rdf:about="http://example.org/">
|
155
|
+
<ex:prop rdf:ID="triple1">blah</ex:prop>
|
156
|
+
</rdf:Description>
|
157
|
+
</rdf:RDF>
|
158
|
+
EOF
|
159
|
+
|
160
|
+
graph = RdfXmlParser.new(sampledoc)
|
161
|
+
graph.graph.size.should == 5
|
162
|
+
graph.graph.to_ntriples.should == <<-EOF;
|
163
|
+
<http://example.org/> <http://example.org/stuff/1.0/prop> \"blah\" .
|
164
|
+
<http://example.org/triples/#triple1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement> .
|
165
|
+
<http://example.org/triples/#triple1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <http://example.org/> .
|
166
|
+
<http://example.org/triples/#triple1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://example.org/stuff/1.0/prop> .
|
167
|
+
<http://example.org/triples/#triple1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> \"blah\" .
|
168
|
+
EOF
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should make sure that the value of rdf:ID attributes match the XML Name production (data attribute version)" do
|
172
|
+
sampledoc = <<-EOF;
|
173
|
+
<?xml version="1.0" ?>
|
174
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
175
|
+
xmlns:eg="http://example.org/">
|
176
|
+
<rdf:Description rdf:ID="a/b" eg:prop="val" />
|
177
|
+
</rdf:RDF>
|
178
|
+
EOF
|
179
|
+
|
180
|
+
lambda do
|
181
|
+
graph = RdfXmlParser.new(sampledoc)
|
182
|
+
end.should raise_error
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should handle parseType=Literal according to xml-literal-namespaces-test001.rdf test" do
|
186
|
+
sampledoc = <<-EOF;
|
187
|
+
<?xml version="1.0"?>
|
188
|
+
|
189
|
+
<!--
|
190
|
+
Copyright World Wide Web Consortium, (Massachusetts Institute of
|
191
|
+
Technology, Institut National de Recherche en Informatique et en
|
192
|
+
Automatique, Keio University).
|
193
|
+
|
194
|
+
All Rights Reserved.
|
195
|
+
|
196
|
+
Please see the full Copyright clause at
|
197
|
+
<http://www.w3.org/Consortium/Legal/copyright-software.html>
|
198
|
+
|
199
|
+
Description: Visibly used namespaces must be included in XML
|
200
|
+
Literal values. Treatment of namespaces that are not
|
201
|
+
visibly used (e.g. rdf: in this example) is implementation
|
202
|
+
dependent. Based on example from Issues List.
|
203
|
+
|
204
|
+
|
205
|
+
$Id: test001.rdf,v 1.2 2002/11/22 13:52:15 jcarroll Exp $
|
206
|
+
|
207
|
+
-->
|
208
|
+
<rdf:RDF xmlns="http://www.w3.org/1999/xhtml"
|
209
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
210
|
+
xmlns:html="http://NoHTML.example.org"
|
211
|
+
xmlns:my="http://my.example.org/">
|
212
|
+
<rdf:Description rdf:ID="John_Smith">
|
213
|
+
<my:Name rdf:parseType="Literal">
|
214
|
+
<html:h1>
|
215
|
+
<b>John</b>
|
216
|
+
</html:h1>
|
217
|
+
</my:Name>
|
218
|
+
|
219
|
+
</rdf:Description>
|
220
|
+
</rdf:RDF>
|
221
|
+
EOF
|
222
|
+
|
223
|
+
graph = RdfXmlParser.new(sampledoc, "http://www.w3.org/2000/10/rdf-tests/rdfcore/rdfms-xml-literal-namespaces/test001.rdf")
|
224
|
+
graph.graph.to_ntriples.should == "<http://www.w3.org/2000/10/rdf-tests/rdfcore/rdfms-xml-literal-namespaces/test001.rdf#John_Smith> <http://my.example.org/Name> \"<html:h1>\n <b>John</b>\n </html:h1>\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .\n"
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should pass rdfms-syntax-incomplete-test001" do
|
228
|
+
sampledoc = <<-EOF;
|
229
|
+
<?xml version="1.0"?>
|
230
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
231
|
+
xmlns:eg="http://example.org/">
|
232
|
+
|
233
|
+
<rdf:Description rdf:nodeID="a">
|
234
|
+
<eg:property rdf:nodeID="a" />
|
235
|
+
</rdf:Description>
|
236
|
+
|
237
|
+
</rdf:RDF>
|
238
|
+
EOF
|
239
|
+
|
240
|
+
graph = RdfXmlParser.new(sampledoc)
|
241
|
+
graph.graph.size.should == 1
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should pass rdfms-syntax-incomplete-test002" do
|
245
|
+
sampledoc = <<-EOF;
|
246
|
+
<?xml version="1.0"?>
|
247
|
+
|
248
|
+
<!--
|
249
|
+
Copyright World Wide Web Consortium, (Massachusetts Institute of
|
250
|
+
Technology, Institut National de Recherche en Informatique et en
|
251
|
+
Automatique, Keio University).
|
252
|
+
|
253
|
+
All Rights Reserved.
|
254
|
+
|
255
|
+
Please see the full Copyright clause at
|
256
|
+
<http://www.w3.org/Consortium/Legal/copyright-software.html>
|
257
|
+
|
258
|
+
-->
|
259
|
+
<!--
|
260
|
+
|
261
|
+
rdf:nodeID can be used to label a blank node.
|
262
|
+
These have file scope and are distinct from any
|
263
|
+
unlabelled blank nodes.
|
264
|
+
$Id: test002.rdf,v 1.1 2002/07/30 09:46:05 jcarroll Exp $
|
265
|
+
|
266
|
+
-->
|
267
|
+
|
268
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
269
|
+
xmlns:eg="http://example.org/">
|
270
|
+
|
271
|
+
<rdf:Description rdf:nodeID="a">
|
272
|
+
<eg:property1 rdf:nodeID="a" />
|
273
|
+
</rdf:Description>
|
274
|
+
<rdf:Description>
|
275
|
+
<eg:property2>
|
276
|
+
|
277
|
+
<!-- Note the rdf:nodeID="b" is redundant. -->
|
278
|
+
<rdf:Description rdf:nodeID="b">
|
279
|
+
<eg:property3 rdf:nodeID="a" />
|
280
|
+
</rdf:Description>
|
281
|
+
</eg:property2>
|
282
|
+
</rdf:Description>
|
283
|
+
|
284
|
+
</rdf:RDF>
|
285
|
+
EOF
|
286
|
+
|
287
|
+
lambda do
|
288
|
+
graph = RdfXmlParser.new(sampledoc)
|
289
|
+
end.should_not raise_error
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should pass rdfms-syntax-incomplete/test003.rdf" do
|
293
|
+
sampledoc = <<-EOF;
|
294
|
+
<?xml version="1.0"?>
|
295
|
+
|
296
|
+
<!--
|
297
|
+
Copyright World Wide Web Consortium, (Massachusetts Institute of
|
298
|
+
Technology, Institut National de Recherche en Informatique et en
|
299
|
+
Automatique, Keio University).
|
300
|
+
|
301
|
+
All Rights Reserved.
|
302
|
+
|
303
|
+
Please see the full Copyright clause at
|
304
|
+
<http://www.w3.org/Consortium/Legal/copyright-software.html>
|
305
|
+
|
306
|
+
-->
|
307
|
+
<!--
|
308
|
+
|
309
|
+
On an rdf:Description or typed node rdf:nodeID behaves
|
310
|
+
similarly to an rdf:about.
|
311
|
+
$Id: test003.rdf,v 1.2 2003/07/24 15:51:06 jcarroll Exp $
|
312
|
+
|
313
|
+
-->
|
314
|
+
|
315
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
316
|
+
xmlns:eg="http://example.org/">
|
317
|
+
|
318
|
+
<!-- In this example the rdf:nodeID is redundant. -->
|
319
|
+
<rdf:Description rdf:nodeID="a" eg:property1="value" />
|
320
|
+
|
321
|
+
</rdf:RDF>
|
322
|
+
EOF
|
323
|
+
|
324
|
+
graph = RdfXmlParser.new(sampledoc)
|
325
|
+
graph.graph[0].subject.to_s.should == "a"
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should be able to handle Bags/Alts etc." do
|
329
|
+
sampledoc = <<-EOF;
|
330
|
+
<?xml version="1.0" ?>
|
331
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:eg="http://example.org/">
|
332
|
+
<rdf:Bag>
|
333
|
+
<rdf:li rdf:resource="http://tommorris.org/" />
|
334
|
+
<rdf:li rdf:resource="http://twitter.com/tommorris" />
|
335
|
+
</rdf:Bag>
|
336
|
+
</rdf:RDF>
|
337
|
+
EOF
|
338
|
+
graph = RdfXmlParser.new(sampledoc)
|
339
|
+
graph.graph[1].predicate.to_s.should == "http://www.w3.org/1999/02/22-rdf-syntax-ns#_1"
|
340
|
+
graph.graph[2].predicate.to_s.should == "http://www.w3.org/1999/02/22-rdf-syntax-ns#_2"
|
341
|
+
end
|
342
|
+
|
343
|
+
# # when we have decent Unicode support, add http://www.w3.org/2000/10/rdf-tests/rdfcore/rdfms-rdf-id/error005.rdf
|
344
|
+
#
|
345
|
+
# it "should support reification" do
|
346
|
+
# pending
|
347
|
+
# end
|
348
|
+
#
|
349
|
+
it "detect bad bagIDs" do
|
350
|
+
sampledoc = <<-EOF;
|
351
|
+
<?xml version="1.0" ?>
|
352
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
353
|
+
<rdf:Description rdf:bagID='333-555-666' />
|
354
|
+
</rdf:RDF>
|
355
|
+
EOF
|
356
|
+
|
357
|
+
lambda do
|
358
|
+
graph = RdfXmlParser.new(sampledoc)
|
359
|
+
end.should raise_error
|
360
|
+
end
|
361
|
+
|
362
|
+
describe "parsing rdf files" do
|
363
|
+
def test_file(filepath, uri = nil)
|
364
|
+
n3_string = File.read(filepath)
|
365
|
+
parser = RdfXmlParser.new(n3_string, uri)
|
366
|
+
ntriples = parser.graph.to_ntriples
|
367
|
+
ntriples.gsub!(/_:bn\d+/, '_:node1')
|
368
|
+
ntriples = ntriples.split("\n").sort.join("\n")
|
369
|
+
|
370
|
+
nt_string = File.read(filepath.sub('.rdf', '.nt'))
|
371
|
+
nt_string = nt_string.split("\n").sort.join("\n")
|
372
|
+
|
373
|
+
ntriples.should == nt_string
|
374
|
+
end
|
375
|
+
|
376
|
+
before(:all) do
|
377
|
+
@rdf_dir = File.join(File.dirname(__FILE__), '..', 'test', 'rdf_tests')
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should parse Coldplay's BBC Music profile" do
|
381
|
+
gid = 'cc197bad-dc9c-440d-a5b5-d52ba2e14234'
|
382
|
+
file = File.join(@rdf_dir, "#{gid}.rdf")
|
383
|
+
test_file(file, "http://www.bbc.co.uk/music/artists/#{gid}")
|
384
|
+
end
|
385
|
+
|
386
|
+
# it "should parse xml literal test" do
|
387
|
+
# file = File.join(@rdf_dir, "xml-literal-mixed.rdf")
|
388
|
+
# test_file(file)
|
389
|
+
# end
|
390
|
+
end
|
391
|
+
end
|