jeops
Class AbstractRuleBase

java.lang.Object
  |
  +--jeops.AbstractRuleBase

public abstract class AbstractRuleBase
extends java.lang.Object
implements java.lang.Cloneable

A generic rule base of Jeops. Objects of this class represent the pairs that it can be treated generically by any rule base.

Version:
0.03 07.04.2000 Method for retrieving an array of dependencies between local declarations and declarations. The two-dimensional array will have as many rows as there are local declarations; each row will have the object bound to the local declaration in the first column, and the remaining columns will have the objects bound to the regular declaration that created the locally declared object.
Author:
Carlos Figueira Filho (csff@di.ufpe.br)

Constructor Summary
AbstractRuleBase(ObjectBase objectBase, AbstractKnowledgeBase knowledgeBase)
          Class constructor.
 
Method Summary
 void assert(java.lang.Object obj)
          Adds an object into this rule base.
abstract  boolean checkPrecForDeclaration(int ruleIndex, int declIndex)
          Checks whether all the preconditions of a rule which reference only the elements declared up to the given index are true.
abstract  boolean checkPrecondition(int ruleIndex, int precIndex)
          Checks whether some preconditions of some rule in this rule base is satisfied.
 java.lang.Object clone()
          Creates a copy of this object.
 boolean equals(java.lang.Object obj)
           
 void fireRule(int ruleIndex)
          Fires one of the rules in this rule base.
 void flush()
          Removes all the objects from this rule base.
abstract  java.util.Hashtable getClassDeclarationCount()
          Returns a mapping from the classes of the objects declared in the rules to the number of occurrences of each one.
abstract  java.lang.Class getDeclaredClass(int ruleIndex, int declarationIndex)
          Returns the class of an object declared in a rule.
abstract  java.lang.String getDeclaredClassName(int ruleIndex, int declarationIndex)
          Returns the class name of an object declared in a rule.
abstract  java.util.Hashtable getInternalRuleMapping(int ruleIndex)
          Returns a table that maps each declared identifier of a rule into its corresponding value.
abstract  java.lang.Object[][] getLocalDeclarationDependency(int ruleIndex)
          Returns a dependency table between the local declarations and the regular ones.
abstract  int[] getNumberOfDeclarations()
          Returns the number of declarations of the rules in this rule base.
abstract  int[] getNumberOfLocalDeclarations()
          Returns the number of local declarations of the rules in this rule base.
abstract  int[] getNumberOfPreconditions()
          Returns the number of preconditions of the rules in this rule base.
abstract  int getNumberOfRules()
          Returns the number of rules in this base.
abstract  java.lang.Object getObject(int ruleIndex, int declarationIndex)
          Returns an object that represents a declaration of some rule.
 int getRuleIndex()
          Returns the index of the rule that has the focus.
abstract  java.lang.String[] getRuleNames()
          Returns the name of the rules in this rule base.
 int hashCode()
           
 void modified(java.lang.Object obj)
          Tells this base that an object was modified, so that the rules can be retested against the object.
 void retract(java.lang.Object obj)
          Removes an object from this rule base.
abstract  void setObject(int ruleIndex, int declarationIndex, java.lang.Object value)
          Sets an object that represents a declaration of some rule.
 void setRuleIndex(int value)
          Defines the index of the rule that has the focus.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRuleBase

public AbstractRuleBase(ObjectBase objectBase,
                        AbstractKnowledgeBase knowledgeBase)
Class constructor.
Parameters:
objectBase - an object base over with this rule base will work.
knowledgeBase - the knowledge base that contains this rule base.
Method Detail

getRuleIndex

public int getRuleIndex()
Returns the index of the rule that has the focus. A rule is said to have focus when it's ready to be fired, i.e., the variables are filled such as the rule's preconditions are satisfied.
Returns:
the index of the rule that has the focus.

setRuleIndex

public void setRuleIndex(int value)
Defines the index of the rule that has the focus. A rule is said to have focus when it's ready to be fired, i.e., the variables are filled such as the rule's preconditions are satisfied.
Parameters:
value - the index of the rule that has the focus.

getNumberOfRules

public abstract int getNumberOfRules()
Returns the number of rules in this base.
Returns:
the number of rules in this base.

checkPrecondition

public abstract boolean checkPrecondition(int ruleIndex,
                                          int precIndex)
Checks whether some preconditions of some rule in this rule base is satisfied.
Parameters:
ruleIndex - the index of the rule to be checked
precIndex - the index of the precondition to be checked
Returns:
true if the corresponding precondition for the given rule is satisfied. false otherwise.

checkPrecForDeclaration

public abstract boolean checkPrecForDeclaration(int ruleIndex,
                                                int declIndex)
Checks whether all the preconditions of a rule which reference only the elements declared up to the given index are true.
Parameters:
ruleIndex - the index of the rule to be checked
declIndex - the index of the declaration to be checked
Returns:
true if all the preconditions of a rule which reference only the elements declared up to the given index are satisfied; false otherwise.

getInternalRuleMapping

public abstract java.util.Hashtable getInternalRuleMapping(int ruleIndex)
Returns a table that maps each declared identifier of a rule into its corresponding value.
Parameters:
ruleIndex - the index of the rule whose mapping is required.
Returns:
a table that maps each declared identifier of a rule into its corresponding value.

fireRule

public void fireRule(int ruleIndex)
Fires one of the rules in this rule base.
Parameters:
ruleIndex - the index of the rule to be fired.

getNumberOfPreconditions

public abstract int[] getNumberOfPreconditions()
Returns the number of preconditions of the rules in this rule base.
Returns:
the number of preconditions of the rules in this rule base.

getNumberOfDeclarations

public abstract int[] getNumberOfDeclarations()
Returns the number of declarations of the rules in this rule base.
Returns:
the number of declarations of the rules in this rule base.

getNumberOfLocalDeclarations

public abstract int[] getNumberOfLocalDeclarations()
Returns the number of local declarations of the rules in this rule base.
Returns:
the number of local declarations of the rules in this rule base.

getRuleNames

public abstract java.lang.String[] getRuleNames()
Returns the name of the rules in this rule base.
Returns:
the name of the rules in this rule base.

getClassDeclarationCount

public abstract java.util.Hashtable getClassDeclarationCount()
Returns a mapping from the classes of the objects declared in the rules to the number of occurrences of each one.
Returns:
a mapping from the classes of the objects declared in the rules to the number of occurrences of each one.

getDeclaredClassName

public abstract java.lang.String getDeclaredClassName(int ruleIndex,
                                                      int declarationIndex)
Returns the class name of an object declared in a rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration.
Returns:
the class name of the declared object.

getDeclaredClass

public abstract java.lang.Class getDeclaredClass(int ruleIndex,
                                                 int declarationIndex)
Returns the class of an object declared in a rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration.
Returns:
the class of the declared object.

setObject

public abstract void setObject(int ruleIndex,
                               int declarationIndex,
                               java.lang.Object value)
Sets an object that represents a declaration of some rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration in the rule
value - the value of the object being set.

getObject

public abstract java.lang.Object getObject(int ruleIndex,
                                           int declarationIndex)
Returns an object that represents a declaration of some rule.
Parameters:
ruleIndex - the index of the rule
declarationIndex - the index of the declaration in the rule
Returns:
the value of the corresponding object.

getLocalDeclarationDependency

public abstract java.lang.Object[][] getLocalDeclarationDependency(int ruleIndex)
Returns a dependency table between the local declarations and the regular ones. It will be a two-dimensional array that will have as many rows as there are local declarations; each row will have the object bound to the local declaration in the first column, and the remaining columns will have the objects bound to the regular declaration that created the locally declared object.
Parameters:
ruleIndex - the index of the rule.
Returns:
a two-dimensional array with the dependencies between the local declarations and the regular ones.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

assert

public void assert(java.lang.Object obj)
Adds an object into this rule base.
Parameters:
obj - the object to be inserted into this base.

retract

public void retract(java.lang.Object obj)
Removes an object from this rule base.
Parameters:
obj - the object to be removed from this base.

flush

public void flush()
Removes all the objects from this rule base.

modified

public void modified(java.lang.Object obj)
Tells this base that an object was modified, so that the rules can be retested against the object.
Parameters:
obj - the object that was modified.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a copy of this object.
Returns:
a clone of this object.
Throws:
java.lang.CloneNotSupportedException - if the class Object doesn't support cloning; it should not happen.