Skip to content

Commit

Permalink
Finish 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 16, 2019
2 parents df1c9e1 + 421ca55 commit c648baa
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 58 deletions.
13 changes: 3 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'rdf-xsd', github: "ruby-rdf/rdf-xsd", branch: "develop"
group :development, :test do
gem 'ebnf', github: "dryruby/ebnf", branch: "develop"
gem 'json-ld', github: "ruby-rdf/json-ld", branch: "develop"
gem "rdf-aggregate-repo", git: "https://github.com/ruby-rdf/rdf-aggregate-repo", branch: "develop"
gem 'rdf-isomorphic', github: "ruby-rdf/rdf-isomorphic", branch: "develop"
gem "rdf-rdfa", github: "ruby-rdf/rdf-rdfa", branch: "develop"
gem "rdf-spec", github: "ruby-rdf/rdf-spec", branch: "develop"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ The `rdf` command-line interface is extended with `entail` and `lint` commands.

## Dependencies

* [Ruby](https://ruby-lang.org/) (>= 2.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)

## Mailing List

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.3
0.6.0
24 changes: 12 additions & 12 deletions lib/rdf/reasoner/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def entail(method, &block)
# @param [Hash{Symbol => Object}] options ({})
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def domain_compatible?(resource, queryable, options = {})
def domain_compatible?(resource, queryable, **options)
%w(owl rdfs schema).map {|r| "domain_compatible_#{r}?".to_sym}.all? do |meth|
!self.respond_to?(meth) || self.send(meth, resource, queryable, options)
!self.respond_to?(meth) || self.send(meth, resource, queryable, **options)
end
end

Expand All @@ -50,9 +50,9 @@ def domain_compatible?(resource, queryable, options = {})
# @param [Hash{Symbol => Object}] options ({})
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def range_compatible?(resource, queryable, options = {})
def range_compatible?(resource, queryable, **options)
%w(owl rdfs schema).map {|r| "range_compatible_#{r}?".to_sym}.all? do |meth|
!self.respond_to?(meth) || self.send(meth, resource, queryable, options)
!self.respond_to?(meth) || self.send(meth, resource, queryable, **options)
end
end
end
Expand Down Expand Up @@ -89,9 +89,9 @@ def entail(method, &block)
# @param [Hash{Symbol => Object}] options ({})
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def domain_compatible?(resource, queryable, options = {})
def domain_compatible?(resource, queryable, **options)
%w(owl rdfs schema).map {|r| "domain_compatible_#{r}?".to_sym}.all? do |meth|
!self.respond_to?(meth) || self.send(meth, resource, queryable, options)
!self.respond_to?(meth) || self.send(meth, resource, queryable, **options)
end
end

Expand All @@ -105,9 +105,9 @@ def domain_compatible?(resource, queryable, options = {})
# @param [Hash{Symbol => Object}] options ({})
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def range_compatible?(resource, queryable, options = {})
def range_compatible?(resource, queryable, **options)
%w(owl rdfs schema).map {|r| "range_compatible_#{r}?".to_sym}.all? do |meth|
!self.respond_to?(meth) || self.send(meth, resource, queryable, options)
!self.respond_to?(meth) || self.send(meth, resource, queryable, **options)
end
end
end
Expand Down Expand Up @@ -233,7 +233,7 @@ def lint
messages = {}

# Check for defined classes in known vocabularies
self.query(predicate: RDF.type) do |stmt|
self.query({predicate: RDF.type}) do |stmt|
vocab = RDF::Vocabulary.find(stmt.object)
term = (RDF::Vocabulary.find_term(stmt.object) rescue nil) if vocab
pname = term ? term.pname : stmt.object.pname
Expand Down Expand Up @@ -275,7 +275,7 @@ def lint
end

# See if type of the subject is in the domain of this predicate
resource_types[stmt.subject] ||= self.query(subject: stmt.subject, predicate: RDF.type).
resource_types[stmt.subject] ||= self.query({subject: stmt.subject, predicate: RDF.type}).
map {|s| (t = (RDF::Vocabulary.find_term(s.object) rescue nil)) && t.entail(:subClassOf)}.
flatten.
uniq.
Expand All @@ -290,7 +290,7 @@ def lint
end

# Make sure that if ranges are defined, the object has an appropriate type
resource_types[stmt.object] ||= self.query(subject: stmt.object, predicate: RDF.type).
resource_types[stmt.object] ||= self.query({subject: stmt.object, predicate: RDF.type}).
map {|s| (t = (RDF::Vocabulary.find_term(s.object) rescue nil)) && t.entail(:subClassOf)}.
flatten.
uniq.
Expand All @@ -316,7 +316,7 @@ def lint
def show_resource(resource)
if resource.node?
resource.to_ntriples + '(' +
self.query(subject: resource, predicate: RDF.type).
self.query({subject: resource, predicate: RDF.type}).
map {|s| s.object.uri? ? s.object.pname : s.object.to_ntriples}
.join(',') +
')'
Expand Down
4 changes: 2 additions & 2 deletions lib/rdf/reasoner/owl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _entail_equivalentClass
if self.predicate == RDF.type
if term = (RDF::Vocabulary.find_term(self.object) rescue nil)
term._entail_equivalentClass do |t|
statements << RDF::Statement(self.to_h.merge(object: t, inferred: true))
statements << RDF::Statement(**self.to_h.merge(object: t, inferred: true))
end
end
end
Expand Down Expand Up @@ -89,7 +89,7 @@ def _entail_equivalentProperty
statements = []
if term = (RDF::Vocabulary.find_term(self.predicate) rescue nil)
term._entail_equivalentProperty do |t|
statements << RDF::Statement(self.to_h.merge(predicate: t, inferred: true))
statements << RDF::Statement(**self.to_h.merge(predicate: t, inferred: true))
end
end
statements.each {|s| yield s} if block_given?
Expand Down
16 changes: 8 additions & 8 deletions lib/rdf/reasoner/rdfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _entail_subClassOf
if term = (RDF::Vocabulary.find_term(self.object) rescue nil)
term._entail_subClassOf do |t|
next if t.node? # Don't entail BNodes
statements << RDF::Statement(self.to_h.merge(object: t, inferred: true))
statements << RDF::Statement(**self.to_h.merge(object: t, inferred: true))
end
end
#$stderr.puts("subClassf(#{self.predicate.pname}): #{statements.map(&:object).map {|r| r.respond_to?(:pname) ? r.pname : r.to_ntriples}}}")
Expand Down Expand Up @@ -143,7 +143,7 @@ def _entail_subPropertyOf
statements = []
if term = (RDF::Vocabulary.find_term(self.predicate) rescue nil)
term._entail_subPropertyOf do |t|
statements << RDF::Statement(self.to_h.merge(predicate: t, inferred: true))
statements << RDF::Statement(**self.to_h.merge(predicate: t, inferred: true))
end
#$stderr.puts("subPropertyOf(#{self.predicate.pname}): #{statements.map(&:object).map {|r| r.respond_to?(:pname) ? r.pname : r.to_ntriples}}}")
end
Expand Down Expand Up @@ -208,7 +208,7 @@ def _entail_domain
if term = (RDF::Vocabulary.find_term(self.predicate) rescue nil)
term.domain.each do |t|
next if t.node? # Don't entail BNodes
statements << RDF::Statement(self.to_h.merge(predicate: RDF.type, object: t, inferred: true))
statements << RDF::Statement(**self.to_h.merge(predicate: RDF.type, object: t, inferred: true))
end
end
#$stderr.puts("domain(#{self.predicate.pname}): #{statements.map(&:object).map {|r| r.respond_to?(:pname) ? r.pname : r.to_ntriples}}}")
Expand All @@ -229,7 +229,7 @@ def _entail_range
if object.resource? && term = (RDF::Vocabulary.find_term(self.predicate) rescue nil)
term.range.each do |t|
next if t.node? # Don't entail BNodes
statements << RDF::Statement(self.to_h.merge(subject: self.object, predicate: RDF.type, object: t, inferred: true))
statements << RDF::Statement(**self.to_h.merge(subject: self.object, predicate: RDF.type, object: t, inferred: true))
end
end
#$stderr.puts("range(#{self.predicate.pname}): #{statements.map(&:object).map {|r| r.respond_to?(:pname) ? r.pname : r.to_ntriples}}")
Expand All @@ -249,13 +249,13 @@ def _entail_range
# @param [Hash{Symbol => Object}] options ({})
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def domain_compatible_rdfs?(resource, queryable, options = {})
def domain_compatible_rdfs?(resource, queryable, **options)
raise RDF::Reasoner::Error, "#{self} can't get domains" unless property?
domains = Array(self.domain).reject(&:node?) - [RDF::OWL.Thing, RDF::RDFS.Resource]

# Fully entailed types of the resource
types = options.fetch(:types) do
queryable.query(subject: resource, predicate: RDF.type).
queryable.query({subject: resource, predicate: RDF.type}).
map {|s| (t = (RDF::Vocabulary.find_term(s.object)) rescue nil) && t.entail(:subClassOf)}.
flatten.
uniq.
Expand All @@ -276,7 +276,7 @@ def domain_compatible_rdfs?(resource, queryable, options = {})
# @param [Hash{Symbol => Object}] options ({})
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def range_compatible_rdfs?(resource, queryable, options = {})
def range_compatible_rdfs?(resource, queryable, **options)
raise RDF::Reasoner::Error, "#{self} can't get ranges" unless property?
if !(ranges = Array(self.range).reject(&:node?) - [RDF::OWL.Thing, RDF::RDFS.Resource]).empty?
if resource.literal?
Expand Down Expand Up @@ -337,7 +337,7 @@ def range_compatible_rdfs?(resource, queryable, options = {})
else
# Fully entailed types of the resource
types = options.fetch(:types) do
queryable.query(subject: resource, predicate: RDF.type).
queryable.query({subject: resource, predicate: RDF.type}).
map {|s| (t = (RDF::Vocabulary.find_term(s.object) rescue nil)) && t.entail(:subClassOf)}.
flatten.
uniq.
Expand Down
18 changes: 9 additions & 9 deletions lib/rdf/reasoner/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ module Schema
# @param [Hash{Symbol => Object}] options
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def domain_compatible_schema?(resource, queryable, options = {})
def domain_compatible_schema?(resource, queryable, **options)
raise RDF::Reasoner::Error, "#{self} can't get domains" unless property?
domains = Array(self.domainIncludes) - [RDF::OWL.Thing]

# Fully entailed types of the resource
types = entailed_types(resource, queryable, options) unless domains.empty?
types = entailed_types(resource, queryable, **options) unless domains.empty?

# Every domain must match some entailed type
resource_acceptable = Array(types).empty? || domains.any? {|d| types.include?(d)}

# Resource may still be acceptable if types include schema:Role, and any any other resource references `resource` using this property
resource_acceptable ||
types.include?(RDF::Vocab::SCHEMA.Role) &&
!queryable.query(predicate: self, object: resource).empty?
!queryable.query({predicate: self, object: resource}).empty?
end

##
Expand All @@ -52,7 +52,7 @@ def domain_compatible_schema?(resource, queryable, options = {})
# @param [Hash{Symbol => Object}] options ({})
# @option options [Array<RDF::Vocabulary::Term>] :types
# Fully entailed types of resource, if not provided, they are queried
def range_compatible_schema?(resource, queryable, options = {})
def range_compatible_schema?(resource, queryable, **options)
raise RDF::Reasoner::Error, "#{self} can't get ranges" unless property?
if !(ranges = Array(self.rangeIncludes) - [RDF::OWL.Thing]).empty?
if resource.literal?
Expand Down Expand Up @@ -123,12 +123,12 @@ def range_compatible_schema?(resource, queryable, options = {})
true # schema:URL matches URI resources
elsif ranges == [RDF::Vocab::SCHEMA.Text] && resource.uri?
# Allowed if resource is untyped
entailed_types(resource, queryable, options).empty?
entailed_types(resource, queryable, **options).empty?
elsif literal_range?(ranges)
false # If resource isn't literal, this is a range violation
else
# Fully entailed types of the resource
types = entailed_types(resource, queryable, options)
types = entailed_types(resource, queryable, **options)

# Every range must match some entailed type
resource_acceptable = Array(types).empty? || ranges.any? {|d| types.include?(d)}
Expand All @@ -138,7 +138,7 @@ def range_compatible_schema?(resource, queryable, options = {})

# Resource also acceptable if it is a Role, and the Role object contains the same predicate having a compatible object
types.include?(RDF::Vocab::SCHEMA.Role) &&
queryable.query(subject: resource, predicate: self).any? do |stmt|
queryable.query({subject: resource, predicate: self}).any? do |stmt|
acc = self.range_compatible_schema?(stmt.object, queryable)
acc
end ||
Expand Down Expand Up @@ -174,9 +174,9 @@ def self.included(mod)

private
# Fully entailed types
def entailed_types(resource, queryable, options = {})
def entailed_types(resource, queryable, **options)
options.fetch(:types) do
queryable.query(subject: resource, predicate: RDF.type).
queryable.query({subject: resource, predicate: RDF.type}).
map {|s| (t = (RDF::Vocabulary.find_term(s.object) rescue nil)) && t.entail(:subClassOf)}.
flatten.
uniq.
Expand Down
18 changes: 9 additions & 9 deletions rdf-reasoner.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ Gem::Specification.new do |gem|
the vocabulary ruleset. This can be used to implement
SPARQL Entailment Regimes.).gsub(/\s+/m, ' ')

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-vocab', '~> 3.0'
gem.add_runtime_dependency 'rdf-xsd', '~> 3.0'
gem.add_runtime_dependency 'rdf', '~> 3.1'
gem.add_runtime_dependency 'rdf-vocab', '~> 3.1'
gem.add_runtime_dependency 'rdf-xsd', '~> 3.1'

gem.add_development_dependency 'rdf-spec', '~> 3.0'
gem.add_development_dependency 'rdf-turtle', '~> 3.0'
gem.add_development_dependency 'json-ld', '~> 3.0'
gem.add_development_dependency 'rdf-spec', '~> 3.1'
gem.add_development_dependency 'rdf-turtle', '~> 3.1'
gem.add_development_dependency 'json-ld', '~> 3.1'
gem.add_development_dependency 'equivalent-xml', '~> 0.6'
gem.add_development_dependency 'rspec', '~> 3.8'
gem.add_development_dependency 'yard' , '~> 0.9.19'
gem.add_development_dependency 'rspec', '~> 3.9'
gem.add_development_dependency 'yard' , '~> 0.9.20'
gem.post_install_message = nil
end
8 changes: 4 additions & 4 deletions script/reason
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

require 'getoptlong'

def run(reader, options)
def run(reader, **options)
repo = RDF::Repository.new << reader
stmt_cnt = repo.count
prefixes = reader.prefixes
Expand Down Expand Up @@ -96,13 +96,13 @@ end

if ARGV.empty?
s = input ? input : $stdin.read
RDF::Reader.for(options[:input_format] || :ntriples).new(input, options) do |reader|
run(reader, options)
RDF::Reader.for(options[:input_format] || :ntriples).new(input, **options) do |reader|
run(reader, **options)
end
else
ARGV.each do |file|
RDF::Reader.open(file, parser_options) do |reader|
run(reader, options)
run(reader, **options)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/suite_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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

0 comments on commit c648baa

Please sign in to comment.