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)


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

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)


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rdf/reasoner/extensions.rb', line 114

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