public
Rubygem
Description: Rena is a Ruby RDF library that I'm trying to help extend.
Clone URL: git://github.com/tommorris/rena.git
started adding RDF Test Cases tests (2004), and building out the parser so 
it passes the tests
tommorris (author)
Sat Jul 05 09:15:36 -0700 2008
commit  ab667ef5dfb591b375f82b8239d3d45d9f1987a8
tree    850cf374982d121e07289dbe9149b7069048c85e
parent  80165dc118a1aa9a21a4afe279f2ab069a9030a7
...
2
3
4
 
5
6
7
...
41
42
43
 
 
 
 
 
 
44
45
46
...
76
77
78
79
80
81
82
83
84
 
 
 
 
 
 
 
 
 
 
 
85
86
87
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
2
3
4
5
6
7
8
...
42
43
44
45
46
47
48
49
50
51
52
53
...
83
84
85
 
 
 
 
 
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
0
@@ -2,6 +2,7 @@ require 'lib/uriref'
0
 require 'lib/graph'
0
 require 'lib/literal'
0
 require 'lib/exceptions/uri_relative_exception'
0
+require 'lib/exceptions/about_each_exception'
0
 require 'lib/rexml_hacks'
0
 
0
 class RdfXmlParser
0
@@ -41,6 +42,12 @@ class RdfXmlParser
0
     element.attributes.each_attribute { |att|
0
       uri = att.namespace + att.name
0
       value = att.to_s
0
+ if uri == "http://www.w3.org/1999/02/22-rdf-syntax-ns#aboutEach"
0
+ raise AboutEachException, "Failed as per RDFMS-AboutEach-Error001.rdf test from 2004 test suite"
0
+ end
0
+ if uri == "http://www.w3.org/1999/02/22-rdf-syntax-ns#aboutEachPrefix"
0
+ raise AboutEachException, "Failed as per RDFMS-AboutEach-Error002.rdf test from 2004 test suite"
0
+ end
0
       if uri == resourceuri #specified resource
0
         begin
0
           possible_subject = URIRef.new(value)
0
@@ -76,12 +83,17 @@ class RdfXmlParser
0
         end
0
       end
0
       
0
- # if uri == "http://www.w3.org/1999/02/22-rdf-syntax-ns#ID"
0
- # begin
0
- #
0
- # rescue UriRelativeException
0
- # end
0
- # end
0
+ if uri == "http://www.w3.org/1999/02/22-rdf-syntax-ns#ID"
0
+ begin
0
+ # check for base
0
+ if att.element.base?
0
+ subject = att.element.base.to_s + value
0
+ else
0
+ raise "Needs to have an ID"
0
+ end
0
+# rescue UriRelativeException
0
+ end
0
+ end
0
 
0
       # add other subject detection subroutines here
0
     }
0
@@ -118,37 +130,6 @@ class RdfXmlParser
0
 
0
     # element parsing
0
     element.each_element { |e|
0
- # uri = e.namespace + e.name
0
- # # if e.get_attribute_ns("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "parseType").to_s == "Literal"
0
- # if e.attributes.get_attribute_ns("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "parseType").to_s == "Literal"
0
- # @graph.add_triple(subject, URIRef.new(uri), TypedLiteral.new(e.children.to_s.strip, "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"))
0
- # elsif e.has_elements?
0
- # # subparsing
0
- # e.each_element { |se| #se = 'striped element'
0
- # if e.attributes.get_attribute_ns("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "parseType").to_s == "Resource"
0
- # object = BNode.new
0
- # else
0
- # object = self.get_uri_from_atts(se, true)
0
- # # @graph.add_triple(subject, URIRef.new(uri), object)
0
- # # self.parse_element(se, object)
0
- # end
0
- # @graph.add_triple(subject, URIRef.new(uri), object)
0
- # self.parse_element(se, object, true)
0
- # }
0
- # elsif e.has_attributes?
0
- # # get object out
0
- # object = self.get_uri_from_atts(e)
0
- # @graph.add_triple(subject, URIRef.new(uri), object)
0
- # if e.attributes.get_attribute_ns("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "datatype")
0
- # @graph.add_triple(subject, URIRef.new(uri), TypedLiteral.new(e.text, e.attributes.get_attribute_ns("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "datatype").to_s.strip))
0
- # end
0
- # elsif e.has_text?
0
- # if e.lang?
0
- # @graph.add_triple(subject, URIRef.new(uri), Literal.new(e.text, e.lang))
0
- # else
0
- # @graph.add_triple(subject, URIRef.new(uri), Literal.new(e.text))
0
- # end
0
- # end
0
       self.parse_resource_element e, subject
0
     }
0
   end
...
14
15
16
17
18
 
 
19
20
21
...
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
34
 
 
 
 
 
 
 
 
 
 
 
35
36
37
38
...
14
15
16
 
 
17
18
19
20
21
...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
0
@@ -14,8 +14,8 @@ describe "RDF/XML Parser" do
0
     sampledoc = <<-EOF;
0
     <?xml version="1.0" ?>
0
     <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
0
- xmlns:ex="http://www.example.org/" xml:lang="en">
0
- <rdf:Description rdf:about="http://www.example.org/foo" ex:name="bar">
0
+ xmlns:ex="http://www.example.org/" xml:lang="en" xml:base="http://www.example.org/foo">
0
+ <rdf:Description rdf:about="#" ex:name="bar">
0
         <ex:belongsTo rdf:resource="http://tommorris.org/" />
0
         <ex:sampleText rdf:datatype="http://www.w3.org/2001/XMLSchema#string">foo</ex:sampleText>
0
         <ex:hadADodgyRelationshipWith rdf:parseType="Resource">
0
@@ -30,8 +30,108 @@ describe "RDF/XML Parser" do
0
     graph.graph.size == 6
0
 # print graph.graph.to_ntriples
0
   end
0
+
0
+ it "should raise an error if rdf:aboutEach is used, as per the negative parser test rdfms-abouteach-error001 (rdf:aboutEach attribute)" do
0
+ sampledoc = <<-EOF;
0
+ <?xml version="1.0" ?>
0
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
0
+ xmlns:eg="http://example.org/">
0
+
0
+ <rdf:Bag rdf:ID="node">
0
+ <rdf:li rdf:resource="http://example.org/node2"/>
0
+ </rdf:Bag>
0
+
0
+ <rdf:Description rdf:aboutEach="#node">
0
+ <dc:rights xmlns:dc="http://purl.org/dc/elements/1.1/">me</dc:rights>
0
+
0
+ </rdf:Description>
0
+
0
+ </rdf:RDF>
0
+ EOF
0
+
0
+ lambda do
0
+ graph = RdfXmlParser.new(sampledoc)
0
+ end.should raise_error
0
+ end
0
+
0
+ it "should raise an error if rdf:aboutEachPrefix is used, as per the negative parser test rdfms-abouteach-error002 (rdf:aboutEachPrefix attribute)" do
0
+ sampledoc = <<-EOF;
0
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
0
+ xmlns:eg="http://example.org/">
0
+
0
+ <rdf:Description rdf:about="http://example.org/node">
0
+ <eg:property>foo</eg:property>
0
+ </rdf:Description>
0
+
0
+ <rdf:Description rdf:aboutEachPrefix="http://example.org/">
0
+ <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">me</dc:creator>
0
+
0
+ </rdf:Description>
0
+
0
+ </rdf:RDF>
0
+ EOF
0
+
0
+ lambda do
0
+ graph = RdfXmlParser.new(sampledoc)
0
+ end.should raise_error
0
+ end
0
+
0
+ it "should fail if given a non-ID as an ID (as per rdfcore-rdfms-rdf-id-error001)" do
0
+ sampledoc = <<-EOF;
0
+ <?xml version="1.0"?>
0
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
0
+ <rdf:Description rdf:ID='333-555-666' />
0
+ </rdf:RDF>
0
+ EOF
0
+
0
+ lambda do
0
+ graph = RdfXmlParser.new(sampledoc)
0
+ end.should raise_error
0
+ end
0
+
0
+ it "should make sure that the value of rdf:ID attributes match the XML Name production (child-element version)" do
0
+ sampledoc = <<-EOF;
0
+ <?xml version="1.0" ?>
0
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
0
+ xmlns:eg="http://example.org/">
0
+ <rdf:Description>
0
+ <eg:prop rdf:ID="q:name" />
0
+ </rdf:Description>
0
+ </rdf:RDF>
0
+ EOF
0
+
0
+ lambda do
0
+ graph = RdfXmlParser.new(sampledoc)
0
+ end.should raise_error
0
+ end
0
+
0
+ it "should make sure that the value of rdf:ID attributes match the XML Name production (data attribute version)" do
0
+ sampledoc = <<-EOF;
0
+ <?xml version="1.0" ?>
0
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
0
+ xmlns:eg="http://example.org/">
0
+ <rdf:Description rdf:ID="a/b" eg:prop="val" />
0
+ </rdf:RDF>
0
+ EOF
0
+
0
+ lambda do
0
+ graph = RdfXmlParser.new(sampledoc)
0
+ end.should raise_error
0
+ end
0
+
0
+ # when we have decent Unicode support, add http://www.w3.org/2000/10/rdf-tests/rdfcore/rdfms-rdf-id/error005.rdf
0
   
0
- it "should conform to the striping pattern" do
0
+ it "detect bad bagIDs" do
0
+ # sampledoc = <<-EOF;
0
+ # <?xml version="1.0" ?>
0
+ # <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
0
+ # <rdf:Description rdf:bagID='333-555-666' />
0
+ # </rdf:RDF>
0
+ # EOF
0
+ #
0
+ # lambda do
0
+ # graph = RdfXmlParser.new(sampledoc)
0
+ # end.should raise_error
0
     pending
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.