ABLE 2.3.0 07/13/2005 14:21:00

com.ibm.able.rules
Class AblePatternMatchEngine

java.lang.Object
  extended bycom.ibm.able.rules.AbleInferenceEngine
      extended bycom.ibm.able.rules.AblePatternMatchEngine
All Implemented Interfaces:
java.io.Serializable

public class AblePatternMatchEngine
extends AbleInferenceEngine
implements java.io.Serializable

This class provides the inferencing algorithm for processing a set of pattern match rules in a ruleblock using data-driven or forward chaining. This engine implements the Rete' network algorithm which caches partial matches. It will produce identical results to the AblePatternMatchLiteEngine but with be more efficient when used for problems with large numbers of rules and/or working memory objects. When objects are added to working memory, only those test conditions which must be evaluated are processed.

The AblePatternMatchEngine processes AbleAssertionRules and AblePatternMatchRules and ignores all others.

The major processing method is infer() which is called by the AbleRuleSet bean as part of the normal bean process() method.

Instances of this class are not directly constructed by the user but are dynamically created by the AbleRuleBlock init() method.

See Also:
AbleRuleSet, AbleRuleBlock, AblePatternMatchRule, AblePatternMatchLiteEngine, Serialized Form

Nested Class Summary
protected static class AblePatternMatchEngine.patternMatchRuleComparator
           
 
Field Summary
protected  java.util.TreeSet conflictSet
           
protected  java.util.Hashtable firedRuleBindingPairs
           
protected  AblePatternMatchNetwork myPatternMatchNet
           
 
Fields inherited from class com.ibm.able.rules.AbleInferenceEngine
myDebugLevel, myRuleBlock, myRuleSet, myRulesFiredCount, myTracer, myWorkingMemory
 
Constructor Summary
AblePatternMatchEngine(AbleRuleSet theRuleSet, AbleLogger theTracer, AbleRuleBlock theRuleBlock)
          Create a new inference engine.
 
Method Summary
 boolean addRuleToConflictSet(AblePatternMatchRule theRule)
          Inserts the Rule into the conflict set based on priority and specificity.
 AbleWorkingMemory allocateWorkingMemory()
          Retrieve the workingMemory object (may be null).
protected  void evalPatternMatchRule(AblePatternMatchRule theRule)
          Evaluate a pattern-match (when-do) rule.
 java.lang.Object getControlParameter(java.lang.String theControlParameter)
          Returns the specified control parameter on the associated inference engine.
 void infer(AbleRuleBlock theRuleBlock)
          Fire the rules in the ruleset using pattern match rules and forward chaining inferencing.
 boolean isRuleBlockValid(AbleRuleBlock theRuleBlock)
          Make sure the current ruleblock is "executable" by this inference engine.
protected  void logConflictSet(java.util.SortedSet conflictSet)
          Write the contents of the conflict set (triggered rules) to the Inference trace log
protected  void logWorkingMemory()
          Write the contents of working memory out to the Inference trace log.
 boolean removeRuleFromConflictSet(AblePatternMatchRule theRule)
          Inserts the Rule into the conflict set based on priority and specificity.
 void setControlParameter(java.lang.String theControlParameter, java.lang.Object theValue)
          Set the specified control parameter on the associated inference engine.
 
Methods inherited from class com.ibm.able.rules.AbleInferenceEngine
askUser, conditionalRulesValid, evalAntecedentClause, evalAntecedentExpression, evalAssertionClause, evalAssertionRule, evalConditionalRule, evalConsequentClause, evalDoUntilRule, evalDoWhileRule, evalForLoopRule, evalIfThenElseRule, evalSwitchRule, evaluateDoActions, evalWhileDoRule, fireEngineBreakpoint, firePropertyChange, getRuleSet, getRulesFiredCount, getWorkingMemory, init, processAssertions, processConsequent, processConsequent, processConsequentClauses, processRuleBlock, reset, resetRuleSet, setControlParameters, setDebugLevel, setInferenceContext, setInferenceContext, setInferenceContext, setRuleSet, setWorkingMemory, startDebugConsole, stopDebugConsole, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myPatternMatchNet

protected AblePatternMatchNetwork myPatternMatchNet

firedRuleBindingPairs

protected transient java.util.Hashtable firedRuleBindingPairs

conflictSet

protected transient java.util.TreeSet conflictSet
Constructor Detail

AblePatternMatchEngine

public AblePatternMatchEngine(AbleRuleSet theRuleSet,
                              AbleLogger theTracer,
                              AbleRuleBlock theRuleBlock)
Create a new inference engine.

Parameters:
theRuleSet - A ruleset whose context is used for inferencing by this inference engine.

theTracer - A tracer object to which this inference engine can log information. This may be null, in which case no information is logged.

theRuleBlock - A ruleblock whose rules are to be used for inferencing by this inference engine.

Method Detail

isRuleBlockValid

public boolean isRuleBlockValid(AbleRuleBlock theRuleBlock)
Make sure the current ruleblock is "executable" by this inference engine. Only assertion rules and pattern match rules are processed.

The ruleblock is invalid if any of the following are present in the ruleblock:

  • Conditional rule
  • If-then-else rule
  • Predicate rule
  • Iteration rule

    All reasons for validation failures are appended to the AbleRuleSet's myIsExReason variable. If validation fails, the inference engine must call myRuleSet.addIsExReason(java.lang.String) to append the reason.

    Specified by:
    isRuleBlockValid in class AbleInferenceEngine
    Returns:
    true, if the ruleset is OK; false, if the ruleset is not executable.

  • infer

    public void infer(AbleRuleBlock theRuleBlock)
               throws AbleDataException
    Fire the rules in the ruleset using pattern match rules and forward chaining inferencing.

    The order of processing is as follows:

    1. Sequentially process all assertion rules in the ruleblock.
    2. Evaluate all pattern match rules using forward chaining and a working memory.

    Specified by:
    infer in class AbleInferenceEngine
    Parameters:
    theRuleBlock - The ruleblock to be processed.

    Throws:
    AbleDataException - When any error occurs.

    evalPatternMatchRule

    protected void evalPatternMatchRule(AblePatternMatchRule theRule)
                                 throws AbleDataException
    Evaluate a pattern-match (when-do) rule.

    Procesing is as follows:

    Overrides:
    evalPatternMatchRule in class AbleInferenceEngine
    Throws:
    AbleDataException - when the data types are incompatible, or when the relational operator is invalid for the current situation or unrecognized.

    logWorkingMemory

    protected void logWorkingMemory()
    Write the contents of working memory out to the Inference trace log. Trace logging is presumed on.


    logConflictSet

    protected void logConflictSet(java.util.SortedSet conflictSet)
    Write the contents of the conflict set (triggered rules) to the Inference trace log


    addRuleToConflictSet

    public boolean addRuleToConflictSet(AblePatternMatchRule theRule)
    Inserts the Rule into the conflict set based on priority and specificity.

    Parameters:
    theRule - the Rule that needs to be added
    Returns:
    True if the rule was already in the conflict set.

    removeRuleFromConflictSet

    public boolean removeRuleFromConflictSet(AblePatternMatchRule theRule)
    Inserts the Rule into the conflict set based on priority and specificity.

    Parameters:
    theRule - The Rule that needs to be removed.

    setControlParameter

    public void setControlParameter(java.lang.String theControlParameter,
                                    java.lang.Object theValue)
                             throws AbleDataException
    Set the specified control parameter on the associated inference engine.

    Specified by:
    setControlParameter in class AbleInferenceEngine
    Throws:
    AbleDataException

    getControlParameter

    public java.lang.Object getControlParameter(java.lang.String theControlParameter)
                                         throws AbleDataException
    Returns the specified control parameter on the associated inference engine.

    Specified by:
    getControlParameter in class AbleInferenceEngine
    Throws:
    AbleDataException

    allocateWorkingMemory

    public AbleWorkingMemory allocateWorkingMemory()
    Description copied from class: AbleInferenceEngine
    Retrieve the workingMemory object (may be null).

    Overrides:
    allocateWorkingMemory in class AbleInferenceEngine
    Returns:
    The current working memory, or null if no working memory exists.

    ABLE 2.3.0 07/13/2005 14:21:00

    (C) Copyright IBM Corporation 1999, 2005