org.jscience.computing.ai.expertsystem
Class AbstractKnowledgeBase

java.lang.Object
  extended by org.jscience.computing.ai.expertsystem.AbstractKnowledgeBase
All Implemented Interfaces:
InternalConflictSetListener

public abstract class AbstractKnowledgeBase
extends java.lang.Object
implements InternalConflictSetListener

The main class of JEOPS. This class models the knowledge the agent has about the world. In it are stored the facts (objects) and (production) rules that act on the first. This class must be subclassed by a concrete knowledge base so that it is provided with the object and rule base needed for work.


Field Summary
protected  java.util.Map entryPoints
          The map that takes class names into the entry points of the Rete network.
 
Constructor Summary
AbstractKnowledgeBase(ConflictSet conflictSet)
          Creates a new knowledge base.
 
Method Summary
 void addConflictSetListener(RuleFireListener l)
          Adds the specified conflict set listener to receive events from this knowledge base.
 void addRuleFireListener(RuleFireListener l)
          Adds the specified rule fire listener to receive events from this knowledge base.
protected abstract  AbstractRuleBase createRuleBase()
          Factory method, used to instantiate the actual rule base.
 void flush()
          Remove all facts (objects) of the object base.
 AbstractRuleBase getRuleBase()
          Returns the (production) rule base of this knowledge base.
 void insert(java.lang.Object obj)
          Inserts a new object in this knowledge base.
 void internalElementAdded(InternalConflictSetEvent e)
          Invoked when an element is added to the conflict set.
 void internalElementRemoved(InternalConflictSetEvent e)
          Invoked when an element is removed from the conflict set.
protected  void modified(java.lang.Object obj)
          Informs this base that an object was modified, so that the rules can be retested against the object.
 void newFirableRule(int ruleIndex, java.lang.Object[] objects)
          Receives a message from the Rete network indicating that the given rule and objects should be inserted into the conflict set.
 java.util.Vector objects(java.lang.String className)
          Returns the objects of a given class.
 void removeConflictSetListener(RuleFireListener l)
          Removes the specified conflict set listener so that it no longer receives conflict set events from this knowledge base.
 void removeRuleFireListener(RuleFireListener l)
          Removes the specified rule fire listener so that it no longer receives rule fire events from this knowledge base.
 boolean retract(java.lang.Object obj)
          Removes a given object from this knowledge base.
 void run()
          Fires the rules in the rule base with the objects present in the object base, until no rule is fireable anymore.
 void setConflictSet(ConflictSet conflictSet)
          Defines a conflict set policy for this knowledge base.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entryPoints

protected java.util.Map entryPoints
The map that takes class names into the entry points of the Rete network. Each object enters the network at a node of its actual class.

Constructor Detail

AbstractKnowledgeBase

public AbstractKnowledgeBase(ConflictSet conflictSet)
Creates a new knowledge base.

Parameters:
conflictSet - the conflict set associated with this knowledge base.
Method Detail

createRuleBase

protected abstract AbstractRuleBase createRuleBase()
Factory method, used to instantiate the actual rule base.

Returns:
the rule base to be used with this knowledge base.

addConflictSetListener

public void addConflictSetListener(RuleFireListener l)
Adds the specified conflict set listener to receive events from this knowledge base.

Parameters:
l - the conflict set listener

addRuleFireListener

public void addRuleFireListener(RuleFireListener l)
Adds the specified rule fire listener to receive events from this knowledge base.

Parameters:
l - the rule base listener

insert

public void insert(java.lang.Object obj)
Inserts a new object in this knowledge base.

Parameters:
obj - the object being inserted.

flush

public void flush()
Remove all facts (objects) of the object base.


getRuleBase

public AbstractRuleBase getRuleBase()
Returns the (production) rule base of this knowledge base.

Returns:
the (production) rule base of this knowledge base.

internalElementAdded

public void internalElementAdded(InternalConflictSetEvent e)
Invoked when an element is added to the conflict set.

Specified by:
internalElementAdded in interface InternalConflictSetListener
Parameters:
e - the conflict set event.

internalElementRemoved

public void internalElementRemoved(InternalConflictSetEvent e)
Invoked when an element is removed from the conflict set.

Specified by:
internalElementRemoved in interface InternalConflictSetListener
Parameters:
e - the conflict set event.

modified

protected void modified(java.lang.Object obj)
Informs this base that an object was modified, so that the rules can be retested against the object.

Parameters:
obj - the object that was modified.

newFirableRule

public void newFirableRule(int ruleIndex,
                           java.lang.Object[] objects)
Receives a message from the Rete network indicating that the given rule and objects should be inserted into the conflict set.

Parameters:
ruleIndex - the index of the firable rule.
objects - the objects that made the rule firable.

objects

public java.util.Vector objects(java.lang.String className)
Returns the objects of a given class.

Parameters:
className - the name of the class.

removeConflictSetListener

public void removeConflictSetListener(RuleFireListener l)
Removes the specified conflict set listener so that it no longer receives conflict set events from this knowledge base.

Parameters:
l - the conflict set listener

removeRuleFireListener

public void removeRuleFireListener(RuleFireListener l)
Removes the specified rule fire listener so that it no longer receives rule fire events from this knowledge base.

Parameters:
l - the rule fire listener

retract

public boolean retract(java.lang.Object obj)
Removes a given object from this knowledge base.

Parameters:
obj - the object being removed.
Returns:
true if the given object belonged to this base; false otherwise.

run

public void run()
Fires the rules in the rule base with the objects present in the object base, until no rule is fireable anymore.


setConflictSet

public void setConflictSet(ConflictSet conflictSet)
Defines a conflict set policy for this knowledge base.

Parameters:
conflictSet - the new conflict set that implements its associated conflict resolution policy.