From 7bd78dbf2ff0dba11b2c7cf6c75507a88981a3f9 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 25 Oct 2020 16:48:17 -0700 Subject: [PATCH 1/6] Update PDD info in the README. --- CONTRIBUTING.md | 8 +++++--- README.md | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b4c897b..2e06a13 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,9 +28,11 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to manage devel enough, be assured we will eventually add you in there. * Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an - explicit [public domain dedication][PDD] on record from you. + explicit [public domain dedication][PDD] on record from you, + which you will be asked to agree to on the first commit to a repo within the organization. + Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization. [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-trig/compare/ +[PDD]: https://unlicense.org/#unlicensing-contributions +[pr]: https://github.com/ruby-rdf/rdf/compare/ diff --git a/README.md b/README.md index 5b6fbe8..d4f4bc8 100755 --- a/README.md +++ b/README.md @@ -85,7 +85,9 @@ To install the latest official release of the `RDF::TriG` gem, do: list in the the `README`. Alphabetical order applies. * Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an - explicit [public domain dedication][PDD] on record from you. + explicit [public domain dedication][PDD] on record from you, + which you will be asked to agree to on the first commit to a repo within the organization. + Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization. ## License This is free and unencumbered public domain software. For more information, @@ -97,7 +99,7 @@ A copy of the [TriG EBNF][] and derived parser files are included in the reposit [RDF]: https://www.w3.org/RDF/ [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 +[PDD]: https://unlicense.org/#unlicensing-contributions [RDF.rb]: https://rubydoc.info/github/ruby-rdf/rdf/master/frames [Backports]: https://rubygems.org/gems/backports [TriG]: https://www.w3.org/TR/trig/ From 27322efd1c54cb32e29673bd4f42ce979bb236e5 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 20 Dec 2020 17:53:09 -0800 Subject: [PATCH 2/6] Run CI on GitHub. --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ Gemfile | 1 - README.md | 5 +++-- Rakefile | 26 -------------------------- rdf-trig.gemspec | 7 +++---- 5 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8d5176a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +# This workflow runs continuous CI across different versions of ruby on all branches and pull requests to develop. + +name: CI +on: + push: + branches: [ '**' ] + pull_request: + branches: [ develop ] + workflow_dispatch: + +jobs: + tests: + name: Ruby ${{ matrix.ruby }} + if: "contains(github.event.commits[0].message, '[ci skip]') == false" + runs-on: ubuntu-latest + env: + CI: true + strategy: + fail-fast: false + matrix: + ruby: + - 2.4 + - 2.5 + - 2.6 + - 2.7 + - ruby-head + - jruby + steps: + - name: Clone repository + uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run tests + run: bundle exec rspec spec + diff --git a/Gemfile b/Gemfile index 0c660f7..903745a 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,6 @@ gem 'ebnf', git: "https://github.com/dryruby/ebnf", branch: "devel group :development do gem "byebug", platforms: :mri - gem 'psych', platforms: [:mri, :rbx] end group :development, :test do diff --git a/README.md b/README.md index d4f4bc8..d7155aa 100755 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ [TriG][] reader/writer for [RDF.rb][RDF.rb] . [![Gem Version](https://badge.fury.io/rb/rdf-trig.png)](https://badge.fury.io/rb/rdf-trig) -[![Build Status](https://travis-ci.org/ruby-rdf/rdf-trig.png?branch=master)](https://travis-ci.org/ruby-rdf/rdf-trig) -[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-trig/badge.svg)](https://coveralls.io/r/ruby-rdf/rdf-trig) +[![Build Status](https://github.com/ruby-rdf/rdf-trig/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf-trig/actions?query=workflow%3ACI) +[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-trig/badge.svg)](https://coveralls.io/github/ruby-rdf/rdf-trig) +[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf) ## Description This is a [Ruby][] implementation of a [TriG][] reader and writer for [RDF.rb][]. diff --git a/Rakefile b/Rakefile index b30f1af..834c548 100755 --- a/Rakefile +++ b/Rakefile @@ -13,29 +13,3 @@ namespace :gem do sh "gem push pkg/rdf-trig-#{File.read('VERSION').chomp}.gem" end end - -desc 'Default: run specs.' -task :default => :spec -task :specs => :spec - -require 'rspec/core/rake_task' -desc 'Run specifications' -RSpec::Core::RakeTask.new do |spec| - spec.rspec_opts = %w(--options spec/spec.opts) if File.exists?('spec/spec.opts') -end - -desc "Run specs through RCov" -RSpec::Core::RakeTask.new("spec:rcov") do |spec| - spec.rcov = true - spec.rcov_opts = %q[--exclude "spec"] -end - -desc "Generate HTML report specs" -RSpec::Core::RakeTask.new("doc:spec") do |spec| - spec.rspec_opts = ["--format", "html", "-o", "doc/spec.html"] -end - -require 'yard' -namespace :doc do - YARD::Rake::YardocTask.new -end diff --git a/rdf-trig.gemspec b/rdf-trig.gemspec index fa5f1da..ae89c7b 100755 --- a/rdf-trig.gemspec +++ b/rdf-trig.gemspec @@ -21,15 +21,14 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 2.4' gem.requirements = [] gem.add_runtime_dependency 'rdf', '~> 3.1' - gem.add_runtime_dependency 'ebnf', '~> 2.0' + gem.add_runtime_dependency 'ebnf', '~> 2.1' gem.add_runtime_dependency 'rdf-turtle', '~> 3.1' gem.add_development_dependency 'json-ld', '~> 3.1' - gem.add_development_dependency 'rspec', '~> 3.9' + gem.add_development_dependency 'rspec', '~> 3.10' gem.add_development_dependency 'rspec-its', '~> 1.3' gem.add_development_dependency 'rdf-isomorphic', '~> 3.1' - gem.add_development_dependency 'yard' , '~> 0.9.20' + gem.add_development_dependency 'yard' , '~> 0.9' gem.add_development_dependency 'rdf-spec', '~> 3.1' - gem.add_development_dependency 'rake', '~> 13.0' gem.post_install_message = nil end From 605c73048d37cbfc3764734b5c5e9839841f451f Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 21 Dec 2020 15:05:25 -0800 Subject: [PATCH 3/6] Account for some variation in error reporting in reader validation. --- spec/reader_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/reader_spec.rb b/spec/reader_spec.rb index 844086c..efc87c4 100644 --- a/spec/reader_spec.rb +++ b/spec/reader_spec.rb @@ -710,7 +710,7 @@ %(GRAPH

.) => %r(Expected wrappedGraph), %(GRAPH

.) => %r(Expected wrappedGraph), %(GRAPH {

}) => %r(Expected wrappedGraph), - %(GRAPH {

) => %r(Expected '}' following triple), + %(GRAPH {

) => RDF::ReaderError, %(GRAPH {

. GRAPH { } @@ -723,7 +723,7 @@ }) => RDF::ReaderError, %(GRAPH () { :s :p :o }) => %r(Expected label or subject), %(GRAPH (1 2) { :s :p :o }) => %r(Expected label or subject), - %( ) => %r(Expected '.' following triple), + %( ) => RDF::ReaderError, %([:p1 :o1] {:s :p :o}) => %r(Expected '.' following triple), %((123) .) => %r(Expected predicateObjectList after collection subject), }.each_pair do |trig, error| From ac5a156df70d2031834bb75549e5badae481a3da Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Tue, 12 Jan 2021 15:19:52 -0800 Subject: [PATCH 4/6] Basic RDF* support, specifically for Turtle test cases. To be determined is how embedded triples within named graphs are treated. --- README.md | 2 +- etc/doap.ttl | 59 +++++++++++++++++++++--------------------- lib/rdf/trig/reader.rb | 29 +++++++++++++++++++-- script/parse | 2 ++ spec/star_spec.rb | 52 +++++++++++++++++++++++++++++++++++++ spec/suite_helper.rb | 34 ++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 33 deletions(-) create mode 100644 spec/star_spec.rb diff --git a/README.md b/README.md index d7155aa..2788623 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Gem Version](https://badge.fury.io/rb/rdf-trig.png)](https://badge.fury.io/rb/rdf-trig) [![Build Status](https://github.com/ruby-rdf/rdf-trig/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf-trig/actions?query=workflow%3ACI) -[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-trig/badge.svg)](https://coveralls.io/github/ruby-rdf/rdf-trig) +[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-trig/badge.svg?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf-trig?branch=develop) [![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf) ## Description diff --git a/etc/doap.ttl b/etc/doap.ttl index c2070e6..bc419e8 100644 --- a/etc/doap.ttl +++ b/etc/doap.ttl @@ -7,39 +7,38 @@ @prefix xsd: . a doap:GitRepository; - dc:title "RDF::TriG"; - doap:browse . + dc:title "RDF::TriG"; + doap:browse . - <> a doap:Project, earl:TestSubject, earl:Software; - doap:blog ; - doap:developer ; - doap:documenter ; - doap:maintainer ; - doap:bug-database ; - doap:description "TriG reader/writer for RDF.rb"; - doap:name "RDF::TriG"; - doap:shortdesc "TriG reader/writer for Ruby."@en; - doap:programming-language "Ruby"; - doap:repository ; - doap:mailing-list ; - doap:implements ; - doap:category , - ; - doap:homepage ; - doap:license ; - foaf:maker ; - dc:date "2011-12-22"^^xsd:date; - dc:creator ; - dc:description "TriG reader/writer for RDF.rb"; - dc:isPartOf . +<> a doap:Project, earl:TestSubject, earl:Software; + doap:name "RDF::TriG"; + doap:shortdesc "TriG reader/writer for the RDF.rb library suite"@en; + doap:description "TriG reader/writer for RDF.rb"; + doap:created "2011-12-22"^^xsd:date; + doap:blog ; + doap:developer ; + doap:documenter ; + doap:maintainer ; + doap:bug-database ; + doap:programming-language "Ruby"; + doap:repository ; + doap:mailing-list ; + doap:implements ; + doap:category , + ; + doap:homepage ; + doap:license ; + foaf:maker ; + dc:creator ; + dc:isPartOf . a foaf:OnlineAccount; - dc:created "2009-01-13T08:58:46-08:00"^^xsd:dateTime; - doap:homepage ; - foaf:accountName "gkellogg"; - foaf:accountServiceHomepage ; - foaf:name "GitHub"; - foaf:page . + dc:created "2009-01-13T08:58:46-08:00"^^xsd:dateTime; + doap:homepage ; + foaf:accountName "gkellogg"; + foaf:accountServiceHomepage ; + foaf:name "GitHub"; + foaf:page . a foaf:Person; foaf:mbox ; diff --git a/lib/rdf/trig/reader.rb b/lib/rdf/trig/reader.rb index 2f7e500..352325a 100644 --- a/lib/rdf/trig/reader.rb +++ b/lib/rdf/trig/reader.rb @@ -23,7 +23,15 @@ class Reader < RDF::Turtle::Reader terminal(:STRING_LITERAL_SINGLE_QUOTE, STRING_LITERAL_SINGLE_QUOTE, unescape: true) # String terminals - terminal(nil, %r([\{\}\(\),.;\[\]a]|\^\^|true|false)) + terminal(nil, %r( + [\(\),.;\[\]Aa] + | \^\^ + | \{\| + | \|\} + | [\{\}] + | true|false + | <<|>> + )x) terminal(:GRAPH, /graph/i) terminal(:PREFIX, PREFIX) @@ -112,7 +120,7 @@ def read_block read_triplesOrGraph || error("Expected triplesOrGraph", production: :block, token: @lexer.first) when '{' read_wrappedGraph || error("Expected wrappedGraph", production: :block, token: @lexer.first) - when '(', '[' + when '(', '[', '<<' read_triples2 || error("Expected collection or blankNodePropertyList", production: :block, token: @lexer.first) when nil # End of input @@ -183,6 +191,23 @@ def read_triples2 end true end + when '<<' + prod(:triples2) do + subject = read_embTriple || error("Failed to parse embedded triple", production: :triples2, token: @lexer.first) + token = @lexer.first + case token && (token.type || token.value) + when 'a', :IRIREF, :PNAME_LN, :PNAME_NS then read_predicateObjectList(subject) + else error("Expected predicateObjectList after collection subject", production: :triples2, token: token) + end + if !@recovering || @lexer.first === '.' + # If recovering, we will have eaten the closing '.' + token = @lexer.shift + unless token && token.value == '.' + error("Expected '.' following triple", production: :triples2, token: token) + end + end + true + end end end diff --git a/script/parse b/script/parse index e83933c..25fc775 100755 --- a/script/parse +++ b/script/parse @@ -95,6 +95,7 @@ opts = GetoptLong.new( ["--profile", GetoptLong::NO_ARGUMENT], ["--progress", GetoptLong::NO_ARGUMENT], ["--quiet", GetoptLong::NO_ARGUMENT], + ["--rdfstar", GetoptLong::NO_ARGUMENT], ["--validate", GetoptLong::NO_ARGUMENT], ["--verbose", GetoptLong::NO_ARGUMENT] ) @@ -115,6 +116,7 @@ opts.each do |opt, arg| options[:quiet] = options[:quiet].to_i + 1 logger.level = Logger::FATAL when '--stream' then writer_options[:stream] = true + when '--rdfstar' then parser_options[:rdfstar] = true when '--validate' then parser_options[:validate] = true when '--verbose' then $verbose = true end diff --git a/spec/star_spec.rb b/spec/star_spec.rb new file mode 100644 index 0000000..f94c0b1 --- /dev/null +++ b/spec/star_spec.rb @@ -0,0 +1,52 @@ +$:.unshift "." +require 'spec_helper' + +describe RDF::TriG::Reader do + # W3C Turtle Test suite from http://w3c.github.io/rdf-tests/turtle/manifest.ttl + describe "rdfstar turtle tests" do + require 'suite_helper' + + %w(turtle/syntax turtle/eval).each do |man| + Fixtures::SuiteTest::Manifest.open("https://w3c.github.io/rdf-star/tests/#{man}/manifest.ttl") do |m| + describe [m.label, m.comment].compact.join(': ') do + m.entries.each do |t| + specify "#{t.name}: #{t.comment}" do + t.logger = RDF::Spec.logger + t.logger.info t.inspect + t.logger.info "source:\n#{t.input}" + + reader = RDF::TriG::Reader.new(t.input, + base_uri: t.base, + canonicalize: false, + validate: true, + rdfstar: true, + logger: t.logger) + + graph = RDF::Repository.new + + if t.positive_test? + begin + graph << reader + rescue Exception => e + expect(e.message).to produce("Not exception #{e.inspect}", t) + end + + if t.evaluate? + output_graph = RDF::Repository.load(t.result, format: :ntriples, rdfstar: true, base_uri: t.base) + expect(graph).to be_equivalent_graph(output_graph, t) + else + expect(graph).to be_a(RDF::Enumerable) + end + else + expect { + graph << reader + expect(graph.dump(:ntriples)).to produce("not this", t) + }.to raise_error(RDF::ReaderError) + end + end + end + end + end + end + end +end unless ENV['CI'] \ No newline at end of file diff --git a/spec/suite_helper.rb b/spec/suite_helper.rb index 1ceb420..0e91437 100644 --- a/spec/suite_helper.rb +++ b/spec/suite_helper.rb @@ -10,6 +10,8 @@ module File LOCAL_PATH = ::File.expand_path("../w3c-rdf/trig", __FILE__) + '/' REMOTE_PATH_NQ = "http://w3c.github.io/rdf-tests/nquads/" LOCAL_PATH_NQ = ::File.expand_path("../w3c-rdf/nquads", __FILE__) + '/' + REMOTE_PATH_STAR = "https://w3c.github.io/rdf-star/" + LOCAL_PATH_STAR = ::File.expand_path("../w3c-rdf-star/", __FILE__) + '/' class << self alias_method :original_open_file, :open_file @@ -91,6 +93,38 @@ def self.open_file(filename_or_url, **options, &block) # For overriding content type from test data document_options[:headers][:content_type] = options[:contentType] if options[:contentType] + remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options) + if block_given? + yield remote_document + else + remote_document + end + when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH_STAR}} && Dir.exist?(LOCAL_PATH_STAR)) + #puts "attempt to open #{filename_or_url} locally" + localpath = filename_or_url.to_s.sub(REMOTE_PATH_STAR, LOCAL_PATH_STAR) + response = begin + ::File.open(localpath) + rescue Errno::ENOENT => e + raise IOError, e.message + end + document_options = { + base_uri: RDF::URI(filename_or_url), + charset: Encoding::UTF_8, + code: 200, + headers: {} + } + #puts "use #{filename_or_url} locally" + document_options[:headers][:content_type] = case filename_or_url.to_s + when /\.ttl$/ then 'text/turtle' + when /\.nt$/ then 'application/n-triples' + when /\.jsonld$/ then 'application/ld+json' + else 'unknown' + end + + document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type) + # For overriding content type from test data + document_options[:headers][:content_type] = options[:contentType] if options[:contentType] + remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options) if block_given? yield remote_document From aec4f4dbedec935a665a6ae54567f27e6bfbd6b9 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 18 Jan 2021 17:30:26 -0800 Subject: [PATCH 5/6] Add coveralls configuration. --- .coveralls.yml | 1 + .github/workflows/ci.yml | 1 + 2 files changed, 2 insertions(+) create mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..fba2d02 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +repo_token: T4Cj59vkwBh79F3pGpO8GAJ9pdMACx9b9 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d5176a..0e1a059 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: - 2.5 - 2.6 - 2.7 + - 3.0 - ruby-head - jruby steps: From 02ae27bb2289368b9aa642ca3e3a7fbd824e5ba9 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Tue, 2 Feb 2021 13:51:05 -0800 Subject: [PATCH 6/6] Version 3.1.2. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 94ff29c..ef538c2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.1 +3.1.2