diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e9e566b..6a5ebbd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ Community contributions are essential for keeping Ruby RDF great. We want to kee This repository uses [Git Flow](https://github.com/nvie/gitflow) to manage development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration. -* create or respond to an issue on the [Github Repository](http://github.com/ruby-rdf/rdf-microdata/issues) +* create or respond to an issue on the [Github Repository](https://github.com/ruby-rdf/rdf-microdata/issues) * Fork and clone the repo: `git clone git@github.com:your-username/rdf-microdata.git` * Install bundle: @@ -30,7 +30,7 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to manage devel of thumb, additions larger than about 15 lines of code), we need an explicit [public domain dedication][PDD] on record from you. -[YARD]: http://yardoc.org/ -[YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md -[PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html +[YARD]: https://yardoc.org/ +[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md +[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html [pr]: https://github.com/ruby-rdf/rdf-microdata/compare/ diff --git a/Gemfile b/Gemfile index c4cd63b..2b51158 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source "https://rubygems.org" gemspec @@ -15,6 +15,7 @@ group :development do gem 'rdf-isomorphic', git: "https://github.com/ruby-rdf/rdf-isomorphic", branch: "develop" gem "rdf-spec", git: "https://github.com/ruby-rdf/rdf-spec", branch: "develop" gem 'rdf-turtle', git: "https://github.com/ruby-rdf/rdf-turtle", branch: "develop" + gem 'rdf-vocab', git: "https://github.com/ruby-rdf/rdf-vocab", branch: "develop" gem 'sxp', git: "https://github.com/dryruby/sxp.rb", branch: "develop" end diff --git a/README.md b/README.md index 7f95f2d..85e1050 100755 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [Microdata][] parser for RDF.rb. -[![Gem Version](https://badge.fury.io/rb/rdf-microdata.png)](http://badge.fury.io/rb/rdf-microdata) -[![Build Status](https://secure.travis-ci.org/ruby-rdf/rdf-microdata.png?branch=master)](http://travis-ci.org/ruby-rdf/rdf-microdata) +[![Gem Version](https://badge.fury.io/rb/rdf-microdata.png)](https://badge.fury.io/rb/rdf-microdata) +[![Build Status](https://secure.travis-ci.org/ruby-rdf/rdf-microdata.png?branch=master)](https://travis-ci.org/ruby-rdf/rdf-microdata) ## DESCRIPTION RDF::Microdata is a Microdata reader for Ruby using the [RDF.rb][RDF.rb] library suite. @@ -45,10 +45,10 @@ GRDDL-type triple generation, such as for html>head>title anchor tags. If the `RDFa` parser is available, {RDF::Microdata::Format} will not assert content type `text/html` or file extension `.html`, as this is also asserted by RDFa. Instead, the RDFa reader will invoke the microdata reader if an `@itemscope` attribute is detected. ## Dependencies -* [RDF.rb](http://rubygems.org/gems/rdf) (>= 3.1) -* [RDF::XSD](http://rubygems.org/gems/rdf-xsd) (>= 3.1) +* [RDF.rb](https://rubygems.org/gems/rdf) (>= 3.1) +* [RDF::XSD](https://rubygems.org/gems/rdf-xsd) (>= 3.1) * [HTMLEntities](https://rubygems.org/gems/htmlentities) ('>= 4.3.0') -* [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.10) +* [Nokogiri](https://rubygems.org/gems/nokogiri) (>= 1.10) * Soft dependency on [Nokogumbo](https://github.com/rubys/nokogumbo) (~> 2.0) ## Documentation @@ -70,13 +70,13 @@ The reader exposes a `#rdfa` method, which can be used to retrieve the transform ## Resources * [RDF.rb][RDF.rb] -* [Documentation](http://www.rubydoc.info/github/ruby-rdf/rdf-microdata/) +* [Documentation](https://www.rubydoc.info/github/ruby-rdf/rdf-microdata/) * [History](file:History.md) * [Microdata][] * [Microdata RDF][] ## Author -* [Gregg Kellogg](http://github.com/gkellogg) - +* [Gregg Kellogg](https://github.com/gkellogg) - ## Contributing @@ -95,20 +95,20 @@ The reader exposes a `#rdfa` method, which can be used to retrieve the transform ## License This is free and unencumbered public domain software. For more information, -see or the accompanying {file:UNLICENSE} file. +see or the accompanying {file:UNLICENSE} file. ## FEEDBACK * gregg@greggkellogg.net -* -* -* +* +* +* [RDF.rb]: https://github.com/ruby-rdf/rdf -[YARD]: http://yardoc.org/ -[YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md -[PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html -[Microdata]: http://dev.w3.org/html5/md/Overview.html "HTML Microdata" -[Microdata RDF]: http://dvcs.w3.org/hg/htmldata/raw-file/default/microdata-rdf/index.html "Microdata to RDF" -[Microdata doc]: http://rubydoc.info/github/ruby-rdf/rdf-microdata/frames +[YARD]: https://yardoc.org/ +[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md +[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html +[Microdata]: https://dev.w3.org/html5/md/Overview.html "HTML Microdata" +[Microdata RDF]: https://dvcs.w3.org/hg/htmldata/raw-file/default/microdata-rdf/index.html "Microdata to RDF" +[Microdata doc]: https://rubydoc.info/github/ruby-rdf/rdf-microdata/frames [Nokogumbo]: https://github.com/rubys/nokogumbo/#readme diff --git a/UNLICENSE b/UNLICENSE index 68a49da..cbd74c5 100644 --- a/UNLICENSE +++ b/UNLICENSE @@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -For more information, please refer to +For more information, please refer to diff --git a/VERSION b/VERSION index fd2a018..94ff29c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.0 +3.1.1 diff --git a/etc/doap.html b/etc/doap.html index f955280..86d520e 100644 --- a/etc/doap.html +++ b/etc/doap.html @@ -3,7 +3,7 @@ Microdata reader for Ruby. - +

Project description for RDF::Microdata.

@@ -18,26 +18,26 @@
Created
Blog
http://greggkellogg.net/
Bug DB
- - http://github.com/ruby-rdf/rdf-microdata/issues + + https://github.com/ruby-rdf/rdf-microdata/issues
Category
Resource Description Framework for - Ruby + Ruby
Implements
Microdata to RDF
-
Download
- http://rubygems.org/gems/rdf-microdata +
Download
+ https://rubygems.org/gems/rdf-microdata
-
Home Page
- http://github.com/ruby-rdf/rdf-microdata +
Home Page
+ https://github.com/ruby-rdf/rdf-microdata
License
- Public Domain + Public Domain
Mailing List
http://lists.w3.org/Archives/Public/public-rdf-ruby/ diff --git a/etc/doap.nt b/etc/doap.nt index 5d745bf..b27b2ee 100644 --- a/etc/doap.nt +++ b/etc/doap.nt @@ -1,19 +1,19 @@ - . - "Microdata reader for Ruby."@en . - "\n RDF::Microdata is an Microdata reader for Ruby using the RDF.rb library suite.\n "@en . - "RDF::Microdata" . - . - . - . - . - . - "2011-08-29"^^ . - . - . - . - . - . - . - . - . - . + . + "Microdata reader for Ruby."@en . + "\n RDF::Microdata is an Microdata reader for Ruby using the RDF.rb library suite.\n "@en . + "RDF::Microdata" . + . + . + . + . + . + "2011-08-29"^^ . + . + . + . + "Ruby" . + . + . + . + . + . diff --git a/etc/doap.ttl b/etc/doap.ttl index b1e671e..f633e7c 100644 --- a/etc/doap.ttl +++ b/etc/doap.ttl @@ -1,27 +1,28 @@ -@prefix dc: . +@base . +@prefix dc: . @prefix doap: . @prefix foaf: . -@prefix rdf: . -@prefix xsd: . +@prefix rdf: . +@prefix xsd: . - a doap:Project; - dc:creator ; - doap:blog ; - doap:bug-database ; +<> a doap:Project; + dc:creator ; + doap:blog ; + doap:bug-database ; doap:category ; doap:created "2011-08-29"^^xsd:date; doap:description """ RDF::Microdata is an Microdata reader for Ruby using the RDF.rb library suite. """@en; - doap:developer ; - doap:documenter ; - doap:download-page ; - doap:homepage ; + doap:developer ; + doap:documenter ; + doap:download-page <>; + doap:homepage ; doap:implements ; - doap:license ; - doap:mailing-list ; - doap:maintainer ; + doap:license ; + doap:mailing-list ; + doap:maintainer ; doap:name "RDF::Microdata"; - doap:programming-language ; + doap:programming-language "Ruby"; doap:shortdesc "Microdata reader for Ruby."@en; - foaf:creator . + foaf:creator . diff --git a/lib/rdf/microdata.rb b/lib/rdf/microdata.rb index c74bfd4..2351346 100644 --- a/lib/rdf/microdata.rb +++ b/lib/rdf/microdata.rb @@ -15,10 +15,10 @@ module RDF # end # end # - # @see http://www.rubydoc.info/github/ruby-rdf/rdf/ - # @see http://www.w3.org/TR/2011/WD-microdata-20110525/ + # @see https://www.rubydoc.info/github/ruby-rdf/rdf/ + # @see https://www.w3.org/TR/2011/WD-microdata-20110525/ # - # @author [Gregg Kellogg](http://greggkellogg.net/) + # @author [Gregg Kellogg](https://greggkellogg.net/) module Microdata USES_VOCAB = RDF::URI("http://www.w3.org/ns/rdfa#usesVocabulary") DEFAULT_REGISTRY = File.expand_path("../../../etc/registry.json", __FILE__) diff --git a/lib/rdf/microdata/format.rb b/lib/rdf/microdata/format.rb index ee7211c..4973c9a 100644 --- a/lib/rdf/microdata/format.rb +++ b/lib/rdf/microdata/format.rb @@ -19,7 +19,7 @@ module RDF::Microdata # @example Obtaining serialization format MIME types # RDF::Format.content_types #=> {"text/html" => [RDF::Microdata::Format]} # - # @see http://www.w3.org/TR/rdf-testcases/#ntriples + # @see https://www.w3.org/TR/rdf-testcases/#ntriples class Format < RDF::Format content_encoding 'utf-8' diff --git a/lib/rdf/microdata/reader.rb b/lib/rdf/microdata/reader.rb index 06e3151..3dcbfcf 100644 --- a/lib/rdf/microdata/reader.rb +++ b/lib/rdf/microdata/reader.rb @@ -8,8 +8,8 @@ module RDF::Microdata # # Based on processing rules, amended with the following: # - # @see http://dvcs.w3.org/hg/htmldata/raw-file/0d6b89f5befb/microdata-rdf/index.html - # @author [Gregg Kellogg](http://greggkellogg.net/) + # @see https://dvcs.w3.org/hg/htmldata/raw-file/0d6b89f5befb/microdata-rdf/index.html + # @author [Gregg Kellogg](https://greggkellogg.net/) class Reader < RDF::Reader format Format include Expansion @@ -39,7 +39,7 @@ def base_uri ## # Reader options - # @see http://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Reader#options-class_method + # @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Reader#options-class_method def self.options super + [ RDF::CLI::Option.new( diff --git a/lib/rdf/microdata/reader/nokogiri.rb b/lib/rdf/microdata/reader/nokogiri.rb index 3b7cabb..561330c 100644 --- a/lib/rdf/microdata/reader/nokogiri.rb +++ b/lib/rdf/microdata/reader/nokogiri.rb @@ -3,7 +3,7 @@ class Reader < RDF::Reader ## # Nokogiri implementation of an HTML parser. # - # @see http://nokogiri.org/ + # @see https://nokogiri.org/ module Nokogiri ## # Returns the name of the underlying XML library. @@ -212,7 +212,9 @@ def root ## # Document errors def doc_errors - @doc.errors.reject {|e| e.to_s =~ /The doctype must be the first token in the document/} + @doc.errors.reject do |e| + e.to_s =~ %r{(The doctype must be the first token in the document)|(Expected a doctype token)|(Unexpected '\?' where start tag name is expected)} + end end ## @@ -230,7 +232,7 @@ def doc_base(base) ## # Based on Microdata element.getItems # - # @see http://www.w3.org/TR/2011/WD-microdata-20110525/#top-level-microdata-items + # @see https://www.w3.org/TR/2011/WD-microdata-20110525/#top-level-microdata-items def getItems @doc.css('[itemscope]').select {|el| !el.has_attribute?('itemprop')}.map {|n| NodeProxy.new(n)} end diff --git a/lib/rdf/microdata/registry.rb b/lib/rdf/microdata/registry.rb index f7940f8..2ad5e48 100644 --- a/lib/rdf/microdata/registry.rb +++ b/lib/rdf/microdata/registry.rb @@ -55,7 +55,7 @@ def self.find(type) # Generate a predicateURI given a `name` # # @param [#to_s] name - # @param [Hash{}] ec Evaluation Context + # @param [RDF::URI] base_uri base URI for resolving `name`. # @return [RDF::URI] def predicateURI(name, base_uri) u = RDF::URI(name) diff --git a/rdf-microdata.gemspec b/rdf-microdata.gemspec index 183e1ad..aa0f116 100755 --- a/rdf-microdata.gemspec +++ b/rdf-microdata.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |gem| gem.date = File.mtime('VERSION').strftime('%Y-%m-%d') gem.name = "rdf-microdata" - gem.homepage = "http://ruby-rdf.github.com/rdf-microdata" + gem.homepage = "https://ruby-rdf.github.com/rdf-microdata" gem.license = 'Unlicense' gem.summary = "Microdata reader for Ruby." gem.description = 'Reads HTML Microdata as RDF.' diff --git a/script/tc b/script/tc new file mode 100755 index 0000000..8e804ad --- /dev/null +++ b/script/tc @@ -0,0 +1,136 @@ +#!/usr/bin/env ruby +require 'rubygems' +$:.unshift(File.expand_path("../../lib", __FILE__)) +require "bundler/setup" +require 'logger' +require 'rdf/microdata' +require 'rdf/isomorphic' +require 'rdf/vocab' +require File.expand_path("../../spec/spec_helper", __FILE__) +require File.expand_path("../../spec/suite_helper", __FILE__) +require 'getoptlong' + +def run_tc(tc, **options) + input_uri = tc.action + + STDOUT.write "run #{tc.attributes['@id']}" + + if options[:verbose] + puts("\nTestCase: #{tc.inspect}") + puts("\nInput:\n" + tc.input) + puts("\nExpected:\n" + tc.expected) if tc.result + end + + begin + puts "open #{input_uri}" if options[:verbose] + options = { + base_uri: input_uri, + registry: tc.registry + }.merge(options) + options[:validate] = !tc.positive_test? + + reader = RDF::Microdata::Reader.open(input_uri, **options) + result = nil + graph = RDF::Graph.new + + #require 'byebug'; byebug + if tc.positive_test? + begin + graph << reader + puts("\nTurtle:\n" + graph.dump(:ttl, standard_prefixes: true)) if options[:verbose] + rescue Exception => e + STDERR.puts "Unexpected exception: #{e.inspect}" if options[:verbose] + result = "failed" + end + else + begin + graph << reader + STDERR.puts "Expected exception" if options[:verbose] + require 'byebug'; byebug + result = "failed" + rescue RDF::ReaderError + result = "passed" + end + end + + if tc.evaluate? && result.nil? + # Remove any rdfa:usesVocabulary property + graph.query({predicate: RDF::RDFA.usesVocabulary}) do |st| + graph.delete!(st) + end + output_graph = RDF::Graph.load(tc.result, base_uri: tc.action) + result = graph.isomorphic_with?(output_graph) ? "passed" : "failed" + else + result ||= "passed" + end + + rescue Exception => e + STDERR.puts "#{"exception:" unless options[:quiet]}: #{e}" + if options[:quiet] + return + else + raise + end + end + + options[:result_count][result] ||= 0 + options[:result_count][result] += 1 + + puts " #{result}" +end + +logger = Logger.new(STDERR) +logger.level = Logger::WARN +logger.formatter = lambda {|severity, datetime, progname, msg| "#{severity}: #{msg}\n"} + +options = { + output: STDOUT, + logger: logger +} + +opts = GetoptLong.new( + ["--help", "-?", GetoptLong::NO_ARGUMENT], + ["--debug", GetoptLong::NO_ARGUMENT], + ["--quiet", GetoptLong::NO_ARGUMENT], + ["--validate", GetoptLong::NO_ARGUMENT], + ["--verbose", GetoptLong::NO_ARGUMENT] +) + +def help(**options) + puts "Usage: #{$0} [options] [test-number ...]" + puts "Options:" + puts " --dump: Dump raw output, otherwise serialize to Ruby" + puts " --debug Display detailed debug output" + puts " --expand Expand graph with vocab_expansion option" + puts " --quiet: Minimal output" + puts " --validate: Validate input" + puts " --verbose: Verbose processing" + puts " --help,-?: This message" + exit(0) +end + +opts.each do |opt, arg| + case opt + when '--help' then help(**options) + when '--debug' then logger.level = Logger::DEBUG + when '--format' then options[:format] = arg.to_sym + when '--quiet' + options[:quiet] = true + logger.level = Logger::FATAL + when '--validate' then options[:validate] = true + when '--verbose' then options[:verbose] = true + end +end + +result_count = {} + +Fixtures::SuiteTest::Manifest.open(Fixtures::SuiteTest::BASE + "manifest.jsonld") do |m| + m.entries.each do |tc| + next unless ARGV.empty? || ARGV.any? {|n| tc.id.match(/#{n}/)} + run_tc(tc, result_count: result_count, **options) + end +end + +result_count.each do |result, count| + puts "#{result}: #{count}" +end diff --git a/spec/matchers.rb b/spec/matchers.rb deleted file mode 100644 index 6d21e35..0000000 --- a/spec/matchers.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'rdf/isomorphic' -require 'rspec/matchers' -require 'rdf/rdfa' - -RSpec::Matchers.define :have_xpath do |xpath, value, trace| - match do |actual| - @doc = Nokogiri::HTML.parse(actual) - return false unless @doc.is_a?(Nokogiri::XML::Document) - return false unless @doc.root.is_a?(Nokogiri::XML::Element) - @namespaces = @doc.namespaces.merge("xhtml" => "http://www.w3.org/1999/xhtml", "xml" => "http://www.w3.org/XML/1998/namespace") - case value - when false - @doc.root.at_xpath(xpath, @namespaces).nil? - when true - !@doc.root.at_xpath(xpath, @namespaces).nil? - when Array - @doc.root.at_xpath(xpath, @namespaces).to_s.split(" ").include?(*value) - when Regexp - @doc.root.at_xpath(xpath, @namespaces).to_s =~ value - else - @doc.root.at_xpath(xpath, @namespaces).to_s == value - end - end - - failure_message do |actual| - msg = "expected that #{xpath.inspect} would be #{value.inspect} in:\n" + actual.to_s - msg += "was: #{@doc.root.at_xpath(xpath, @namespaces)}" - msg += "\nDebug:#{trace.join("\n")}" if trace - msg - end - - failure_message_when_negated do |actual| - msg = "expected that #{xpath.inspect} would not be #{value.inspect} in:\n" + actual.to_s - msg += "\nDebug:#{trace.join("\n")}" if trace - msg - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0be34c4..adf8bd4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,6 @@ require 'rdf/turtle' require 'rdf/spec' require 'rdf/spec/matchers' -require 'matchers' ::RSpec.configure do |c| c.filter_run focus: true diff --git a/spec/suite_helper.rb b/spec/suite_helper.rb index e47d415..bb6c140 100644 --- a/spec/suite_helper.rb +++ b/spec/suite_helper.rb @@ -119,11 +119,11 @@ module Fixtures module SuiteTest BASE = RDF::URI("http://w3c.github.io/microdata-rdf/tests/") class Manifest < JSON::LD::Resource - def self.open(file) + def self.open(file, &block) #puts "open: #{file}" RDF::Util::File.open_file(file) do |f| json = JSON.parse(f.read) - self.from_jsonld(json) + block.call(self.from_jsonld(json['@graph'].first)) end end @@ -161,6 +161,10 @@ def result BASE.join(property('result')) if property('result') end + def expected + RDF::Util::File.open_file(result).read + end + def positive_test? !Array(attributes['@type']).join(" ").match(/Negative/) end diff --git a/spec/suite_spec.rb b/spec/suite_spec.rb index 3a7219b..1d63b5e 100644 --- a/spec/suite_spec.rb +++ b/spec/suite_spec.rb @@ -9,8 +9,8 @@ {native: :native, RDFa: :rdfa}.each do |w, sym| describe w do - Fixtures::SuiteTest::Manifest.open(MANIFEST).each do |m| - describe m.comment do + Fixtures::SuiteTest::Manifest.open(MANIFEST) do |m| + describe m.label do m.entries.each do |t| specify "#{t.name}: #{t.comment}" do t.logger = ::RDF::Spec.logger @@ -33,7 +33,7 @@ registry: t.registry, vocab_expansion: t.vocab_expansion, logger: t.logger, - sym => true # Invoke appropriat writer + sym => true # Invoke appropriate writer ) expect(reader).to be_a RDF::Reader graph = RDF::Repository.new