Module: RDF::Enumerable
- Defined in:
- lib/rdf/reasoner/extensions.rb
Constant Summary collapse
- @@entailments =
{}
Class Method Summary collapse
-
.add_entailment(method, proc) ⇒ Object
Add an entailment method.
Instance Method Summary collapse
-
#entail(*rules, &block) ⇒ Object
Perform entailments on this enumerable in a single pass, yielding entailed statements.
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
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 #entail ⇒ Enumerator
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.
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 |