Class: RDF::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/reasoner/extensions.rb

Constant Summary collapse

@@entailments =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_entailment(method, proc) ⇒ Object

Add an entailment method. The method accepts no arguments, and returns or yields an array of values associated with the particular entailment method

Parameters:

  • method (Symbol)
  • proc (Proc)


68
69
70
# File 'lib/rdf/reasoner/extensions.rb', line 68

def add_entailment(method, proc)
  @@entailments[method] = proc
end

Instance Method Details

#domain_compatible?(resource, queryable, options = {}) ⇒ Boolean

Determine if the domain of a property term is consistent with the specified resource in ‘queryable`.

Parameters:

  • resource (RDF::Resource)
  • queryable (RDF::Queryable)
  • options (Hash{Symbol => Object}) (defaults to: {})

    ({})

Options Hash (options):

  • :types (Array<RDF::Vocabulary::Term>)

    Fully entailed types of resource, if not provided, they are queried

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/rdf/reasoner/extensions.rb', line 92

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)
  end
end

#entail(method) {|term| ... } ⇒ Array<Term>

Perform an entailment on this term.

Parameters:

  • method (Symbol)

    A registered entailment method

Yields:

  • term

Yield Parameters:

  • term (Term)

Returns:

  • (Array<Term>)


80
81
82
# File 'lib/rdf/reasoner/extensions.rb', line 80

def entail(method, &block)
  self.send(@@entailments.fetch(method), &block)
end

#range_compatible?(resource, queryable, options = {}) ⇒ Boolean

Determine if the range of a property term is consistent with the specified resource in ‘queryable`.

Specific entailment regimes should insert themselves before this to apply the appropriate semantic condition

Parameters:

  • resource (RDF::Resource)
  • queryable (RDF::Queryable)
  • options (Hash{Symbol => Object}) (defaults to: {})

    ({})

Options Hash (options):

  • :types (Array<RDF::Vocabulary::Term>)

    Fully entailed types of resource, if not provided, they are queried

Returns:

  • (Boolean)


108
109
110
111
112
# File 'lib/rdf/reasoner/extensions.rb', line 108

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)
  end
end