diff --git a/Gemfile.lock b/Gemfile.lock index 2b4cf91..627a2b8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -35,7 +35,7 @@ GEM rspec-expectations (~> 2.11.0) rspec-mocks (~> 2.11.0) rspec-core (2.11.1) - rspec-expectations (2.11.2) + rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.2) spira (0.0.12) diff --git a/etc/registry.json b/etc/registry.json index 062158f..79f6346 100644 --- a/etc/registry.json +++ b/etc/registry.json @@ -3,21 +3,32 @@ "propertyURI": "vocabulary", "multipleValues": "unordered", "properties": { + "additionalType": {"subPropertyOf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, + "blogPosts": {"multipleValues": "list"}, "blogPosts": {"multipleValues": "list"}, "breadcrumb": {"multipleValues": "list"}, "byArtist": {"multipleValues": "list"}, "creator": {"multipleValues": "list"}, + "episode": {"multipleValues": "list"}, "episodes": {"multipleValues": "list"}, + "event": {"multipleValues": "list"}, "events": {"multipleValues": "list"}, + "founder": {"multipleValues": "list"}, "founders": {"multipleValues": "list"}, "itemListElement": {"multipleValues": "list"}, "musicGroupMember": {"multipleValues": "list"}, "performerIn": {"multipleValues": "list"}, + "actor": {"multipleValues": "list"}, + "actors": {"multipleValues": "list"}, + "performer": {"multipleValues": "list"}, "performers": {"multipleValues": "list"}, "producer": {"multipleValues": "list"}, "recipeInstructions": {"multipleValues": "list"}, + "season": {"multipleValues": "list"}, "seasons": {"multipleValues": "list"}, + "subEvent": {"multipleValues": "list"}, "subEvents": {"multipleValues": "list"}, + "track": {"multipleValues": "list"}, "tracks": {"multipleValues": "list"} } }, diff --git a/lib/rdf/microdata/reader.rb b/lib/rdf/microdata/reader.rb index d58f62c..813ce9b 100644 --- a/lib/rdf/microdata/reader.rb +++ b/lib/rdf/microdata/reader.rb @@ -50,7 +50,7 @@ def self.load_registry(registry_uri) return if @registry_uri == registry_uri json = RDF::Util::File.open_file(registry_uri) { |f| JSON.load(f) } - + @prefixes = {} json.each do |prefix, elements| next unless elements.is_a?(Hash) @@ -227,6 +227,7 @@ def initialize(input = $stdin, options = {}, &block) # Load registry begin registry_uri = options[:registry_uri] || DEFAULT_REGISTRY + add_debug(@doc, "registry = #{registry_uri}") Registry.load_registry(registry_uri) rescue JSON::ParserError => e raise RDF::ReaderError, "Failed to parse registry: #{e.message}" @@ -458,6 +459,7 @@ def generatePropertyValues(element, subject, predicate, values) # If the registry contains a URI prefix that is a character for character match of predicate up to the length # of the URI prefix, set vocab as that URI prefix. Otherwise set vocab to null registry = Registry.find(predicate) + add_debug("generatePropertyValues") { "list(#{predicate})? #{registry.as_list(predicate).inspect}"} if registry if registry && registry.as_list(predicate) value = generateRDFCollection(element, values) add_triple(element, subject, predicate, value) diff --git a/spec/suite_helper.rb b/spec/suite_helper.rb index 21fd933..2bfa0a6 100644 --- a/spec/suite_helper.rb +++ b/spec/suite_helper.rb @@ -21,10 +21,12 @@ module File # @yield [IO] File stream def self.open_file(filename_or_url, options = {}, &block) #puts "open #{filename_or_url}" - case filename_or_url.to_s + f = case filename_or_url.to_s when /^file:/ path = filename_or_url[5..-1] Kernel.open(path.to_s, &block) + when 'http://www.w3.org/ns/md' + Kernel.open(RDF::Microdata::Reader::DEFAULT_REGISTRY) when /^#{REMOTE_PATH}/ begin #puts "attempt to open #{filename_or_url} locally" @@ -44,21 +46,23 @@ def response.content_type; 'unknown'; end end #puts "use #{filename_or_url} locally as #{response.content_type}" - if block_given? - begin - yield response - ensure - response.close - end - else - response - end + response rescue Errno::ENOENT # Not there, don't run tests Kernel.open(path.to_s, &block) end else end + + if block_given? + begin + yield f + ensure + f.close + end + else + f + end end end end @@ -99,7 +103,7 @@ def method_missing(method, *args) def inspect "" @@ -137,18 +141,14 @@ class Entry < JSON::LD::Resource def data self.action['data'] end - - def query - self.action['query'] - end - + def registry - self.action.fetch('registry', - "http://www.w3.org/TR/microdata-rdf/tests/test-registry.json") + property('registry') || + "http://www.w3.org/TR/microdata-rdf/tests/test-registry.json" end - def result - property('result') == 'true' + def positiveTest + property('positiveTest') == 'true' end def trace; @debug.join("\n"); end diff --git a/spec/suite_spec.rb b/spec/suite_spec.rb index 643c371..5f468db 100644 --- a/spec/suite_spec.rb +++ b/spec/suite_spec.rb @@ -24,9 +24,9 @@ graph = RDF::Graph.new << reader #puts "parse #{t.query} as #{RDF::Reader.for(t.query)}" - output_graph = RDF::Graph.load(t.query, :base_uri => t.data) + output_graph = RDF::Graph.load(t.result, :base_uri => t.data) puts "result: #{CGI.escapeHTML(graph.dump(:ttl))}" if ::RDF::Microdata::debug? - if t.result + if t.positiveTest graph.should be_equivalent_graph(output_graph, t) else graph.should_not be_equivalent_graph(output_graph, t) diff --git a/spec/test-files/test-registry.json b/spec/test-files/test-registry.json index c0ebf28..c4c9d82 100644 --- a/spec/test-files/test-registry.json +++ b/spec/test-files/test-registry.json @@ -36,28 +36,5 @@ "list": {"multipleValues": "list"}, "typed": {"datatype": "http://typed"} } - }, - "http://schema.org/": { - "propertyURI": "vocabulary", - "multipleValues": "unordered", - "properties": { - "additionalType": {"subPropertyOf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}, - "blogPosts": {"multipleValues": "list"}, - "breadcrumb": {"multipleValues": "list"}, - "byArtist": {"multipleValues": "list"}, - "creator": {"multipleValues": "list"}, - "episodes": {"multipleValues": "list"}, - "events": {"multipleValues": "list"}, - "founders": {"multipleValues": "list"}, - "itemListElement": {"multipleValues": "list"}, - "musicGroupMember": {"multipleValues": "list"}, - "performerIn": {"multipleValues": "list"}, - "performers": {"multipleValues": "list"}, - "producer": {"multipleValues": "list"}, - "recipeInstructions": {"multipleValues": "list"}, - "seasons": {"multipleValues": "list"}, - "subEvents": {"multipleValues": "list"}, - "tracks": {"multipleValues": "list"} - } } }