ABLE 2.0.0 07/02/2003 10:25:01

com.ibm.able.rules
Class AblePredicateEngine

java.lang.Object
  |
  +--com.ibm.able.rules.AbleInferenceEngine
        |
        +--com.ibm.able.rules.AblePredicateEngine
All Implemented Interfaces:
java.io.Serializable

public class AblePredicateEngine
extends AbleInferenceEngine
implements java.io.Serializable

This class provides the control code and inferencing algorithm for processing a set of Predicate rules in a ruleblock using backward chaining with backtracking (similar to Prolog).

The AblePredicateEngine processes AbleAssertionRules and AblePredicateRules and ignores all others. The control property ARL.Goal must be set to point to a predicate referenced in the head of one or more predicate facts or rules in the ruleblock.

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, AbleAssertionRule, AblePredicateRule, Serialized Form

Field Summary
protected  java.util.Hashtable cutTable
           
protected  boolean findAllSolutions
          True if we are to find all possible solutions False if we are to find first solution only
protected  java.util.Vector globalClauseLists
           
protected  AblePredicateQuery myGoal
          The PredicateGoal() specified in the ruleset
protected  java.util.Vector myGoalList
          Predicates from the predicate query
protected  java.util.Vector solutionList
          Set of all solutions found for the query
 
Fields inherited from class com.ibm.able.rules.AbleInferenceEngine
myDebugLevel, myRuleBlock, myRuleSet, myRulesFiredCount, myTracer, myWorkingMemory
 
Constructor Summary
AblePredicateEngine(AbleRuleSet theRuleSet, AbleLogger theTracer, AbleRuleBlock theRuleBlock)
          Create a new inference engine.
 
Method Summary
protected  void applyGoalBindings(java.util.Vector bindings)
          Apply the value of match variables to any unbound goal variables Remove the binding from the list once it is applied
protected  boolean assert_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean asserta_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean assertz_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean atom_chars_2(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean atom_concat_3(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean atom_length_2(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean atom_number_2(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean backwardChain(java.util.Vector goalList, java.util.Vector goalBindings, int level)
          Given a goal variable, apply inverse moves and work toward the intial state:
protected  boolean call_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean consult_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
static java.lang.String Copyright()
          Determine the copyright of this class.
protected  boolean functor_3(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
 java.lang.Object getControlParameter(java.lang.String theControlParameter)
          Returns the specified control parameter on the associated inference engine.
 AblePredicateQuery getPredicateQuery()
           
 java.util.Vector getSolutionList()
           
 void infer(AbleRuleBlock theRuleBlock)
          Fire the rules in the ruleblock using Predicate rules of backward chaining inferencing: given a goal variable, apply inverse moves and work toward the intial state.
 void init()
          Initialize the predicate inference engine by adding all predicate facts and rules to the working memory.
protected  boolean isList_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
 boolean isRuleBlockValid(AbleRuleBlock theRuleBlock)
          Make sure the current ruleblock is "executable" by this inference engine.
protected  boolean match(java.lang.Object term1, java.lang.Object term2, java.util.Vector bindings, java.util.Vector goalBindings)
          This is the major method in this inference engine It unifies two predicates, binds local variables as required and returns a list of goalBindings (when both vars are unbound) Note: this method causes side-effects, local variables are bound, so they must be unbound to restore predicates to initial condition in case of failure Returns true if term1 matches (unifies) with term2, false otherwise
protected  boolean matchLists(AblePredicate list1, AblePredicate list2, java.util.Vector bindings, java.util.Vector goalBindings)
          See if list1 matches (unifies) with list2 Uses standard list notation .(X .(Y, [])) etc.
protected  boolean member_2(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean nonvar_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean retract_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean retractall_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
 void setControlParameter(java.lang.String theControlParameter, java.lang.Object theValue)
          Set the specified control parameter on the associated inference engine.
protected  boolean sub_atom_5(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean unify_2(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean univ_2(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
protected  boolean var_1(AblePredicate theGoal, java.util.Vector goalList, java.util.Vector goalBindings, int level)
           
 
Methods inherited from class com.ibm.able.rules.AbleInferenceEngine
askUser, conditionalRulesValid, evalAntecedentClause, evalAntecedentExpression, evalAssertionClause, evalAssertionRule, evalConditionalRule, evalConsequentClause, evalDoUntilRule, evalDoWhileRule, evalForLoopRule, evalIfThenElseRule, evalPatternMatchRule, evaluateDoActions, evalWhileDoRule, fireEngineBreakpoint, firePropertyChange, getRuleSet, getRulesFiredCount, getWorkingMemory, processAssertions, processConsequent, processRuleBlock, resetRuleSet, setControlParameters, setDebugLevel, setRuleSet, setWorkingMemory, startDebugConsole, stopDebugConsole, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myGoal

protected AblePredicateQuery myGoal
The PredicateGoal() specified in the ruleset

solutionList

protected java.util.Vector solutionList
Set of all solutions found for the query

findAllSolutions

protected boolean findAllSolutions
True if we are to find all possible solutions False if we are to find first solution only

myGoalList

protected java.util.Vector myGoalList
Predicates from the predicate query

globalClauseLists

protected java.util.Vector globalClauseLists

cutTable

protected java.util.Hashtable cutTable
Constructor Detail

AblePredicateEngine

public AblePredicateEngine(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.

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

  • Conditional rules
  • if-then-else rules
  • Pattern match rules
  • Iteration rules

    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.

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

  • init

    public void init()
              throws AbleException
    Initialize the predicate inference engine by adding all predicate facts and rules to the working memory.
    Overrides:
    init in class AbleInferenceEngine

    infer

    public void infer(AbleRuleBlock theRuleBlock)
               throws AbleDataException
    Fire the rules in the ruleblock using Predicate rules of backward chaining inferencing: given a goal variable, apply inverse moves and work toward the intial state.

    The infer() method is called by the AbleRuleSet process() method as part of the overall ruleset bean processing sequence.

    The order of processing is as follows:

    1. Sequentially process all assertion rules in the ruleblock.
    2. Evaluate all enabled Predicate rules using backward chaining until the goal is reached or inferencing fails to find the goal.
    Overrides:
    infer in class AbleInferenceEngine
    Parameters:
    theRuleBlock - The ruleblock containing the rules to be processed.

    Throws:
    AbleDataException - When any error occurs.

    matchLists

    protected boolean matchLists(AblePredicate list1,
                                 AblePredicate list2,
                                 java.util.Vector bindings,
                                 java.util.Vector goalBindings)
                          throws AbleDataException
    See if list1 matches (unifies) with list2 Uses standard list notation .(X .(Y, [])) etc. If so, return true and a vector of bindings If not, return false

    match

    protected boolean match(java.lang.Object term1,
                            java.lang.Object term2,
                            java.util.Vector bindings,
                            java.util.Vector goalBindings)
                     throws AbleDataException
    This is the major method in this inference engine It unifies two predicates, binds local variables as required and returns a list of goalBindings (when both vars are unbound) Note: this method causes side-effects, local variables are bound, so they must be unbound to restore predicates to initial condition in case of failure Returns true if term1 matches (unifies) with term2, false otherwise

    backwardChain

    protected boolean backwardChain(java.util.Vector goalList,
                                    java.util.Vector goalBindings,
                                    int level)
                             throws AbleDataException
    Given a goal variable, apply inverse moves and work toward the intial state:
    Parameters:
    theGoal - Must be an AblePredicateQuery object, containing one or more AblePredicates.


    applyGoalBindings

    protected void applyGoalBindings(java.util.Vector bindings)
                              throws AbleDataException
    Apply the value of match variables to any unbound goal variables Remove the binding from the list once it is applied

    getSolutionList

    public final java.util.Vector getSolutionList()

    setControlParameter

    public void setControlParameter(java.lang.String theControlParameter,
                                    java.lang.Object theValue)
                             throws AbleDataException
    Set the specified control parameter on the associated inference engine. Predicate supports "Goal" and "FindAllSolutions".
    Overrides:
    setControlParameter in class AbleInferenceEngine

    getControlParameter

    public java.lang.Object getControlParameter(java.lang.String theControlParameter)
                                         throws AbleDataException
    Returns the specified control parameter on the associated inference engine. Predicate supports "Goal" and "FindAllSolutions".
    Overrides:
    getControlParameter in class AbleInferenceEngine

    getPredicateQuery

    public AblePredicateQuery getPredicateQuery()

    isList_1

    protected boolean isList_1(AblePredicate theGoal,
                               java.util.Vector goalList,
                               java.util.Vector goalBindings,
                               int level)
                        throws AbleDataException

    call_1

    protected boolean call_1(AblePredicate theGoal,
                             java.util.Vector goalList,
                             java.util.Vector goalBindings,
                             int level)
                      throws AbleDataException

    atom_chars_2

    protected boolean atom_chars_2(AblePredicate theGoal,
                                   java.util.Vector goalList,
                                   java.util.Vector goalBindings,
                                   int level)
                            throws AbleDataException

    atom_concat_3

    protected boolean atom_concat_3(AblePredicate theGoal,
                                    java.util.Vector goalList,
                                    java.util.Vector goalBindings,
                                    int level)
                             throws AbleDataException

    sub_atom_5

    protected boolean sub_atom_5(AblePredicate theGoal,
                                 java.util.Vector goalList,
                                 java.util.Vector goalBindings,
                                 int level)
                          throws AbleDataException

    atom_number_2

    protected boolean atom_number_2(AblePredicate theGoal,
                                    java.util.Vector goalList,
                                    java.util.Vector goalBindings,
                                    int level)
                             throws AbleDataException

    atom_length_2

    protected boolean atom_length_2(AblePredicate theGoal,
                                    java.util.Vector goalList,
                                    java.util.Vector goalBindings,
                                    int level)
                             throws AbleDataException

    functor_3

    protected boolean functor_3(AblePredicate theGoal,
                                java.util.Vector goalList,
                                java.util.Vector goalBindings,
                                int level)
                         throws AbleDataException

    unify_2

    protected boolean unify_2(AblePredicate theGoal,
                              java.util.Vector goalList,
                              java.util.Vector goalBindings,
                              int level)
                       throws AbleDataException

    consult_1

    protected boolean consult_1(AblePredicate theGoal,
                                java.util.Vector goalList,
                                java.util.Vector goalBindings,
                                int level)
                         throws AbleDataException

    assert_1

    protected boolean assert_1(AblePredicate theGoal,
                               java.util.Vector goalList,
                               java.util.Vector goalBindings,
                               int level)
                        throws AbleDataException

    asserta_1

    protected boolean asserta_1(AblePredicate theGoal,
                                java.util.Vector goalList,
                                java.util.Vector goalBindings,
                                int level)
                         throws AbleDataException

    assertz_1

    protected boolean assertz_1(AblePredicate theGoal,
                                java.util.Vector goalList,
                                java.util.Vector goalBindings,
                                int level)
                         throws AbleDataException

    retract_1

    protected boolean retract_1(AblePredicate theGoal,
                                java.util.Vector goalList,
                                java.util.Vector goalBindings,
                                int level)
                         throws AbleDataException

    retractall_1

    protected boolean retractall_1(AblePredicate theGoal,
                                   java.util.Vector goalList,
                                   java.util.Vector goalBindings,
                                   int level)
                            throws AbleDataException

    member_2

    protected boolean member_2(AblePredicate theGoal,
                               java.util.Vector goalList,
                               java.util.Vector goalBindings,
                               int level)
                        throws AbleDataException

    var_1

    protected boolean var_1(AblePredicate theGoal,
                            java.util.Vector goalList,
                            java.util.Vector goalBindings,
                            int level)
                     throws AbleDataException

    nonvar_1

    protected boolean nonvar_1(AblePredicate theGoal,
                               java.util.Vector goalList,
                               java.util.Vector goalBindings,
                               int level)
                        throws AbleDataException

    univ_2

    protected boolean univ_2(AblePredicate theGoal,
                             java.util.Vector goalList,
                             java.util.Vector goalBindings,
                             int level)
                      throws AbleDataException

    Copyright

    public static java.lang.String Copyright()
    Determine the copyright of this class.
    Returns:
    A String containing this class's copyright statement.

    ABLE 2.0.0 07/02/2003 10:25:01

    (C) Copyright IBM Corporation 1999, 2003