rdf-rdfa 0.0.1 → 0.0.2

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.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/rdf/rdfa.rb'}"
9
+ puts "Loading rdf-rdfa gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,173 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe RDF::RDFa::Format do
4
+ it "should be discoverable" do
5
+ formats = [
6
+ RDF::Format.for(:rdfa),
7
+ RDF::Format.for("etc/foaf.html"),
8
+ RDF::Format.for(:file_name => "etc/foaf.html"),
9
+ RDF::Format.for(:file_extension => "html"),
10
+ RDF::Format.for(:file_extension => "xhtml"),
11
+ RDF::Format.for(:content_type => "text/html"),
12
+ RDF::Format.for(:content_type => "application/xhtml+xml"),
13
+ ]
14
+ formats.each { |format| format.should == RDF::RDFa::Format }
15
+ end
16
+ end
17
+
18
+ describe "RDF::RDFa::Reader" do
19
+ it "should be discoverable" do
20
+ readers = [
21
+ RDF::Reader.for(:rdfa),
22
+ RDF::Reader.for("etc/foaf.html"),
23
+ RDF::Reader.for(:file_name => "etc/foaf.html"),
24
+ RDF::Reader.for(:file_extension => "html"),
25
+ RDF::Reader.for(:file_extension => "xhtml"),
26
+ RDF::Reader.for(:content_type => "text/html"),
27
+ RDF::Reader.for(:content_type => "application/xhtml+xml"),
28
+ ]
29
+ readers.each { |reader| reader.should == RDF::RDFa::Reader }
30
+ end
31
+
32
+ it "should parse simple doc" do
33
+ sampledoc = <<-EOF;
34
+ <?xml version="1.0" encoding="UTF-8"?>
35
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
36
+ <html xmlns="http://www.w3.org/1999/xhtml"
37
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
38
+ <head>
39
+ <title>Test 0001</title>
40
+ </head>
41
+ <body>
42
+ <p>This photo was taken by <span class="author" about="photo1.jpg" property="dc:creator">Mark Birbeck</span>.</p>
43
+ </body>
44
+ </html>
45
+ EOF
46
+
47
+ reader = RDF::RDFa::Reader.new(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0001.xhtml", :strict => true)
48
+ reader.graph.size.should == 1
49
+ reader.graph.should have_object("Mark Birbeck")
50
+ end
51
+
52
+ it "should parse simple doc without a base URI" do
53
+ sampledoc = <<-EOF;
54
+ <?xml version="1.0" encoding="UTF-8"?>
55
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
56
+ <html xmlns="http://www.w3.org/1999/xhtml"
57
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
58
+ <body>
59
+ <p>This photo was taken by <span class="author" about="_:photo" property="dc:creator">Mark Birbeck</span>.</p>
60
+ </body>
61
+ </html>
62
+ EOF
63
+
64
+ reader = RDF::RDFa::Reader.new(sampledoc, :strict => true)
65
+ reader.graph.size.should == 1
66
+ reader.graph.should have_triple([RDF::Node('photo'), RDF::DC11.creator, "Mark Birbeck"])
67
+ end
68
+
69
+ it "should parse an XML Literal" do
70
+ sampledoc = <<-EOF
71
+ <?xml version="1.0" encoding="UTF-8"?>
72
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
73
+ <html xmlns="http://www.w3.org/1999/xhtml"
74
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
75
+ <head>
76
+ <title>Test 0011</title>
77
+ </head>
78
+ <body>
79
+ <div about="">
80
+ Author: <span property="dc:creator">Albert Einstein</span>
81
+ <h2 property="dc:title">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
82
+ </div>
83
+ </body>
84
+ </html>
85
+ EOF
86
+
87
+ reader = RDF::RDFa::Reader.new(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :strict => true)
88
+ reader.graph.size.should == 2
89
+
90
+ reader.graph.should have_object("Albert Einstein")
91
+ reader.graph.should have_object(
92
+ RDF::Literal("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time",
93
+ :datatype => RDF.XMLLiteral)
94
+ )
95
+ end
96
+
97
+
98
+ it "should parse BNodes" do
99
+ sampledoc = <<-EOF
100
+ <?xml version="1.0" encoding="UTF-8"?>
101
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
102
+ <html xmlns="http://www.w3.org/1999/xhtml"
103
+ xmlns:foaf="http://xmlns.com/foaf/0.1/">
104
+ <head>
105
+ <title>Test 0017</title>
106
+ </head>
107
+ <body>
108
+ <p>
109
+ <span about="[_:a]" property="foaf:name">Manu Sporny</span>
110
+ <span about="[_:a]" rel="foaf:knows" resource="[_:b]">knows</span>
111
+ <span about="[_:b]" property="foaf:name">Ralph Swick</span>.
112
+ </p>
113
+ </body>
114
+ </html>
115
+ EOF
116
+
117
+ reader = RDF::RDFa::Reader.new(sampledoc, :base_uri => "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/0011.xhtml", :strict => true)
118
+
119
+ reader.graph.size.should == 3
120
+ reader.graph.should have_object("Ralph Swick")
121
+ reader.graph.should have_object("Manu Sporny")
122
+ end
123
+
124
+ def self.test_cases(suite)
125
+ [] #RdfaHelper::TestCase.test_cases(suite)
126
+ end
127
+
128
+ # W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
129
+ %w(xhtml html4 html5).each do |suite|
130
+ describe "w3c #{suite} testcases" do
131
+ describe "that are approved" do
132
+ test_cases(suite).each do |t|
133
+ puts t.inspect
134
+ next unless t.status == "approved"
135
+ #next unless t.name =~ /0140/
136
+ specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
137
+ #puts t.input
138
+ #puts t.results
139
+ begin
140
+ t.run_test do |rdfa_string, rdfa_parser|
141
+ rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [])
142
+ end
143
+ rescue SparqlException => e
144
+ pending(e.message) { raise }
145
+ end
146
+ end
147
+ end
148
+ end
149
+ describe "that are unreviewed" do
150
+ test_cases(suite).each do |t|
151
+ next unless t.status == "unreviewed"
152
+ #next unless t.name =~ /0185/
153
+ #puts t.inspect
154
+ specify "test #{t.name}: #{t.title}#{", (negative test)" unless t.expectedResults}" do
155
+ begin
156
+ t.run_test do |rdfa_string, rdfa_parser|
157
+ rdfa_parser.parse(rdfa_string, t.informationResourceInput, :debug => [])
158
+ end
159
+ rescue SparqlException => e
160
+ pending(e.message) { raise }
161
+ rescue Spec::Expectations::ExpectationNotMetError => e
162
+ if t.name =~ /01[789]\d/
163
+ raise
164
+ else
165
+ pending() { raise }
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -3,6 +3,9 @@ $:.unshift File.dirname(__FILE__)
3
3
 
4
4
  require 'rubygems'
5
5
  require 'spec'
6
- require 'rdfa/reader'
6
+ require 'rdf/rdfa'
7
+ require 'rdf/spec'
7
8
 
8
- include RDFa
9
+ Spec::Runner.configure do |config|
10
+ config.include(RDF::Spec::Matchers)
11
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-rdfa
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Gregg Kellogg
@@ -15,63 +16,101 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-06-02 00:00:00 -07:00
19
+ date: 2010-06-03 00:00:00 -07:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
- name: nokogiri
23
+ name: rdf
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ">="
27
29
  - !ruby/object:Gem::Version
30
+ hash: 23
31
+ segments:
32
+ - 0
33
+ - 1
34
+ - 6
35
+ version: 0.1.6
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: nokogiri
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 29
28
47
  segments:
29
48
  - 1
30
49
  - 3
31
50
  - 3
32
51
  version: 1.3.3
33
52
  type: :runtime
34
- version_requirements: *id001
53
+ version_requirements: *id002
35
54
  - !ruby/object:Gem::Dependency
36
- name: rdf
55
+ name: patron
37
56
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
39
59
  requirements:
40
60
  - - ">="
41
61
  - !ruby/object:Gem::Version
62
+ hash: 3
42
63
  segments:
43
64
  - 0
44
- - 1
65
+ - 4
45
66
  - 6
46
- version: 0.1.6
67
+ version: 0.4.6
47
68
  type: :runtime
48
- version_requirements: *id002
69
+ version_requirements: *id003
49
70
  - !ruby/object:Gem::Dependency
50
71
  name: rspec
51
72
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
53
75
  requirements:
54
76
  - - ">="
55
77
  - !ruby/object:Gem::Version
78
+ hash: 3
56
79
  segments:
57
80
  - 0
58
81
  version: "0"
59
82
  type: :development
60
- version_requirements: *id003
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdf-spec
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ type: :development
97
+ version_requirements: *id005
61
98
  - !ruby/object:Gem::Dependency
62
99
  name: activesupport
63
100
  prerelease: false
64
- requirement: &id004 !ruby/object:Gem::Requirement
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
+ none: false
65
103
  requirements:
66
104
  - - ">="
67
105
  - !ruby/object:Gem::Version
106
+ hash: 3
68
107
  segments:
69
108
  - 2
70
109
  - 3
71
110
  - 0
72
111
  version: 2.3.0
73
112
  type: :development
74
- version_requirements: *id004
113
+ version_requirements: *id006
75
114
  description: " RDF::RDFa is an RDFa parser for Ruby using the RDF.rb library suite.\n"
76
115
  email: gregg@kellogg-assoc.com
77
116
  executables: []
@@ -79,19 +118,27 @@ executables: []
79
118
  extensions: []
80
119
 
81
120
  extra_rdoc_files:
121
+ - AUTHORS
82
122
  - History.txt
83
123
  - README.rdoc
84
124
  files:
125
+ - AUTHORS
126
+ - History.txt
85
127
  - README.rdoc
86
128
  - Rakefile
87
129
  - VERSION
130
+ - etc/foaf.html
131
+ - etc/xhv.html
88
132
  - example.rb
89
- - lib/rdfa/format.rb
90
- - lib/rdfa/reader.rb
91
- - lib/rdfa/reader/exceptions.rb
92
- - lib/rdfa/reader/namespace.rb
93
- - lib/rdfa/reader/version.rb
94
- - spec/namespaces_spec.rb
133
+ - lib/rdf/rdfa.rb
134
+ - lib/rdf/rdfa/format.rb
135
+ - lib/rdf/rdfa/reader.rb
136
+ - lib/rdf/rdfa/reader/exceptions.rb
137
+ - lib/rdf/rdfa/version.rb
138
+ - lib/rdf/rdfa/vocab.rb
139
+ - pkg/.gitignore
140
+ - rdf-rdfa.gemspec
141
+ - script/console
95
142
  - spec/rdfa-triples/0001.nt
96
143
  - spec/rdfa-triples/0006.nt
97
144
  - spec/rdfa-triples/0007.nt
@@ -205,10 +252,9 @@ files:
205
252
  - spec/rdfa-triples/0126.nt
206
253
  - spec/rdfa-triples/1001.nt
207
254
  - spec/rdfa_helper.rb
208
- - spec/rdfa_parser_spec.rb
255
+ - spec/rdfa_reader_spec.rb
209
256
  - spec/spec.opts
210
257
  - spec/spec_helper.rb
211
- - History.txt
212
258
  has_rdoc: true
213
259
  homepage: http://github.com/gkellogg/rdf-rdfa
214
260
  licenses: []
@@ -219,28 +265,31 @@ rdoc_options:
219
265
  require_paths:
220
266
  - lib
221
267
  required_ruby_version: !ruby/object:Gem::Requirement
268
+ none: false
222
269
  requirements:
223
270
  - - ">="
224
271
  - !ruby/object:Gem::Version
272
+ hash: 3
225
273
  segments:
226
274
  - 0
227
275
  version: "0"
228
276
  required_rubygems_version: !ruby/object:Gem::Requirement
277
+ none: false
229
278
  requirements:
230
279
  - - ">="
231
280
  - !ruby/object:Gem::Version
281
+ hash: 3
232
282
  segments:
233
283
  - 0
234
284
  version: "0"
235
285
  requirements: []
236
286
 
237
287
  rubyforge_project:
238
- rubygems_version: 1.3.6
288
+ rubygems_version: 1.3.7
239
289
  signing_key:
240
290
  specification_version: 3
241
291
  summary: RDFa parser for RDF.rb.
242
292
  test_files:
243
- - spec/namespaces_spec.rb
244
293
  - spec/rdfa_helper.rb
245
- - spec/rdfa_parser_spec.rb
294
+ - spec/rdfa_reader_spec.rb
246
295
  - spec/spec_helper.rb
@@ -1,19 +0,0 @@
1
- module RDF::RDFa
2
- ##
3
- # N-Triples format specification.
4
- #
5
- # @example Obtaining an NTriples format class
6
- # RDF::Format.for(:ntriples) #=> RDF::NTriples::Format
7
- # RDF::Format.for("etc/doap.nt")
8
- # RDF::Format.for(:file_name => "etc/doap.nt")
9
- # RDF::Format.for(:file_extension => "nt")
10
- # RDF::Format.for(:content_type => "text/plain")
11
- #
12
- # @see http://www.w3.org/TR/rdf-testcases/#ntriples
13
- class Format < RDF::Format
14
- content_type 'text/html', :extension => :html
15
- content_encoding 'ascii'
16
-
17
- reader { RDFa::Reader }
18
- end
19
- end
@@ -1,72 +0,0 @@
1
- module RDF::RDFa class Reader
2
- # From RdfContext
3
- class Namespace
4
- attr_accessor :prefix, :fragment
5
-
6
- # Creates a new namespace given a URI and the prefix.
7
- def initialize(uri, prefix)
8
- prefix = prefix.to_s
9
-
10
- @uri = uri.to_s
11
-
12
- raise ParserException, "Invalid prefix '#{prefix}'" unless prefix_valid?(prefix)
13
- @prefix = prefix
14
- end
15
-
16
- # Allows the construction of arbitrary URIs on the namespace.
17
- def method_missing(methodname, *args)
18
- self + methodname
19
- end
20
-
21
- # Construct a URIRef from a namespace as in method_missing, but without method collision issues.
22
- # Rules are somewhat different than for normal URI unions, as the raw URI is used as the source,
23
- # not a normalized URI, and the result is not normalized
24
- def +(suffix)
25
- prefix = @uri
26
- suffix = suffix.to_s.sub(/^\#/, "") if prefix.index("#")
27
- suffix = suffix.to_s.sub(/_$/, '')
28
- # FIXME: URIRef.new(prefix + suffix.to_s, :normalize => false, :namespace => self)
29
- RDF::URI.new(prefix + suffix.to_s)
30
- end
31
-
32
- # Make sure to attach fragment
33
- def uri
34
- self + ""
35
- end
36
-
37
- # Bind this namespace to a Graph
38
- def bind(graph)
39
- graph.bind(self)
40
- end
41
-
42
- # Compare namespaces
43
- def eql?(other)
44
- self.uri == other.uri
45
- end
46
- alias_method :==, :eql?
47
-
48
- # Output xmlns attribute name
49
- def xmlns_attr
50
- prefix.empty? ? "xmlns" : "xmlns:#{prefix}"
51
- end
52
-
53
- # Output namespace definition as a hash
54
- def xmlns_hash
55
- {xmlns_attr => @uri.to_s}
56
- end
57
-
58
- def to_s
59
- "#{prefix}: #{@uri}"
60
- end
61
-
62
- def inspect
63
- "Namespace[abbr='#{prefix}',uri='#{@uri}']"
64
- end
65
-
66
- private
67
- # The Namespace prefix must be an NCName
68
- def prefix_valid?(prefix)
69
- NC_REGEXP.match(prefix.to_s) || prefix.to_s.empty?
70
- end
71
- end
72
- end end