A partial RDFS/OWL/schema.org reasoner for RDF.rb.
Reasons over RDFS/OWL vocabularies and schema.org to generate statements which are entailed based on base RDFS/OWL rules along with vocabulary information. It can also be used to ask specific questions, such as if a given object is consistent with the vocabulary ruleset. This can be used to implement SPARQL Entailment Regimes and RDF Schema entailment.
- Entail rdfs:subClassOfgenerating an array of terms which are ancestors of the subject.
- Entail rdfs:subPropertyOfgenerating an array of terms which are ancestors of the subject.
- Entail rdfs:domainandrdfs:rangeaddingrdf:typeassertions on the subject or object.
- Inverse rdfs:subClassOfentailment, to find descendant classes of the subject term.
- Inverse rdfs:subPropertyOfentailment, to find descendant properties of the subject term.
- Entail owl:equivalentClassgenerating an array of terms equivalent to the subject.
- Entail owl:equivalentPropertygenerating an array of terms equivalent to the subject.
- domainCompatible?determines if a particular resource is compatible with the domain definition of a given predicate, based on the intersection of entailed subclasses with the property domain.
- rangeCompatible?determines if a particular resource is compatible with the range definition of a given predicate, based on the intersection of entailed subclasses or literal types with the property domain.
- adds entailandlintcommands to therdfcommand line interface
Domain and Range entailment include specific rules for schema.org vocabularies.
- A plain literal is an acceptable value for any property.
- If resourceis of typeschema:Role,resourceis domain acceptable if any other resource referencesresourceusing the same property.
- If resourceis of typeschema:Role, it is range acceptable if it has the same property with an acceptable value.
- If resourceis of typerdf:List(must be previously entailed), it is range acceptable if all members of the list are otherwise range acceptable on the same property.
As loading vocabularies can dominate processing time, the RDF::Vocabulary.limit_vocabs method can be used to set a specific set of vocabularies over which to reason. For example:
RDF::Vocabulary.limit_vocabs(:rdf, :rdf, :schema)
will limit the vocabularies which are returned from RDF::Vocabulary.each, which is used for reasoning and other operations over vocabularies and terms.
require 'rdf/reasoner'
RDF::Reasoner.apply(:rdfs)
term = RDF::Vocabulary.find_term("http://xmlns.com/foaf/0.1/Person")
term.entail(:subClassOf)
  # => [
    foaf:Agent,
    http://www.w3.org/2000/10/swap/pim/contact#Person,
    geo:SpatialThing,
    foaf:Person
  ]
require 'rdf/reasoner'
RDF::Reasoner.apply(:rdfs)
term = RDF::Vocab::FOAF.Person
term.entail(:subClass) # => [foaf:Person, mo:SoloMusicArtist]
require 'rdf/reasoner'
require 'rdf/turtle'
RDF::Reasoner.apply(:rdfs)
graph = RDF::Graph.load("etc/doap.ttl")
subj = RDF::URI("https://rubygems.org/gems/rdf-reasoner")
RDF::Vocab::DOAP.name.domain_compatible?(subj, graph) # => true
require 'rdf/reasoner'
require 'rdf/turtle'
RDF::Reasoner.apply(:rdfs)
graph = RDF::Graph.load("etc/doap.ttl")
obj = RDF::Literal(Date.new)
RDF::Vocab::DOAP.created.range_compatible?(obj, graph) # => true
require 'rdf/reasoner'
require 'rdf/turtle'
RDF::Reasoner.apply(:owl)
graph = RDF::Graph.load("etc/doap.ttl")
graph.entail!(:equivalentClass)
require 'rdf/reasoner'
require 'rdf/turtle'
RDF::Reasoner.apply(:rdfs, :owl)
graph = RDF::Graph.load("etc/doap.ttl")
graph.enum_statement.entail.count # >= graph.enum_statement.count
require 'rdf/reasoner'
require 'rdf/turtle'
RDF::Reasoner.apply(:rdfs, :owl)
graph = RDF::Graph.load("etc/doap.ttl")
graph.entail!
messages = graph.lint
messages.each do |kind, term_messages|
  term_messages.each do |term, messages|
    options[:output].puts "#{kind}  #{term}"
    messages.each {|m| options[:output].puts "  #{m}"}
  end
end
The rdf command-line interface is extended with entail and lint commands. Entail can be used in combination, with serialize to generate an output graph representation including entailed triples.
- Do your best to adhere to the existing coding conventions and idioms.
- Don't use hard tabs, and don't leave trailing whitespace on any line.
Before committing, run git diff --checkto make sure of this.
- Do document every method you add using YARD annotations. Read the tutorial or just look at the existing code for examples.
- Don't touch the .gemspec,VERSIONorAUTHORSfiles. If you need to change them, do so on your private branch only.
- Do feel free to add yourself to the CREDITSfile and the corresponding list in the theREADME. 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 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 organization.
This is free and unencumbered public domain software. For more information, see https://unlicense.org/ or the accompanying {file:UNLICENSE} file.
