Module: RuleEngineMixin

Defined in:
lib/activerdf_rules/rule_engine_mixin.rb

Overview

This module may be included in any writeable ActiveRDF adapter in order to have automatic rule processing every time a triple is added to the database, and it will continue to process the rules until none of the rules will add new information to the database.

Example:

class << adapter
  include RuleEngineMixin
end
adapter.rule_engine = RuleEngine.new :rule_base => RuleEngine::RDFSRuleBase

Notice that you must set the rule_engine attribute after the module is mixed in. If you do not specify a RuleEngine, then automatic rule processing will NOT take place.

There are three included RuleBases two for RDF Schema, and one for OWL.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/activerdf_rules/rule_engine_mixin.rb', line 18

def self.included(base)#:nodoc:
  base.class_eval do
    attr_accessor :rule_engine
    attr_accessor :disable_rules
    alias _add add
    
    # Adding a triple to the database will trigger rule processing and it
    # will continue to process rules until none of the rules will add new
    # information to the database.
    def add(*a)
      r = _add(*a)
      unless @disable_rules || @rule_engine.nil?
        @disable_rules = true
        while @rule_engine.process_rules; end
        @disable_rules = false
      end
      r
    end
  end
end