rdfa_parser 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,7 @@ rescue LoadError
17
17
  end
18
18
 
19
19
  module RdfaParser
20
+ VERSION = File.read(File.join(File.dirname(__FILE__), "..", "VERSION")).chop # Version in parent directory
20
21
  LINK_TYPES = %w(
21
22
  alternate appendix bookmark cite chapter contents copyright first glossary
22
23
  help icon index last license meta next p3pv1 prev role section stylesheet subsection
@@ -392,8 +392,9 @@ module RdfaParser
392
392
  BNode.new(suffix || "")
393
393
  elsif curie.to_s.empty?
394
394
  @debug << "curie_to_resource_or_bnode #{URIRef.new(subject)}"
395
- # Empty curie resolves to current subject
396
- URIRef.new(subject)
395
+ # Empty curie resolves to current subject (No, an empty curie should be ignored)
396
+ # URIRef.new(subject)
397
+ nil
397
398
  else
398
399
  ns = uri_mappings[prefix.to_s]
399
400
  raise ParserException, "No namespace mapping for #{prefix}" unless ns
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html version="XHTML+RDFa 1.0"
3
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
4
+ <head>
5
+ <title>Test 0011</title>
6
+ </head>
7
+ <body>
8
+ <div about="">
9
+ Author: <span property="dc:creator">Albert Einstein</span>
10
+ <h2 property="dc:title">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
11
+ </div>
12
+ </body>
13
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html
3
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
4
+ <head>
5
+ <title>Test 0011</title>
6
+ </head>
7
+ <body>
8
+ <div about="">
9
+ Author: <span property="dc:creator">Albert Einstein</span>
10
+ <h2 property="dc:title">E = mc<sup>2</sup>: The Most Urgent Problem of Our Time</h2>
11
+ </div>
12
+ </body>
13
+ </html>
@@ -18,6 +18,7 @@ module Matchers
18
18
  @sorted_actual.length == @sorted_expected.length
19
19
  end
20
20
  def failure_message_for_should
21
+ info = @info.respond_to?(:information) ? @info.information : ""
21
22
  if @last_line < @sorted_actual.length && @sorted_expected[@last_line]
22
23
  "Graph differs at entry #{@last_line}:\nexpected: #{@sorted_expected[@last_line].to_ntriples}\nactual: #{@sorted_actual[@last_line].to_ntriples}"
23
24
  elsif @last_line < @actual.triples.length
@@ -25,7 +26,7 @@ module Matchers
25
26
  else
26
27
  "Graph entry count differs:\nexpected: #{@sorted_expected.length}\nactual: #{@sorted_actual.length}"
27
28
  end +
28
- "\n\n#{@info + "\n" unless @info.empty?}" +
29
+ "\n\n#{info + "\n" unless info.empty?}" +
29
30
  "Unsorted Expected:\n#{@expected.to_ntriples}" +
30
31
  "Unsorted Results:\n#{@actual.to_ntriples}"
31
32
  end
@@ -44,25 +45,29 @@ module Matchers
44
45
  end
45
46
  def matches?(actual)
46
47
  @actual = actual
48
+ @expected_results = @info.respond_to?(:expectedResults) ? @info.expectedResults : true
47
49
  model = Redland::Model.new
48
50
  ntriples_parser = Redland::Parser.ntriples
49
51
  ntriples_parser.parse_string_into_model(model, actual.to_ntriples, "http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/")
50
52
 
51
53
  @results = @query.execute(model)
52
- if @expected.match(/(This test should result in a 'NO'|negative test case)/)
53
- @results.nil? || (@results.is_boolean? && !@results.get_boolean?)
54
- else
54
+ if @expected_results
55
55
  @results.is_boolean? && @results.get_boolean?
56
+ else
57
+ @results.nil? || @results.is_boolean? && !@results.get_boolean?
56
58
  end
57
59
  end
58
60
  def failure_message_for_should
59
- "#{@info + "\n" unless @info.empty?}" +
61
+ info = @info.respond_to?(:information) ? @info.information : ""
62
+ "#{info + "\n" unless info.empty?}" +
60
63
  if @results.nil?
61
64
  "Query failed to return results"
62
65
  elsif !@results.is_boolean?
63
66
  "Query returned non-boolean results"
64
- else
67
+ elsif @expected_results
65
68
  "Query returned false"
69
+ else
70
+ "Query returned true (expected false)"
66
71
  end +
67
72
  "\n#{@expected}" +
68
73
  "\nResults:\n#{@actual.to_ntriples}"
@@ -16,14 +16,15 @@ module RdfaHelper
16
16
  attr_accessor :purpose
17
17
  attr_accessor :reviewStatus
18
18
  attr_accessor :specificationReference
19
- attr_accessor :expected_results
19
+ attr_accessor :expectedResults
20
20
 
21
21
  @@test_cases = []
22
22
 
23
23
  def initialize(statements)
24
- expected_results = true
24
+ self.expectedResults = true
25
25
  statements.each do |statement|
26
26
  next if statement.subject.is_a?(Redland::BNode)
27
+ #next unless statement.subject.uri.short_name == "Test0122"
27
28
  unless self.about
28
29
  self.about = URI.parse(statement.subject.uri.to_s)
29
30
  self.name = statement.subject.uri.short_name
@@ -35,6 +36,9 @@ module RdfaHelper
35
36
  elsif statement.predicate.uri.short_name == "informationResourceResults"
36
37
  self.informationResourceResults = statement.object.uri.to_s.sub!(/^.*xhtml1-testcases/, TEST_DIR)
37
38
  self.originalInformationResourceResults = statement.object.uri.to_s
39
+ elsif statement.predicate.uri.short_name == "expectedResults"
40
+ self.expectedResults = statement.object.literal.value == "true"
41
+ #puts "expectedResults = #{statement.object.literal.value}"
38
42
  elsif self.respond_to?("#{statement.predicate.uri.short_name}=")
39
43
  s = case
40
44
  when statement.object.literal? then statement.object.literal
@@ -47,12 +51,16 @@ module RdfaHelper
47
51
  end
48
52
  end
49
53
 
54
+ def status
55
+ reviewStatus.to_s.split("#").last
56
+ end
57
+
50
58
  def information
51
59
  %w(purpose specificationReference).map {|a| v = self.send(a); "#{a}: #{v}" if v}.compact.join("\n")
52
60
  end
53
61
 
54
- def self.parse_test_cases
55
- return unless @@test_cases.empty?
62
+ def self.test_cases
63
+ return @@test_cases unless @@test_cases.empty?
56
64
 
57
65
  manifest = File.read(File.join(TEST_DIR, "rdfa-xhtml1-test-manifest.rdf"))
58
66
  rdfxml_parser = Redland::Parser.new
@@ -64,11 +72,9 @@ module RdfaHelper
64
72
 
65
73
  @@test_cases = test_hash.values.map {|statements| TestCase.new(statements)}.
66
74
  compact.
67
- select{|t| t.reviewStatus == "http://www.w3.org/2006/03/test-description#approved"}.
75
+ select{|t| t.status != "rejected"}.
68
76
  sort_by{|t| t.about.is_a?(URI) ? t.about.to_s : "zzz"}
69
77
  end
70
-
71
- def self.test_cases; parse_test_cases; @@test_cases; end
72
78
  end
73
79
  end
74
80
 
@@ -104,7 +110,6 @@ class NTriplesParser
104
110
  end
105
111
 
106
112
  def redland_to_native(resource)
107
- # puts resource.inspect
108
113
  case
109
114
  when resource.literal?
110
115
  node_type = Redland.librdf_node_get_literal_value_datatype_uri(resource.literal.node)
@@ -88,15 +88,15 @@ describe "RDFa parser" do
88
88
  xml.should include("Manu Sporny")
89
89
  end
90
90
 
91
+ def self.test_cases
92
+ RdfaHelper::TestCase.test_cases
93
+ end
94
+
91
95
  # W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
92
96
  describe "w3c xhtml1 testcases" do
93
- def self.test_cases
94
- RdfaHelper::TestCase.test_cases
95
- end
96
-
97
97
  test_cases.each do |t|
98
- #next unless t.name == "Test0100"
99
- specify "test #{t.name}: #{t.title}" do
98
+ #next unless t.name == "Test0122"
99
+ specify "#{t.status} test #{t.name}: #{t.title}" do
100
100
  rdfa_string = File.read(t.informationResourceInput)
101
101
  rdfa_parser = RdfaParser::RdfaParser.new
102
102
  rdfa_parser.parse(rdfa_string, t.originalInformationResourceInput)
@@ -107,9 +107,9 @@ describe "RDFa parser" do
107
107
  # Check triples, as Rasql doesn't implement UNION
108
108
  ntriples = File.read(t.informationResourceResults.sub("sparql", "nt"))
109
109
  parser = NTriplesParser.new(ntriples)
110
- rdfa_parser.graph.should be_equivalent_graph(parser.graph, t.information)
110
+ rdfa_parser.graph.should be_equivalent_graph(parser.graph, t)
111
111
  else
112
- rdfa_parser.graph.should pass_query(query_string, t.information)
112
+ rdfa_parser.graph.should pass_query(query_string, t)
113
113
  end
114
114
 
115
115
  rdfa_parser.graph.to_rdfxml.should be_valid_xml
@@ -0,0 +1 @@
1
+ <http://example.com/9999.xhtml> <http://example.com/ex#script> <http://example.com/javascripts/jrails.js> .
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
3
+ "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ex="http://example.com/ex#">
5
+ <head about="http://example.com/9998.xhtml">
6
+ <script src="/javascripts/jrails.js" rev="ex:script" resource="http://example.com/9998.xhtml" type="text/javascript"></script>
7
+ </head>
8
+ </html>
@@ -1,3 +0,0 @@
1
- <http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js> <http://cmx.org/spec/cmxterms#script> "" .
2
- <http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/9999.xhtml> <http://cmx.org/spec/cmxterms#script> "foo"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
3
- <http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/9999.xhtml> <http://www.w3.org/1999/xhtml/vocab#stylesheet> <http://www.w3.org/stylesheets/cmx.css?1249860775> .
@@ -1,14 +1,8 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
3
3
  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
4
- <html xmlns="http://www.w3.org/1999/xhtml">
5
- <head>
6
- <title>Test 999</title>
7
- <link href="/stylesheets/cmx.css?1249860775" media="screen" rel="stylesheet" type="text/css">
8
- <link rel="profile" href="http://purl.org/uF/hCard/1.0/">
9
- <script xmlns:cmxterms="http://cmx.org/spec/cmxterms#" property="cmxterms:script" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
10
- <script xmlns:cmxterms="http://cmx.org/spec/cmxterms#" property="cmxterms:script" type="text/javascript">foo</script>
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ex="http://example.com/ex#">
5
+ <head about="http://example.com/9999.xhtml">
6
+ <script src="/javascripts/jrails.js" rev="ex:script" resource="[]" type="text/javascript"></script>
11
7
  </head>
12
- <body>
13
- </body>
14
8
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdfa_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-18 00:00:00 -07:00
12
+ date: 2009-10-25 00:00:00 -07:00
13
13
  default_executable: rdfa_parser
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,7 @@ files:
78
78
  - Rakefile
79
79
  - VERSION
80
80
  - bin/rdfa_parser
81
+ - earl-xhtml1-approved.txt
81
82
  - lib/rdfa_parser.rb
82
83
  - lib/rdfa_parser/bnode.rb
83
84
  - lib/rdfa_parser/exceptions.rb
@@ -92,6 +93,8 @@ files:
92
93
  - script/generate
93
94
  - spec/bnode_spec.rb
94
95
  - spec/graph_spec.rb
96
+ - spec/html4-testcases/0011.html
97
+ - spec/html5-testcases/0011.html
95
98
  - spec/literal_spec.rb
96
99
  - spec/matchers.rb
97
100
  - spec/namespace_spec.rb
@@ -440,6 +443,8 @@ files:
440
443
  - spec/xhtml1-testcases/1001.nt
441
444
  - spec/xhtml1-testcases/1001.sparql
442
445
  - spec/xhtml1-testcases/1001.xhtml
446
+ - spec/xhtml1-testcases/9998.nt
447
+ - spec/xhtml1-testcases/9998.xhtml
443
448
  - spec/xhtml1-testcases/9999.nt
444
449
  - spec/xhtml1-testcases/9999.xhtml
445
450
  - spec/xhtml1-testcases/rdfa-xhtml1-test-manifest.rdf