Module: RDF::Enumerable

Includes:
Isomorphic
Included in:
JSON::LD::Resource, MergeGraph, Normalize::Carroll2001, Normalize::URDNA2015
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-isomorphic-b2a4cf0fe112/lib/rdf/isomorphic.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-63fee6d2320c/lib/rdf/reasoner/extensions.rb

Overview

Extend RDF::Enumerables with these functions.

Constant Summary collapse

@@entailments =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Isomorphic

#bijection_to, #isomorphic_with?

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:



148
149
150
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-63fee6d2320c/lib/rdf/reasoner/extensions.rb', line 148

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

Instance Method Details

#entail {|statement| ... } #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| ... }

    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 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-reasoner-63fee6d2320c/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