jess
Class Rete

java.lang.Object
  |
  +--jess.Rete

public class Rete
extends java.lang.Object
implements java.io.Serializable

The reasoning engine. Executes the built Rete network, and coordinates many other activities.

(C) 1997 Ernest J. Friedman-Hill and Sandia National Laboratories

Author:
Ernest J. Friedman-Hill
See Also:
Serialized Form

Field Summary
static int ACTIVATE
           
static int EVERY_TIME
           
static int INSTALL
           
 
Constructor Summary
Rete()
          Constructors
Rete(java.applet.Applet a)
           
 
Method Summary
 Deffacts addDeffacts(Deffacts df)
          Creates a new deffacts in this object
 Defglobal addDefglobal(Defglobal dg)
          Creates a new Defglobal in this object.
 HasLHS addDefrule(HasLHS dr)
          Creates a new defrule in this object
 Deftemplate addDeftemplate(Deftemplate dt)
          Creates a new deftemplate in this object.
 void addInputRouter(java.lang.String s, java.io.Reader is, boolean consoleLike)
           
 void addJessListener(JessListener jel)
           
 void addOutputRouter(java.lang.String s, java.io.Writer os)
           
 Userfunction addUserfunction(Userfunction uf)
          Creates a new function in this object Will happily destroy an old one.
 Userpackage addUserpackage(Userpackage up)
          Add a Userpackage to this engine.
 int assert(Fact f)
          Assert a fact
 int assertString(java.lang.String s)
          Assert a fact, as a String
 void clear()
          Reinitialize engine Thanks to Karl Mueller for idea
 void clearStorage()
          Clear the storage used by store() and fetch().
 Value executeCommand(java.lang.String cmd)
          Stuff to let Java code call functions inside of us.
 Value fetch(java.lang.String name)
          Retrieve an object previously stored with store().
 Defglobal findDefglobal(java.lang.String name)
           
 HasLHS findDefrule(java.lang.String name)
          Find a defrule object with a certain name
 Deftemplate findDeftemplate(java.lang.String name)
          Find a deftemplate object with a certain name
 Fact findFactByID(int id)
          This 'find' is used by the retract that rules use.
 Userfunction findUserfunction(java.lang.String name)
          Find a userfunction, if there is one.
 java.applet.Applet getApplet()
          Returns the applet this Rete is installed in.
 java.io.PrintWriter getErrStream()
           
 int getEvalSalience()
          Fetch the salience evaluation behaviour
 int getEventMask()
           
 boolean getFactDuplication()
          Returns true if duplicate facts are allowed, false otherwise.
 Context getGlobalContext()
          Fetch the global execution context.
 boolean getInputMode(java.lang.String s)
           
 java.io.Reader getInputRouter(java.lang.String s)
           
 java.io.Writer getOutputRouter(java.lang.String s)
           
 java.io.PrintWriter getOutStream()
           
 boolean getResetGlobals()
          When resetGlobals is true, the initializers of global variables are evaluated when (reset) is executed.
 void halt()
          Jane, stop this crazy thing!
 java.util.Enumeration listActivations()
          Return an Enumeration of all the activiations - i.e, the agenda.
 java.util.Enumeration listDeffacts()
          Return an Enumeration of all the deffacts in this engine.
 java.util.Enumeration listDefglobals()
          Return an Enumeration of all the defglobals in this engine.
 java.util.Enumeration listDefrules()
          Return an Enumeration of all the defrules in this engine.
 java.util.Enumeration listDeftemplates()
          Return an Enumeration of all the deftemplates in this engine, both explicit and implied.
 java.util.Enumeration listFacts()
          Return an Enumeration of all the facts currently on the fact-list
 java.util.Enumeration listFunctions()
          Return an Enumeration of all the functions in this engine: built-in, user, and deffunctions.
 java.util.Enumeration listJessListeners()
           
 java.lang.String ppFacts()
           
 java.lang.String ppFacts(java.lang.String name)
          Return the pretty print forms of all facts, as a big string
 void processPendingFacts()
          DONT call this - it's going to be package-private soon.
 void removeInputRouter(java.lang.String s)
           
 void removeJessListener(JessListener jel)
           
 void removeOutputRouter(java.lang.String s)
           
 void reset()
          Reset the Rete engine.
 Fact retract(Fact f)
          Retract a fact.
 Fact retract(int id)
          Retract a fact by ID, used by rule RHSs.
 Fact retractString(java.lang.String s)
          Karl Mueller NASA/GSFC Code 522.2 (Karl.R.Mueller@gsfc.nasa.gov) 27.January.1998 Retract a fact as a string
 int run()
          Run the actual engine.
 int run(int max)
           
 void setApplet(java.applet.Applet a)
          Associates this Rete with an applet so that, for instance, the (batch) commands will look for scripts using the applet's document base URL.
 void setEvalSalience(int method)
          Set the salience evaluation behaviour.
 void setEventMask(int i)
           
 void setFactDuplication(boolean v)
          Turn fact-duplication on or off.
 void setPendingFact(Fact fact, boolean assert)
           
 void setResetGlobals(boolean reset)
          When resetGlobals is true, the initializers of global variables are evaluated when (reset) is executed.
 java.lang.String setStrategy(Strategy s)
           
 Value store(java.lang.String name, java.lang.Object val)
          Store a value in the engine under a given name for later retrieval by fetch.
 Value store(java.lang.String name, Value val)
          Store a value in the engine under a given name for later retrieval by fetch.
 Value unDefrule(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTALL

public static final int INSTALL

ACTIVATE

public static final int ACTIVATE

EVERY_TIME

public static final int EVERY_TIME
Constructor Detail

Rete

public Rete()
Constructors

Rete

public Rete(java.applet.Applet a)
Parameters:
a -  
Method Detail

getApplet

public java.applet.Applet getApplet()
Returns the applet this Rete is installed in. Returns null if none.
Returns:
The applet

setApplet

public void setApplet(java.applet.Applet a)
Associates this Rete with an applet so that, for instance, the (batch) commands will look for scripts using the applet's document base URL.
Parameters:
a - The applet

getGlobalContext

public final Context getGlobalContext()
Fetch the global execution context.
Returns:
The global execution context.

setResetGlobals

public final void setResetGlobals(boolean reset)
When resetGlobals is true, the initializers of global variables are evaluated when (reset) is executed.
Parameters:
reset - The value of this property

getResetGlobals

public final boolean getResetGlobals()
When resetGlobals is true, the initializers of global variables are evaluated when (reset) is executed.
Returns:
The value of this property

setEvalSalience

public final void setEvalSalience(int method)
                           throws JessException
Set the salience evaluation behaviour. The behaviour can be one of INSTALL, ACTIVATE, or EVERY_TIME; the default is INSTALL. When the behaviour is INSTALL, a rule's salience is evulated once when the rule is compiled. If it is ACTIVATE, it is computed each time the rule is activated. If it is EVERY_TIME, salience evaluations are done for all rules each time the next rule on the agenda is to be chosen.
Parameters:
method - One of the acceptable values
Throws:
JessException - If something goes wrong

getEvalSalience

public final int getEvalSalience()
Fetch the salience evaluation behaviour
Returns:
The salience evaluation behaviour

addInputRouter

public void addInputRouter(java.lang.String s,
                           java.io.Reader is,
                           boolean consoleLike)
Parameters:
s -  
is -  
consoleLike -  

addOutputRouter

public void addOutputRouter(java.lang.String s,
                            java.io.Writer os)
Parameters:
s -  
os -  

removeInputRouter

public void removeInputRouter(java.lang.String s)
Parameters:
s -  

removeOutputRouter

public void removeOutputRouter(java.lang.String s)
Parameters:
s -  

getInputRouter

public java.io.Reader getInputRouter(java.lang.String s)
Parameters:
s -  
Returns:
 

getInputMode

public boolean getInputMode(java.lang.String s)
Parameters:
s -  
Returns:
 

getOutputRouter

public java.io.Writer getOutputRouter(java.lang.String s)
Parameters:
s -  
Returns:
 

setPendingFact

public void setPendingFact(Fact fact,
                           boolean assert)
Parameters:
fact -  

processPendingFacts

public void processPendingFacts()
                         throws JessException
DONT call this - it's going to be package-private soon.
Throws:
JessException -  

getFactDuplication

public boolean getFactDuplication()
Returns true if duplicate facts are allowed, false otherwise.
Returns:
Value of factDuplication.

setFactDuplication

public void setFactDuplication(boolean v)
Turn fact-duplication on or off.
Parameters:
v - Value to assign to factDuplication.

store

public Value store(java.lang.String name,
                   Value val)
Store a value in the engine under a given name for later retrieval by fetch.
Parameters:
name - A key under which to file the value
val - The value to store
Returns:
Any old value stored under this name, or null.

store

public Value store(java.lang.String name,
                   java.lang.Object val)
Store a value in the engine under a given name for later retrieval by fetch. The Object is first wrapped in a new jess.Value object.
Parameters:
name - A key under which to file the value
val - The value to store
Returns:
Any old value stored under this name, or null.

fetch

public Value fetch(java.lang.String name)
Retrieve an object previously stored with store().
Parameters:
name - The key under which to find an object
Returns:
The object, or null if not found.
See Also:
store(java.lang.String, jess.Value)

clearStorage

public void clearStorage()
Clear the storage used by store() and fetch().

getErrStream

public java.io.PrintWriter getErrStream()
Returns:
 

getOutStream

public java.io.PrintWriter getOutStream()
Returns:
 

clear

public void clear()
           throws JessException
Reinitialize engine Thanks to Karl Mueller for idea
Throws:
JessException -  

reset

public void reset()
           throws JessException
Reset the Rete engine. Remove all facts, activations, etc. Clear all non-globals from the global scope. Assert (initial-fact). Broadcasts a JessEvent of type RESET.
Throws:
JessException - If anything goes wrong.

assertString

public int assertString(java.lang.String s)
                 throws JessException
Assert a fact, as a String
Parameters:
s -  
Returns:
 
Throws:
JessException -  

assert

public int assert(Fact f)
           throws JessException
Assert a fact
Parameters:
f -  
Returns:
 
Throws:
JessException -  

retractString

public Fact retractString(java.lang.String s)
                   throws JessException
Karl Mueller NASA/GSFC Code 522.2 (Karl.R.Mueller@gsfc.nasa.gov) 27.January.1998 Retract a fact as a string
Parameters:
s -  
Throws:
JessException -  

retract

public Fact retract(Fact f)
             throws JessException
Retract a fact.
Parameters:
f - A Fact object. Doesn't need to be the actual object that appears on the fact-list; can just be a Fact that could compare equal to one.
Throws:
JessException - If anything goes wrong.

retract

public Fact retract(int id)
             throws JessException
Retract a fact by ID, used by rule RHSs.
Parameters:
id - The fact-id of a fact
Throws:
JessException - If anything goes wrong.

findFactByID

public Fact findFactByID(int id)
                  throws JessException
This 'find' is used by the retract that rules use. Consider the returned Fact to be READ-ONLY!
Parameters:
id - The fact-id
Returns:
The fact, or null if none
Throws:
JessException - If something goes wrong

ppFacts

public java.lang.String ppFacts(java.lang.String name)
Return the pretty print forms of all facts, as a big string
Parameters:
name -  
Returns:
 

ppFacts

public java.lang.String ppFacts()
                         throws JessException
Returns:
 
Throws:
JessException -  

listDeffacts

public java.util.Enumeration listDeffacts()
Return an Enumeration of all the deffacts in this engine.

listDeftemplates

public java.util.Enumeration listDeftemplates()
Return an Enumeration of all the deftemplates in this engine, both explicit and implied.

listDefrules

public java.util.Enumeration listDefrules()
Return an Enumeration of all the defrules in this engine.

listFacts

public java.util.Enumeration listFacts()
Return an Enumeration of all the facts currently on the fact-list

listActivations

public java.util.Enumeration listActivations()
Return an Enumeration of all the activiations - i.e, the agenda.

listDefglobals

public java.util.Enumeration listDefglobals()
Return an Enumeration of all the defglobals in this engine.

listFunctions

public java.util.Enumeration listFunctions()
Return an Enumeration of all the functions in this engine: built-in, user, and deffunctions.

findDefrule

public final HasLHS findDefrule(java.lang.String name)
Find a defrule object with a certain name
Parameters:
name -  
Returns:
 

findDeftemplate

public Deftemplate findDeftemplate(java.lang.String name)
Find a deftemplate object with a certain name
Parameters:
name -  
Returns:
 

addDeftemplate

public Deftemplate addDeftemplate(Deftemplate dt)
                           throws JessException
Creates a new deftemplate in this object. Ensure that every deftemplate has a unique class name; silently ignore redefinitions!
Parameters:
dt -  
Returns:
 
Throws:
JessException -  

addDeffacts

public Deffacts addDeffacts(Deffacts df)
                     throws JessException
Creates a new deffacts in this object
Parameters:
df -  
Returns:
 
Throws:
JessException -  

addDefglobal

public Defglobal addDefglobal(Defglobal dg)
                       throws JessException
Creates a new Defglobal in this object. Trick it into resetting right now, regardless of the setting of resetGlobals.
Parameters:
dg -  
Returns:
 
Throws:
JessException -  

findDefglobal

public Defglobal findDefglobal(java.lang.String name)
Parameters:
name -  
Returns:
 

addUserfunction

public Userfunction addUserfunction(Userfunction uf)
Creates a new function in this object Will happily destroy an old one.
Parameters:
uf - A new USerfunction
Returns:
The parameter, or null if call rejected by event handler

addUserpackage

public Userpackage addUserpackage(Userpackage up)
Add a Userpackage to this engine. A package generally calls addUserfunction lots of times.
Parameters:
up - The package object
Returns:
The package object, or null if call rejected by event handler

findUserfunction

public final Userfunction findUserfunction(java.lang.String name)
Find a userfunction, if there is one.
Parameters:
name - The name of the function
Returns:
The Userfunction object, if there is one.

addDefrule

public final HasLHS addDefrule(HasLHS dr)
                        throws JessException
Creates a new defrule in this object
Parameters:
dr -  
Returns:
 
Throws:
JessException -  

unDefrule

public final Value unDefrule(java.lang.String name)
                      throws JessException
Parameters:
name -  
Returns:
 
Throws:
JessException -  

setStrategy

public java.lang.String setStrategy(Strategy s)
                             throws JessException
Parameters:
s -  
Returns:
 
Throws:
JessException -  

run

public int run()
        throws JessException
Run the actual engine.
Returns:
 
Throws:
JessException -  

run

public int run(int max)
        throws JessException
Parameters:
max -  
Returns:
 
Throws:
JessException -  

executeCommand

public Value executeCommand(java.lang.String cmd)
                     throws JessException
Stuff to let Java code call functions inside of us.
Parameters:
cmd -  
Returns:
 
Throws:
JessException -  

halt

public void halt()
Jane, stop this crazy thing!

listJessListeners

public java.util.Enumeration listJessListeners()
Parameters:
jel -  

addJessListener

public void addJessListener(JessListener jel)
Parameters:
jel -  

removeJessListener

public void removeJessListener(JessListener jel)
Parameters:
jel -  

getEventMask

public int getEventMask()

setEventMask

public void setEventMask(int i)

© 1997 E.J. Friedman-Hill and Sandia Corporation