Module: RDF::Enumerable

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)


148
149
150
# File 'lib/rdf/reasoner/extensions.rb', line 148

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

Instance Method Details

#entail {|statement| ... } ⇒ void #entailEnumerator

Perform entailments on this enumerable in a single pass, yielding entailed statements.

For best results, either run rules separately expanding the enumberated graph, or run repeatedly until no new statements are added to the enumerable containing both original and entailed statements. As ‘:subClassOf` and `:subPropertyOf` entailments are implicitly recursive, this may not be necessary except for extreme cases.

Overloads:

  • #entail {|statement| ... } ⇒ void

    This method returns an undefined value.

    Parameters:

    • *rules (Array<Symbol>)

      Registered entailment method(s).

    Yields:

    • statement

    Yield Parameters:

  • #entailEnumerator

    Parameters:

    • *rules (Array<Symbol>)

      Registered entailment method(s)

    Returns:

    • (Enumerator)


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/rdf/reasoner/extensions.rb', line 169

def entail(*rules, &block)
  if block_given?
    rules = %w(subClassOf subPropertyOf domain range).map(&:to_sym) if rules.empty?

    self.each do |statement|
      rules.each {|rule| statement.entail(rule, &block)}
    end
  else
    # Otherwise, return an Enumerator with the entailed statements
    this = self
    RDF::Queryable::Enumerator.new do |yielder|
      this.entail(*rules) {|y| yielder << y}
    end
  end
end