Skip to content

Commit

Permalink
Finish 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 16, 2019
2 parents 51d54f4 + cc011a4 commit c3353fb
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 74 deletions.
14 changes: 4 additions & 10 deletions .travis.yml
@@ -1,21 +1,15 @@
cache: bundler
language: ruby
bundler_args: --without debug
script: "bundle exec rspec spec"
before_install: "gem update --system"
env:
- CI=true
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- jruby-9
- rbx-3
- 2.6
- 2.7
- jruby
cache: bundler
sudo: false
matrix:
allow_failures:
- rvm: jruby-9
- rvm: rbx-3
- rvm: jruby
dist: trusty
10 changes: 2 additions & 8 deletions Gemfile
Expand Up @@ -18,12 +18,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", platform: :ruby
gem 'simplecov', require: false, platform: :mri
gem 'coveralls', require: false, platform: :mri
end

platforms :rbx do
gem 'rubysl', '~> 2.0'
gem 'rubinius', '~> 2.0'
gem 'json'
gem 'simplecov', platforms: :mri
gem 'coveralls', '~> 0.8', platforms: :mri
end
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.0.1
3.1.0
14 changes: 7 additions & 7 deletions lib/rdf/trig/streaming_writer.rb
Expand Up @@ -11,24 +11,24 @@ def stream_statement(statement)
if statement.graph_name != @streaming_graph
stream_epilogue
if statement.graph_name
@output.write "#{format_term(statement.graph_name, options)} {"
@output.write "#{format_term(statement.graph_name, **options)} {"
end
@streaming_graph, @streaming_subject, @streaming_predicate = statement.graph_name, statement.subject, statement.predicate
@output.write "#{format_term(statement.subject, options)} "
@output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, options)} "
@output.write "#{format_term(statement.subject, **options)} "
@output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, **options)} "
elsif statement.subject != @streaming_subject
@output.puts " ." if @previous_statement
@output.write "#{indent(@streaming_subject ? 1 : 0)}"
@streaming_subject, @streaming_predicate = statement.subject, statement.predicate
@output.write "#{format_term(statement.subject, options)} "
@output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, options)} "
@output.write "#{format_term(statement.subject, **options)} "
@output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, **options)} "
elsif statement.predicate != @streaming_predicate
@streaming_predicate = statement.predicate
@output.write ";\n#{indent(@streaming_subject ? 2 : 1)}#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, options)} "
@output.write ";\n#{indent(@streaming_subject ? 2 : 1)}#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, **options)} "
else
@output.write ",\n#{indent(@streaming_subject ? 3 : 2)}"
end
@output.write("#{format_term(statement.object, options)}")
@output.write("#{format_term(statement.object, **options)}")
@previous_statement = statement
end

Expand Down
9 changes: 4 additions & 5 deletions lib/rdf/trig/writer.rb
Expand Up @@ -87,7 +87,7 @@ class Writer < RDF::Turtle::Writer
# @yieldreturn [void]
# @yield [writer]
# @yieldparam [RDF::Writer] writer
def initialize(output = $stdout, options = {}, &block)
def initialize(output = $stdout, **options, &block)
super do
# Set both @repo and @graph to a new repository.
@repo = @graph = RDF::Repository.new
Expand All @@ -100,7 +100,6 @@ def initialize(output = $stdout, options = {}, &block)
end
end


##
# Adds a triple to be serialized
# @param [RDF::Resource] subject
Expand Down Expand Up @@ -197,8 +196,8 @@ def blankNodePropertyList?(resource, position)
end

def resource_in_single_graph?(resource)
graph_names = @repo.query(subject: resource).map(&:graph_name)
graph_names += @repo.query(object: resource).map(&:graph_name)
graph_names = @repo.query({subject: resource}).map(&:graph_name)
graph_names += @repo.query({object: resource}).map(&:graph_name)
graph_names.uniq.length <= 1
end

Expand All @@ -208,7 +207,7 @@ def order_graphs
graph_names = @repo.graph_names.to_a.sort

# include default graph, if necessary
graph_names.unshift(nil) unless @repo.query(graph_name: false).to_a.empty?
graph_names.unshift(nil) unless @repo.query({graph_name: false}).to_a.empty?

graph_names
end
Expand Down
20 changes: 10 additions & 10 deletions rdf-trig.gemspec
Expand Up @@ -18,18 +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 'rdf', '~> 3.1'
gem.add_runtime_dependency 'ebnf', '~> 1.1'
gem.add_runtime_dependency 'rdf-turtle', '~> 3.0', '>= 3.0.3'
gem.add_development_dependency 'json-ld', '~> 3.0'
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 'yard' , '~> 0.9.12'
gem.add_development_dependency 'rdf-spec', '~> 3.0'
gem.add_development_dependency 'rake', '~> 12.0'
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-its', '~> 1.3'
gem.add_development_dependency 'rdf-isomorphic', '~> 3.1'
gem.add_development_dependency 'yard' , '~> 0.9.20'
gem.add_development_dependency 'rdf-spec', '~> 3.1'
gem.add_development_dependency 'rake', '~> 13.0'

gem.post_install_message = nil
end
12 changes: 6 additions & 6 deletions script/parse
Expand Up @@ -9,7 +9,7 @@ require 'rdf/nquads'
require 'ebnf/ll1/parser'
require 'getoptlong'

def run(input, options)
def run(input, **options)
if options[:profile]
require 'profiler'
end
Expand All @@ -33,15 +33,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::Repository.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
Expand Down Expand Up @@ -122,10 +122,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
14 changes: 7 additions & 7 deletions script/tc
Expand Up @@ -12,7 +12,7 @@ require 'getoptlong'
ASSERTOR = "http://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#{'-nquads' if options[:nquads]}.ttl", __FILE__))
options[:output].puts %(
<> foaf:primaryTopic <http://rubygems.org/gems/rdf#{'-trig' unless options[:nquads]}> ;
Expand Down Expand Up @@ -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]
Expand All @@ -63,7 +63,7 @@ def run_tc(tc, options)
validate: true
}.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
Expand Down Expand Up @@ -142,7 +142,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"
Expand All @@ -159,7 +159,7 @@ end

opts.each do |opt, arg|
case opt
when '--help' then help(options)
when '--help' then help(**options)
when '--dbg' then logger.level = Logger::DEBUG
when '--earl'
options[:quiet] = options[:earl] = true
Expand All @@ -177,15 +177,15 @@ end

manifests = (options[:nquads] ? [Fixtures::SuiteTest::NQBASE] : [Fixtures::SuiteTest::BASE]).map {|b| b + "manifest.ttl"}

earl_preamble(options) if options[:earl]
earl_preamble(**options) if options[:earl]

result_count = {}

manifests.each do |manifest|
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
end
Expand Down
4 changes: 2 additions & 2 deletions spec/reader_spec.rb
Expand Up @@ -931,15 +931,15 @@
end
end

def parse(input, options = {})
def parse(input, **options)
@logger = RDF::Spec.logger
options = {
logger: @logger,
validate: false,
canonicalize: false,
}.merge(options)
graph = options[:graph] || RDF::Repository.new
RDF::TriG::Reader.new(input, options).each do |statement|
RDF::TriG::Reader.new(input, **options).each do |statement|
graph << statement
end
graph
Expand Down
18 changes: 9 additions & 9 deletions spec/suite_helper.rb
Expand Up @@ -6,9 +6,9 @@
# For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it
module RDF::Util
module File
REMOTE_PATH = "http://www.w3.org/2013/TriGTests/"
REMOTE_PATH = "http://w3c.github.io/rdf-tests/trig/"
LOCAL_PATH = ::File.expand_path("../w3c-rdf/trig", __FILE__) + '/'
REMOTE_PATH_NQ = "http://www.w3.org/2013/N-QuadsTests/"
REMOTE_PATH_NQ = "http://w3c.github.io/rdf-tests/nquads/"
LOCAL_PATH_NQ = ::File.expand_path("../w3c-rdf/nquads", __FILE__) + '/'

class << self
Expand All @@ -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]
Expand Down Expand Up @@ -57,7 +57,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
Expand Down Expand Up @@ -91,23 +91,23 @@ 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
end

module Fixtures
module SuiteTest
BASE = "http://www.w3.org/2013/TriGTests/"
NQBASE = "http://www.w3.org/2013/N-QuadsTests/"
BASE = "http://w3c.github.io/rdf-tests/trig/"
NQBASE = "http://w3c.github.io/rdf-tests/nquads/"
FRAME = JSON.parse(%q({
"@context": {
"xsd": "http://www.w3.org/2001/XMLSchema#",
Expand All @@ -131,7 +131,7 @@ def self.open(file)
g = RDF::Repository.load(file, format: :turtle)
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
Expand Down
19 changes: 10 additions & 9 deletions spec/writer_spec.rb
Expand Up @@ -52,11 +52,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
Expand Down Expand Up @@ -115,8 +115,8 @@
}
),
[
%r(^<a> <b> \[ a <Class>\] \.)m,
%r(^<C> \{\s*<d> <e> \[ a <Class>\] \.\s*\})m
%r(^<a> <b> \[\s*a <Class>\s*\] \.)m,
%r(^<C> \{\s*<d> <e> \[\s*a <Class>\s*\] \.\s*\})m
],
[
%r(^<a> <b> _:c \.)m,
Expand Down Expand Up @@ -341,22 +341,23 @@
end
end unless ENV['CI']

def parse(input, options = {})
def parse(input, **options)
reader = RDF::Reader.for(options.fetch(:format, :trig))
reader.new(input, options, &:each).to_a.extend(RDF::Enumerable)
reader.new(input, **options, &:each).to_a.extend(RDF::Enumerable)
end

# Serialize ntstr to a string and compare against regexps
def serialize(ntstr, regexps = [], base_uri: nil, **options)
prefixes = options[:prefixes] || {}
repo = ntstr.is_a?(RDF::Enumerable) ? ntstr : parse(ntstr, base_uri: base_uri, prefixes: prefixes, validate: false, logger: [], **options)
logger.info "serialized: #{ntstr}"
result = RDF::TriG::Writer.buffer(options.merge(
result = RDF::TriG::Writer.buffer(
logger: logger,
base_uri: base_uri,
prefixes: prefixes,
encoding: Encoding::UTF_8
)) do |writer|
encoding: Encoding::UTF_8,
**options
) do |writer|
writer << repo
end

Expand Down

0 comments on commit c3353fb

Please sign in to comment.