diff --git a/.travis.yml b/.travis.yml index 43881d7..83a126b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,16 @@ language: ruby -bundler_args: --without debug script: "bundle exec rspec spec" -before_install: - - 'gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)' - - 'gem update bundler --conservative' env: - CI=true rvm: - - 2.2.2 - - 2.3 - 2.4 - 2.5 - 2.6 - - jruby-9 - - rbx-3 + - 2.7 + - jruby cache: bundler sudo: false matrix: allow_failures: - - rvm: jruby-9 - - rvm: rbx-3 + - rvm: jruby dist: trusty diff --git a/Gemfile b/Gemfile index 72621c7..a6ae8aa 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,6 @@ group :development, :test do gem 'rdf-vocab', git: "https://github.com/ruby-rdf/rdf-vocab", branch: "develop" gem 'sxp', git: "https://github.com/dryruby/sxp.rb", branch: "develop" gem "redcarpet", platforms: :ruby - gem 'simplecov', require: false, platform: :mri - gem 'coveralls', require: false, platform: :mri + gem 'simplecov', platforms: :mri + gem 'coveralls', '~> 0.8', platforms: :mri end diff --git a/README.md b/README.md index 1db4dc0..cf99018 100755 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ This version uses a hand-written parser using the Lexer from the [EBNF][] gem in ## Dependencies -* [Ruby](https://ruby-lang.org/) (>= 2.2) -* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.0) +* [Ruby](https://ruby-lang.org/) (>= 2.4) +* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.1) * [EBNF][] (~> 1.1) ## Installation diff --git a/VERSION b/VERSION index 818bd47..fd2a018 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.6 +3.1.0 diff --git a/lib/rdf/turtle/freebase_reader.rb b/lib/rdf/turtle/freebase_reader.rb index 59cf166..20380e8 100644 --- a/lib/rdf/turtle/freebase_reader.rb +++ b/lib/rdf/turtle/freebase_reader.rb @@ -55,7 +55,7 @@ def read_prefix ## # Read a PNAME of the form `prefix:suffix`. # @return [RDF::URI] - def read_pname(options = {}) + def read_pname(**options) if pname_str = match(/^(\w+:\S+)/) ns, suffix = pname_str.split(':', 2) if suffix[-1,1] == "." diff --git a/lib/rdf/turtle/reader.rb b/lib/rdf/turtle/reader.rb index 6f2652d..22c6011 100644 --- a/lib/rdf/turtle/reader.rb +++ b/lib/rdf/turtle/reader.rb @@ -48,14 +48,14 @@ def self.options # Redirect for Freebase Reader # # @private - def self.new(input = nil, options = {}, &block) + def self.new(input = nil, **options, &block) klass = if options[:freebase] FreebaseReader else self end reader = klass.allocate - reader.send(:initialize, input, options, &block) + reader.send(:initialize, input, **options, &block) reader end @@ -82,7 +82,7 @@ def self.new(input = nil, options = {}, &block) # @option options [Boolean] :freebase (false) # Use optimized Freebase reader # @return [RDF::Turtle::Reader] - def initialize(input = nil, options = {}, &block) + def initialize(input = nil, **options, &block) super do @options = { anon_base: "b0", @@ -98,7 +98,7 @@ def initialize(input = nil, options = {}, &block) log_debug("canonicalize") {canonicalize?.inspect} log_debug("intern") {intern?.inspect} - @lexer = EBNF::LL1::Lexer.new(input, self.class.patterns, @options) + @lexer = EBNF::LL1::Lexer.new(input, self.class.patterns, **@options) if block_given? case block.arity @@ -184,14 +184,14 @@ def process_iri(iri) end # Create a literal - def literal(value, options = {}) + def literal(value, **options) log_debug("literal") do "value: #{value.inspect}, " + "options: #{options.inspect}, " + "validate: #{validate?.inspect}, " + "c14n?: #{canonicalize?.inspect}" end - RDF::Literal.new(value, options.merge(validate: validate?, canonicalize: canonicalize?)) + RDF::Literal.new(value, validate: validate?, canonicalize: canonicalize?, **options) rescue ArgumentError => e error("Argument Error #{e.message}", production: :literal, token: @lexer.first) end @@ -587,7 +587,7 @@ class SyntaxError < RDF::ReaderError # @option options [Symbol] :production (nil) # @option options [String] :token (nil) # @option options [Integer] :lineno (nil) - def initialize(message, options = {}) + def initialize(message, **options) @production = options[:production] @token = options[:token] @lineno = options[:lineno] || (@token.lineno if @token.respond_to?(:lineno)) diff --git a/lib/rdf/turtle/streaming_writer.rb b/lib/rdf/turtle/streaming_writer.rb index 09b867d..10cca2c 100644 --- a/lib/rdf/turtle/streaming_writer.rb +++ b/lib/rdf/turtle/streaming_writer.rb @@ -28,15 +28,15 @@ def stream_statement(statement) if statement.subject != @streaming_subject @output.puts ' .' if @streaming_subject @streaming_subject, @streaming_predicate = statement.subject, statement.predicate - @output.write "#{format_term(statement.subject, options)} " - @output.write "#{format_term(statement.predicate, options)} " + @output.write "#{format_term(statement.subject, **options)} " + @output.write "#{format_term(statement.predicate, **options)} " elsif statement.predicate != @streaming_predicate @streaming_predicate = statement.predicate - @output.write ";\n#{indent(1)}#{format_term(statement.predicate, options)} " + @output.write ";\n#{indent(1)}#{format_term(statement.predicate, **options)} " else @output.write ",\n#{indent(2)}" end - @output.write("#{format_term(statement.object, options)}") + @output.write("#{format_term(statement.object, **options)}") end ## diff --git a/lib/rdf/turtle/writer.rb b/lib/rdf/turtle/writer.rb index 182d0b8..b18e23f 100644 --- a/lib/rdf/turtle/writer.rb +++ b/lib/rdf/turtle/writer.rb @@ -123,7 +123,7 @@ def self.options # @yieldreturn [void] # @yield [writer] # @yieldparam [RDF::Writer] writer - def initialize(output = $stdout, options = {}, &block) + def initialize(output = $stdout, **options, &block) @graph = RDF::Graph.new @uri_to_pname = {} @uri_to_prefix = {} @@ -272,7 +272,7 @@ def sort_properties(properties) # @param [RDF::Literal, String, #to_s] literal # @param [Hash{Symbol => Object}] options # @return [String] - def format_literal(literal, options = {}) + def format_literal(literal, **options) case literal when RDF::Literal case @options[:literal_shorthand] && literal.valid? ? literal.datatype : false @@ -297,7 +297,7 @@ def format_literal(literal, options = {}) # @param [RDF::URI] uri # @param [Hash{Symbol => Object}] options # @return [String] - def format_uri(uri, options = {}) + def format_uri(uri, **options) md = uri.relativize(base_uri) log_debug("relativize") {"#{uri.to_ntriples} => #{md.inspect}"} if md != uri.to_s md != uri.to_s ? "<#{md}>" : (get_pname(uri) || "<#{uri}>") @@ -309,7 +309,7 @@ def format_uri(uri, options = {}) # @param [RDF::Node] node # @param [Hash{Symbol => Object}] options # @return [String] - def format_node(node, options = {}) + def format_node(node, **options) options[:unique_bnodes] ? node.to_unique_base : node.to_base end @@ -349,7 +349,7 @@ def order_subjects # Add distinguished classes top_classes.each do |class_uri| - graph.query(predicate: RDF.type, object: class_uri). + graph.query({predicate: RDF.type, object: class_uri}). map {|st| st.subject}. sort. uniq. @@ -546,7 +546,7 @@ def p_term(resource, position) l = if resource == RDF.nil "()" else - format_term(resource, options) + format_term(resource, **options) end @output.write(l) end @@ -595,7 +595,7 @@ def objectList(objects) # @return [Integer] the number of properties serialized def predicateObjectList(subject, from_bpl = false) properties = {} - @graph.query(subject: subject) do |st| + @graph.query({subject: subject}) do |st| (properties[st.predicate.to_s] ||= []) << st.object end diff --git a/rdf-turtle.gemspec b/rdf-turtle.gemspec index da4d566..c8901e2 100755 --- a/rdf-turtle.gemspec +++ b/rdf-turtle.gemspec @@ -18,19 +18,18 @@ Gem::Specification.new do |gem| gem.files = %w(AUTHORS README.md History UNLICENSE VERSION) + Dir.glob('lib/**/*.rb') gem.require_paths = %w(lib) - gem.required_ruby_version = '>= 2.2.2' + gem.required_ruby_version = '>= 2.4' gem.requirements = [] - gem.add_runtime_dependency 'rdf', '~> 3.0' - gem.add_runtime_dependency 'ebnf', '~> 1.1' - gem.add_development_dependency 'rspec', '~> 3.7' - gem.add_development_dependency 'rspec-its', '~> 1.2' - gem.add_development_dependency 'rdf-isomorphic', '~> 3.0' - #gem.add_development_dependency 'json-ld', '~> 3.0' - gem.add_development_dependency 'rdf-spec', '~> 3.0' - gem.add_development_dependency 'rdf-vocab', '~> 3.0' - gem.add_development_dependency 'json-ld', '>= 2.1', '< 4.0' + gem.add_runtime_dependency 'rdf', '~> 3.1' + gem.add_runtime_dependency 'ebnf', '~> 1.2' + gem.add_development_dependency 'rspec', '~> 3.9' + gem.add_development_dependency 'rspec-its', '~> 1.3' + gem.add_development_dependency 'rdf-isomorphic', '~> 3.1' + gem.add_development_dependency 'json-ld', '~> 3.1' + gem.add_development_dependency 'rdf-spec', '~> 3.1' + gem.add_development_dependency 'rdf-vocab', '~> 3.1' - gem.add_development_dependency 'rake', '~> 12.0' - gem.add_development_dependency 'yard' , '~> 0.9.12' + gem.add_development_dependency 'rake', '~> 13.0' + gem.add_development_dependency 'yard' , '~> 0.9.20' gem.post_install_message = nil end diff --git a/script/parse b/script/parse index 7e862a9..2ccd523 100755 --- a/script/parse +++ b/script/parse @@ -19,7 +19,7 @@ require 'rdf/ntriples' require 'ebnf/ll1/parser' require 'getoptlong' -def run(input, options) +def run(input, **options) if options[:profile] require 'profiler' end @@ -31,7 +31,7 @@ def run(input, options) num = 0 Profiler__::start_profile if options[:profile] if options[:output_format] == :ntriples || options[:quiet] || options[:benchmark] - r = reader_class.new(input, options[:parser_options]) + r = reader_class.new(input, **options[:parser_options]) r.each do |statement| num += 1 if options[:errors] && statement.invalid? @@ -45,15 +45,15 @@ def run(input, options) end end elsif options[:output_format] == :inspect - reader_class.new(input, options[:parser_options]).each do |statement| + reader_class.new(input, **options[:parser_options]).each do |statement| num += 1 options[:output].puts statement.inspect end else - r = reader_class.new(input, options[:parser_options]) + r = reader_class.new(input, **options[:parser_options]) g = RDF::Graph.new << r num = g.count - options[:output].puts g.dump(options[:output_format], {prefixes: r.prefixes}.merge(options[:writer_options])) + options[:output].puts g.dump(options[:output_format], prefixes: r.prefixes, **options[:writer_options]) end if options[:profile] Profiler__::stop_profile @@ -137,10 +137,10 @@ end if ARGV.empty? s = input ? input : $stdin.read - run(StringIO.new(s), options) + run(StringIO.new(s), **options) else ARGV.each do |test_file| - run(Kernel.open(test_file), options) + run(Kernel.open(test_file), **options) end end puts diff --git a/script/tc b/script/tc index 9932ba1..a755aa1 100755 --- a/script/tc +++ b/script/tc @@ -12,7 +12,7 @@ require 'getoptlong' ASSERTOR = "https://greggkellogg.net/foaf#me" RUN_TIME = Time.now -def earl_preamble(options) +def earl_preamble(**options) options[:output].write File.read(File.expand_path("../../etc/doap#{'-ntriples' if options[:ntriples]}.ttl", __FILE__)) options[:output].puts %( <> foaf:primaryTopic ; @@ -43,7 +43,7 @@ def earl_preamble(options) ) end -def run_tc(tc, options) +def run_tc(tc, **options) STDERR.write "run #{tc.name}" if options[:verbose] @@ -64,7 +64,7 @@ def run_tc(tc, options) logger: logger }.merge(options) - reader = RDF::Reader.for(tc.action).new(tc.input, options) + reader = RDF::Reader.for(tc.action).new(tc.input, **options) graph = RDF::Repository.new result = nil @@ -139,7 +139,7 @@ opts = GetoptLong.new( ["--verbose", "-v", GetoptLong::NO_ARGUMENT] ) -def help(options) +def help(**options) puts "Usage: #{$0} [options] [test-number ...]" puts "Options:" puts " --debug: Display detailed debug output" @@ -157,7 +157,7 @@ end opts.each do |opt, arg| case opt - when '--help' then help(options) + when '--help' then help(**options) when '--dbg' then options[:level] = Logger::DEBUG when '--earl' options[:quiet] = options[:earl] = true @@ -175,14 +175,14 @@ end manifest = (options[:ntriples] ? Fixtures::SuiteTest::NTBASE : Fixtures::SuiteTest::BASE) + "manifest.ttl" -earl_preamble(options) if options[:earl] +earl_preamble(**options) if options[:earl] result_count = {} Fixtures::SuiteTest::Manifest.open(manifest) do |m| m.entries.each do |tc| next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)} - run_tc(tc, options.merge(result_count: result_count)) + run_tc(tc, result_count: result_count, **options) end end diff --git a/spec/freebase_spec.rb b/spec/freebase_spec.rb index a05a0a6..e51028b 100644 --- a/spec/freebase_spec.rb +++ b/spec/freebase_spec.rb @@ -141,7 +141,7 @@ end end - def parse(input, options = {}) + def parse(input, **options) @logger = RDF::Spec.logger options = { logger: @logger, @@ -149,7 +149,7 @@ def parse(input, options = {}) canonicalize: false, }.merge(options) graph = options[:graph] || RDF::Graph.new - RDF::Turtle::FreebaseReader.new(input, options).each do |statement| + RDF::Turtle::FreebaseReader.new(input, **options).each do |statement| graph << statement end graph diff --git a/spec/reader_spec.rb b/spec/reader_spec.rb index 093f45b..3cddde1 100644 --- a/spec/reader_spec.rb +++ b/spec/reader_spec.rb @@ -1865,7 +1865,7 @@ end end - def parse(input, options = {}) + def parse(input, **options) @logger = RDF::Spec.logger options = { logger: @logger, @@ -1873,7 +1873,7 @@ def parse(input, options = {}) canonicalize: false, }.merge(options) graph = options[:graph] || RDF::Graph.new - RDF::Turtle::Reader.new(input, options).each do |statement| + RDF::Turtle::Reader.new(input, **options).each do |statement| graph << statement end graph diff --git a/spec/suite_helper.rb b/spec/suite_helper.rb index eaeb799..95890c8 100644 --- a/spec/suite_helper.rb +++ b/spec/suite_helper.rb @@ -24,7 +24,7 @@ class << self # HTTP Request headers. # @return [IO] File stream # @yield [IO] File stream - def self.open_file(filename_or_url, options = {}, &block) + def self.open_file(filename_or_url, **options, &block) case when filename_or_url.to_s =~ /^file:/ path = filename_or_url[5..-1] @@ -55,7 +55,7 @@ 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) + remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options) if block_given? yield remote_document else @@ -87,14 +87,14 @@ 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) + remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options) if block_given? yield remote_document else remote_document end else - original_open_file(filename_or_url, options, &block) + original_open_file(filename_or_url, **options, &block) end end end @@ -138,7 +138,7 @@ def self.open(file) g = RDF::Repository.load(file, format: :ttl) JSON::LD::API.fromRDF(g) do |expanded| JSON::LD::API.frame(expanded, FRAME) do |framed| - yield Manifest.new(framed['@graph'].first) + yield Manifest.new(framed) end end end diff --git a/spec/writer_spec.rb b/spec/writer_spec.rb index 24f521d..f6d6587 100644 --- a/spec/writer_spec.rb +++ b/spec/writer_spec.rb @@ -139,11 +139,11 @@ } }.each do |name, params| it name do - serialize(params[:input], params[:regexp], params) + serialize(params[:input], params[:regexp], **params) end it "#{name} (stream)" do - serialize(params[:input], params.fetch(:regexp_stream, params[:regexp]), params.merge(stream: true)) + serialize(params[:input], params.fetch(:regexp_stream, params[:regexp]), stream: true, **params) end end end @@ -293,7 +293,7 @@ }, }.each do |name, params| it name do - serialize(params[:input], params[:regexp], params) + serialize(params[:input], params[:regexp], **params) end end end @@ -335,7 +335,7 @@ }, }.each do |name, params| it name do - serialize(params[:input], params[:regexp], params) + serialize(params[:input], params[:regexp], **params) end end end @@ -631,8 +631,8 @@ end end unless ENV['CI'] # Not for continuous integration - def parse(input, options = {}) - RDF::Turtle::Reader.new(input, options, &:each).to_a.extend(RDF::Enumerable) + def parse(input, **options) + RDF::Turtle::Reader.new(input, **options, &:each).to_a.extend(RDF::Enumerable) end # Serialize ntstr to a string and compare against regexps @@ -640,12 +640,13 @@ def serialize(ntstr, regexps = [], base_uri: nil, **options) prefixes = options[:prefixes] || {} g = ntstr.is_a?(RDF::Enumerable) ? ntstr : parse(ntstr, base_uri: base_uri, prefixes: prefixes, validate: false, logger: []) logger.info "serialized: #{ntstr}" - result = RDF::Turtle::Writer.buffer(options.merge( + result = RDF::Turtle::Writer.buffer( logger: logger, base_uri: base_uri, prefixes: prefixes, - encoding: Encoding::UTF_8 - )) do |writer| + encoding: Encoding::UTF_8, + **options + ) do |writer| writer << g end