jess
Class Rete

java.lang.Object
  extended byjess.Rete
All Implemented Interfaces:
java.util.EventListener, JessListener, java.io.Serializable

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

The central class in the Jess library. Executes the built Rete network, and coordinates many other activities. Rete is basically a facade for all the other classes in the Jess library.

The jess.Rete class is the rule engine itself. Each jess.Rete object has its own working memory, agenda, rules, etc. To embed Jess in a Java application, you'll simply need to create one or more jess.Rete objects and manipulate them appropriately.

(C) 2006 Sandia National Laboratories

See Also:
Serialized Form

Field Summary
static int ACTIVATE
          Constant passed to setEvalSalience() to indicate that dynamic salience expressions should be evaluated whenever a rule is activated.
static int EVERY_TIME
          Constant passed to setEvalSalience() to indicate that dynamic salience expressions should be evaluated before every rule is fired.
static int INSTALL
          Constant passed to setEvalSalience() to indicate that dynamic salience expressions should be evaluated only when a rule is installed (the default.)
static java.util.Map s_lineNumberTable
           
 
Constructor Summary
Rete()
          Construct a single rule engine instance.
Rete(java.applet.Applet applet)
          Construct a single rule engine instance for use in an applet.
Rete(java.lang.Object appObject)
           
 
Method Summary
protected  void aboutToFire(Activation a)
          Allows a subclass to be notified immediately before a rule fires.
 Value add(java.lang.Object o)
          Add an object to working memory using various defaults.
 void addAll(java.util.Collection c)
          Add a collection of objects to working memory.
 void addAll(java.util.Iterator it)
          Add a collection of objects to working memory.
 void addDebugListener(JessListener jel)
          Add a listener so that it will receive debug events.
 Deffacts addDeffacts(Deffacts df)
          Add a deffacts construct to this rule engine.
 Defglobal addDefglobal(Defglobal dg)
          Creates a new Defglobal in this rule engine.
 java.util.List addDefglobals(java.util.List dg)
          Adds a list of Defglobals to this object, as if by addDefglobal().
 void addDefmodule(Defmodule module)
          Define a new module, which becomes current.
 void addDefmodule(java.lang.String name)
          Deprecated. As of Jess 7, use addDefmodule(Defmodule).
 void addDefmodule(java.lang.String name, java.lang.String comment)
          Deprecated. As of Jess 7, use addDefmodule(Defmodule).
 HasLHS addDefrule(HasLHS dr)
          Add a rule or query to this engine.
 Deftemplate addDeftemplate(Deftemplate dt)
          Creates a new deftemplate in this rule engine.
 void addInputRouter(java.lang.String s, java.io.Reader is, boolean consoleLike)
          Add an "input router" to this object.
 void addJessListener(JessListener jel)
           
 void addOutputRouter(java.lang.String s, java.io.Writer os)
          Add an "output router" to this object.
 Userfunction addUserfunction(Userfunction uf)
          Creates a new function in this rule engine.
 Userpackage addUserpackage(Userpackage up)
          Add a Userpackage to this engine.
 Fact assertFact(Fact f)
          Assert a fact.
 Fact assertFact(Fact f, Context c)
          Assert a fact, using the given execution context.
 Fact assertString(java.lang.String s)
          Assert a fact, as a String, using the global execution context.
 Fact assertString(java.lang.String s, Context c)
          Assert a fact, as a String.
 Value batch(java.lang.String filename)
          Execute a file of Jess language code or JessML code.
 void bload(java.io.InputStream is)
          Read this object's state from the given stream.
 void bsave(java.io.OutputStream os)
          Save this object's state out to the given stream.
 void clear()
          Reinitializes this rule engine.
 void clearFocusStack()
          Empty the module focus stack.
 void clearStorage()
          Clear the storage used by store() and fetch().
 boolean containsObject(java.lang.Object o)
          Indicates whether a given object is being held in working memory.
 int countQueryResults(java.lang.String name, ValueVector params)
          Invoke the named query and return the count of matching results.
 int countQueryResults(java.lang.String name, ValueVector params, Context context)
          Invoke the named query and return the count of matching results.
 Deftemplate createDeftemplate(java.lang.String name)
          Find or create the deftemplate by the given name.
 Value defclass(java.lang.String jessName, java.lang.String clazz, java.lang.String parent)
          Add a defclass definition (a deftemplate) to this engine.
 Value defclass(java.lang.String jessName, java.lang.String clazz, java.lang.String parent, boolean includeMemberVariables)
          Add a defclass definition (a deftemplate) to this engine.
 void defineFeature(java.lang.String name)
          Register a named feature, as if by the "provide" function.
 Value definstance(java.lang.String jessTypename, java.lang.Object object, boolean dynamic)
          Make a shadow fact for the given object and add it to working memory.
 Value definstance(java.lang.String jessTypename, java.lang.Object object, boolean dynamic, Context context)
          Make a shadow fact for the given object and add it to working memory.
protected  int doPreAssertionProcessing(Fact f)
          This method is called as a Fact is about to be asserted.
 Value eval(java.lang.String cmd)
          Evaluate a Jess expression in this engine's global context.
 Value eval(java.lang.String cmd, Context context)
          Evaluate a Jess expression in the given execution context.
 void eventHappened(JessEvent je)
          Responds to a JessEvent by emitting "watch" messages.
 Value executeCommand(java.lang.String cmd)
          Deprecated. Use eval() instead.
 Value executeCommand(java.lang.String cmd, Context context)
          Deprecated. Use eval() instead.
 Value fetch(java.lang.String name)
          Retrieve an object previously stored with store().
 java.lang.Class findClass(java.lang.String className)
          Load a class using the active ClassLoader.
 Deffacts findDeffacts(java.lang.String name)
          Return the named deffacts object.
 Defglobal findDefglobal(java.lang.String name)
          Look up a defglobal by name.
 HasLHS findDefrule(java.lang.String name)
          Find a defrule or defquery object with a certain name.
 Deftemplate findDeftemplate(java.lang.String name)
          Find a deftemplate object with a certain name.
 Fact findFactByFact(Fact f)
          Find a Fact object in working memory, given a Fact object that is identical to it.
 Fact findFactByID(int id)
          Return a Fact object given its numeric fact-id.
 Userfunction findUserfunction(java.lang.String name)
          Find a userfunction, if there is one by the given name.
 java.lang.Object getActivationSemaphore()
          The monitor of the object returned from this method will be signalled whenever an activation appears.
 java.applet.Applet getApplet()
          If this Rete object is part of an applet, and the applet was supplied as a constructor argument, then this method will return it.
 java.lang.Class getAppObjectClass()
          Return the Class that represents the "app object" for this Rete.
 java.lang.ClassLoader getClassLoader()
          Return the ClassLoader that will be used to find classes named in Jess ocde.
 ClassResearcher getClassResearcher()
          Return the ClassResearcher this engine will use to learn about Java classes mentioned in Jess code.
 java.lang.String getCurrentModule()
          Return the name of the current module.
 java.io.PrintWriter getErrStream()
          Return the WSTDERR router, where Jess sends error messages.
 int getEvalSalience()
          Fetch the salience evaluation behaviour, which helps determine the priority of rule firing.
 int getEventMask()
          Query the current value of the event mask.
static Factory getFactory()
          Return the Factory Jess will use to create Rete Tokens.
 java.lang.String getFocus()
          Query the focus module.
 Context getGlobalContext()
          Fetch the global execution context.
 boolean getInputMode(java.lang.String s)
          Returns the consoleLike property for the named input router.
 java.io.Reader getInputRouter(java.lang.String s)
          Return the Reader registered under a given router name.
 java.util.Iterator getObjects(Filter filter)
          Return a subset of Java objects (definstances) in working memory.
 java.io.Writer getOutputRouter(java.lang.String s)
          Return the Writer registered under a given router name.
 java.io.PrintWriter getOutStream()
          Return the WSTDERR router, where Jess sends much of its standard output.
 boolean getResetGlobals()
          Return the resetGlobals property.
 java.net.URL getResource(java.lang.String name)
          Load a resource using the current ClassLoader's getResource() method.
 Fact getShadowFactForObject(java.lang.Object o)
          Returns the "shadow fact" that represents the given object in working memory.
 Strategy getStrategy()
          Retrieve the Strategy object this engine is using to order activations on the agenda.
 java.util.List getSupportedFacts(Fact supporter)
          Returns a list of Fact objects that receive logical support from the argument.
 java.util.List getSupportingTokens(Fact fact)
          Returns a list of one or more jess.Token objects that provide logical support for this fact.
 Activation getThisActivation()
          Get the activation record for the currently firing rule.
 java.lang.String getThisRuleName()
          Find out the name of the currently firing rule.
 void halt()
          Stop the engine from firing rules.
 void importClass(java.lang.String clazz)
          Make a single class name available for use in unqualified form in Jess code.
 void importPackage(java.lang.String pack)
          Make all the classes in a package available for use in unqualified form from Jess code.
 boolean isDebug()
          Return whether the engine is in debug mode.
 boolean isFeatureDefined(java.lang.String name)
          Return whether a feature name has been registered by the "provide" function.
 boolean isHalted()
          Returns true if halt has been called since the last run() call.
 java.lang.Class javaClassForDefclass(java.lang.String name)
          Return the Java Class corresponding to a given Defclass name, or null if the name was not found.
protected  void justFired(Activation a)
          Allows a subclass to be notified immediately after a rule fires.
 java.util.Iterator listActivations()
          Return an Iterator over all the activiations for the current module.
 java.util.Iterator listActivations(java.lang.String moduleName)
          Return an Iterator over all the activiations for the named module.
 java.util.Iterator listDebugListeners()
          Return an iterator over all listeners that will receive debug events.
 java.util.Iterator listDefclasses()
          Return an Iterator over all the names of all defclasses.
 java.util.Iterator listDeffacts()
          Return an Iterator over all the deffacts in this engine.
 java.util.Iterator listDefglobals()
          Return an Iterator over all the defglobals in this engine.
 java.util.Iterator listDefinstances()
          Return an Iterator over all the Java objects currently represented by shadow facts in working memory.
 java.util.Iterator listDefrules()
          Return an Iterator over all the defrules in this engine.
 java.util.Iterator listDeftemplates()
          Return an Iterator over all the deftemplates in this engine, both explicit and implied.
 java.util.Iterator listFacts()
          Return an Iterator over all the facts currently in working memory.
 java.util.Iterator listFocusStack()
          Iterate over the module focus stack, from bottom to top.
 java.util.Iterator listFunctions()
          Return an Iterator over all user-defined functions and deffunctions in this engine.
 java.util.Iterator listJessListeners()
           
 java.util.Iterator listModules()
          List all modules.
static LineNumberRecord lookupFunction(Funcall fc)
          Return information about the source location of a given function call, if known.
 WorkingMemoryMarker mark()
          Return a marker for the current state of working memory.
 Fact modify(Fact fact, java.lang.String[] slotNames, Value[] slotValues)
          Modify any number of slots in a fact.
 Fact modify(Fact fact, java.lang.String[] slotNames, Value[] slotValues, Context context)
          Modify any number of slots in a fact.
 Fact modify(Fact fact, java.lang.String slotName, Value slotValue)
          Modify one slot in a fact.
 Fact modify(Fact fact, java.lang.String slotName, Value slotValue, Context context)
          Modify one slot in a fact.
 Activation peekNextActivation()
          Return the next activation record from the agenda.
 java.lang.String popFocus(java.lang.String expected)
          Remove the top module from the focus stack, and return it.
 void ppFacts(java.lang.String head, java.io.Writer output)
          Pretty-print all the facts with the given head to the Writer.
 void ppFacts(java.lang.String head, java.io.Writer output, boolean inXML)
          Pretty-print all the facts with the given head to the Writer.
 void ppFacts(java.io.Writer output)
          Pretty-print all the facts in working memory to the Writer.
 void ppFacts(java.io.Writer output, boolean inXML)
          Pretty-print all the facts in working memory to the Writer.
static void recordFunction(Funcall fc, LineNumberRecord lnr)
          Store a debug symbol for a function call.
static void recordFunction(Funcall fc, java.lang.String fileName, int lineno)
          Store a debug symbol for a function call.
 Fact remove(java.lang.Object object)
          Remove the given object from working memory.
 void removeAll(java.util.Collection c)
          Remove a collection of objects from working memory.
 void removeDebugListener(JessListener jel)
          Remove a listener so that it will no longer receive debug events.
 void removeFacts(java.lang.String name)
          Retract all the facts using a given template that are currently in working memory.
 void removeInputRouter(java.lang.String s)
          Remove the named router from the engine.
 void removeJessListener(JessListener jel)
           
 void removeOutputRouter(java.lang.String s)
          Remove the named router from the engine.
 void removeUserDefinedFunctions()
          Removes all user-defined functions from this engine.
 void removeUserfunction(java.lang.String name)
          Remove any currently defined function by the given name.
 void reset()
          Reset the rule engine.
 void resetToMark(WorkingMemoryMarker marker)
          Restore working memory by retracting all facts asserted after the given marker was placed.
 java.lang.String resolveName(java.lang.String name)
          Decorate the name with the current module name, if it doesn't already contain a module name.
 Fact retract(Fact f)
          Retract a fact.
 Fact retractString(java.lang.String s)
          Retract a fact represented as a string.
 int run()
          Run the rule engine.
 int run(int max)
          Run the rule engine.
 java.util.Iterator runQuery(java.lang.String name, ValueVector params)
          Deprecated. Since Jess 7.0, superceded by runQueryStar()
 java.util.Iterator runQuery(java.lang.String name, ValueVector params, Context context)
          Deprecated. Since Jess 7.0, superceded by runQueryStar()
 QueryResult runQueryStar(java.lang.String name, ValueVector params)
          Invoke the named query and return the results.
 QueryResult runQueryStar(java.lang.String name, ValueVector params, Context context)
          Invoke the named query and return the results.
 int runUntilHalt()
          Run the rule engine until halt() is called.
 void setApplet(java.applet.Applet applet)
          Notify this Rete object that it is part of an Applet.
 void setAppObject(java.lang.Object appObject)
          Specify the "app object" for this Rete.
 void setClassLoader(java.lang.ClassLoader loader)
          Specify the ClassLoader that will be used to load classes named in Jess code.
 void setClassResearcher(ClassResearcher researcher)
          Set the ClassResearcher this engine will use to learn about Java classes mentioned in Jess code.
 java.lang.String setCurrentModule(java.lang.String name)
          Change the current module.
 void setDebug(boolean debug)
          Specify whether the engine should be in debug mode.
 void setEvalSalience(int method)
          Set the salience evaluation behaviour.
 void setEventMask(int mask)
          You can control which events this object will fire using this method.
static void setFactory(Factory f)
          Set the Factory Jess will use to create Rete Tokens.
 void setFocus(java.lang.String name)
          Change the focus module.
 void setPassiveMode(boolean passiveMode)
          Return whether the engine is in passive mode.
 void setResetGlobals(boolean reset)
          Set the resetGlobals property.
 java.lang.String setStrategy(Strategy s)
          Tell this engine to use the given Strategy object to order the rules on the agenda.
 java.lang.String setWatchRouter(java.lang.String s)
          Sets the router the "watch" facility will use for output.
 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.
 java.lang.String toString()
          Returns "[Rete]".
 Value unDeffacts(java.lang.String name)
          Remove a deffacts from the engine.
 Fact undefinstance(java.lang.Object object)
          Remove the given object from working memory.
 Value unDefrule(java.lang.String name)
          Remove a rule or query from this Rete object.
 void unwatch(int which)
          Cancel some debugging information.
 void unwatchAll()
          Cancel all debugging info.
 Value updateObject(java.lang.Object object)
          Bring a shadow fact up to date.
 Value updateObject(java.lang.Object object, java.lang.String slotName)
          Bring one slot of a shadow fact up to date.
 void verifyModule(java.lang.String moduleName)
          Throw an exception if the argument isn't the name of a module.
 void waitForActivations()
          Waits on the activation lock as long as the agenda is empty.
 void watch(int which)
          Produce some debugging information.
 void watchAll()
          Produce all possible debugging info.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

s_lineNumberTable

public static java.util.Map s_lineNumberTable

INSTALL

public static final int INSTALL
Constant passed to setEvalSalience() to indicate that dynamic salience expressions should be evaluated only when a rule is installed (the default.)

See Also:
Constant Field Values

ACTIVATE

public static final int ACTIVATE
Constant passed to setEvalSalience() to indicate that dynamic salience expressions should be evaluated whenever a rule is activated.

See Also:
Constant Field Values

EVERY_TIME

public static final int EVERY_TIME
Constant passed to setEvalSalience() to indicate that dynamic salience expressions should be evaluated before every rule is fired. This has a large impact on performance.

See Also:
Constant Field Values
Constructor Detail

Rete

public Rete()
Construct a single rule engine instance. It will use the context ClassLoader to load classes named in Jess code.


Rete

public Rete(java.applet.Applet applet)
Construct a single rule engine instance for use in an applet. It will use the applet's ClassLoader to load classes named in Jess code.

Parameters:
applet - If this Rete object is being created inside an applet, pass it as an argument.

Rete

public Rete(java.lang.Object appObject)
Method Detail

addInputRouter

public void addInputRouter(java.lang.String s,
                           java.io.Reader is,
                           boolean consoleLike)
Add an "input router" to this object. An input router is basically just a Reader that Jess can read from. It's stored in a map and looked up by name. The router "t" corresponds to standard input, but you can define your own routers, or reassign existing ones, using this method.

Parameters:
s - the router name
is - a Reader where the router's data comes from
consoleLike - see the Jess manual

removeInputRouter

public void removeInputRouter(java.lang.String s)
Remove the named router from the engine. The Reader is not closed -- if it needs to be closed, you must do that yourself.

Parameters:
s - the name of the router to remove

getInputRouter

public java.io.Reader getInputRouter(java.lang.String s)
Return the Reader registered under a given router name.

Parameters:
s - the router name
Returns:
the router, or null if none

addOutputRouter

public void addOutputRouter(java.lang.String s,
                            java.io.Writer os)
Add an "output router" to this object. An input router is basically just a Writer that Jess can send data to. It's stored in a map and looked up by name. The router "t" corresponds to standard output, but you can define your own routers, or reassign existing ones, using this method.

Parameters:
s - the router name
os - where the data should go

removeOutputRouter

public void removeOutputRouter(java.lang.String s)
Remove the named router from the engine. The Writer is not closed -- if it needs to be closed, you must do that yourself.

Parameters:
s - the name of the router

getInputMode

public boolean getInputMode(java.lang.String s)
Returns the consoleLike property for the named input router. The boolean argument consoleLike to the addInputRouter method specifies whether the stream should be treated like the standard input or like a file. The difference is that on console-like streams, a read call consumes an entire line of input, but only the first token is returned; while on file-like streams, only the characters that make up each token are consumed on any one call. That means, for instance, that a read followed by a readline will consume two lines of text from a console-like stream, but only one from a file-like stream, given that the first line is of non-zero length.

Parameters:
s - the router name
Returns:
the console-like property for that router, or null if the router doesn't exist.

getOutputRouter

public java.io.Writer getOutputRouter(java.lang.String s)
Return the Writer registered under a given router name.

Parameters:
s - The router name
Returns:
The router, or null if none

getErrStream

public java.io.PrintWriter getErrStream()
Return the WSTDERR router, where Jess sends error messages.

Returns:
The WSTDERR router

getOutStream

public java.io.PrintWriter getOutStream()
Return the WSTDERR router, where Jess sends much of its standard output. The "t" router is distinct from WSTDOUT, but they initially both go to System.out.

Returns:
The WSTDOUT router

doPreAssertionProcessing

protected int doPreAssertionProcessing(Fact f)
                                throws JessException
This method is called as a Fact is about to be asserted. It is meant to be overridden by extensions that need to do additional processig when facts are added to working memory.

Parameters:
f - a Fact about to be asserted
Returns:
non-zero if the assertion should not proceed
Throws:
JessException

clear

public void clear()
           throws JessException
Reinitializes this rule engine. Working memory is cleared, all rules are deleted, deffunctions are removed, all templates are forgotten, the watch state is reset, and a JessEvent of type JessEvent.CLEAR is sent, and then the event mask is set to 0.

Throws:
JessException - if anything goes wrong

reset

public void reset()
           throws JessException
Reset the rule engine. Clears working memory and the agenda, but rules remain defined. Clears all non-globals from the global scope. Asserts (initial-fact), reasserts all deffacts and definstances, then broadcasts a JessEvent of type JessEvent.RESET.

Throws:
JessException - if anything goes wrong

assertString

public Fact assertString(java.lang.String s,
                         Context c)
                  throws JessException
Assert a fact, as a String. For example, you can say

Rete engine = ...
Context context = ...
engine.assertString("(person (name Fred))", context);

Parameters:
s - a String representing a fact
c - an execution context for resolving variables
Returns:
the fact that was asserted
Throws:
JessException - if something goes wrong

assertString

public Fact assertString(java.lang.String s)
                  throws JessException
Assert a fact, as a String, using the global execution context. For example, you can say

Rete engine = ...
engine.assertString("(person (name Fred))");

Parameters:
s - a String representing a fact
Returns:
the fact that was asserted
Throws:
JessException - if something goes wrong

assertFact

public Fact assertFact(Fact f)
                throws JessException
Assert a fact. Adds the given Fact to working memory. This fact becomes the property of Jess after calling assertFact() -- don't change any of its fields until the fact is retracted!

Parameters:
f - a Fact object.
Returns:
the fact
Throws:
JessException - if anything goes wrong

assertFact

public Fact assertFact(Fact f,
                       Context c)
                throws JessException
Assert a fact, using the given execution context. Adds the given Fact to working memory. This fact becomes the property of Jess after calling assertFact() -- don't change any of its fields until the fact is retracted!

Parameters:
f - a Fact object.
c - an execution context
Returns:
the fact
Throws:
JessException - if anything goes wrong

retractString

public Fact retractString(java.lang.String s)
                   throws JessException
Retract a fact represented as a string. Parses the String to create a Fact object, then tries to remove that fact from working memory.

Parameters:
s - a String form of a Fact
Throws:
JessException

retract

public Fact retract(Fact f)
             throws JessException
Retract a fact. Removes the Fact from working memory. 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.

Parameters:
f - a Fact object
Throws:
JessException - if anything goes wrong

removeFacts

public void removeFacts(java.lang.String name)
                 throws JessException
Retract all the facts using a given template that are currently in working memory. If the name is a defclass name, the Java objects will be removed from working memory as well.

Parameters:
name - the name of a template
Throws:
JessException - if anything goes wrong

modify

public Fact modify(Fact fact,
                   java.lang.String slotName,
                   Value slotValue)
            throws JessException
Modify one slot in a fact. This function works for both plain and shadow facts. For shadow facts, the corresponding Java object is also modified. Uses the global context to resolve the value.

Parameters:
fact - a fact that's currently in working memory
slotName - the name of a slot in the fact
slotValue - a new value for the named slot
Returns:
the fact argument
Throws:
JessException - if the slot name is bad or any other error occurs

modify

public Fact modify(Fact fact,
                   java.lang.String slotName,
                   Value slotValue,
                   Context context)
            throws JessException
Modify one slot in a fact. This function works for both plain and shadow facts. For shadow facts, the corresponding Java object is also modified. Uses the supplied context to resolve the value.

Parameters:
fact - a fact that's currently in working memory
slotName - the name of a slot in the fact
slotValue - a new value for the named slot
context - an execution context
Returns:
the fact argument
Throws:
JessException - if the slot name is bad or any other error occurs

modify

public Fact modify(Fact fact,
                   java.lang.String[] slotNames,
                   Value[] slotValues)
            throws JessException
Modify any number of slots in a fact. This function works for both plain and shadow facts. For shadow facts, the corresponding Java object is also modified. Uses the global context to resolve the values.

Parameters:
fact - a fact that's currently in working memory
slotNames - the names of some slots in the fact
slotValues - new values for the named slots
Returns:
the fact argument
Throws:
JessException - if any slot name is bad or any other error occurs

modify

public Fact modify(Fact fact,
                   java.lang.String[] slotNames,
                   Value[] slotValues,
                   Context context)
            throws JessException
Modify any number of slots in a fact. This function works for both plain and shadow facts. For shadow facts, the corresponding Java object is also modified. Uses the given context to resolve the values.

Parameters:
fact - a fact that's currently in working memory.
slotNames - the names of some slots in the fact
slotValues - new values for the named slots.
context - the execution context
Returns:
the fact argument
Throws:
JessException - if any slot name is bad or any other error occursy

findFactByID

public Fact findFactByID(int id)
                  throws JessException
Return a Fact object given its numeric fact-id. This method is very slow; don't use it unless you have to. 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

findFactByFact

public Fact findFactByFact(Fact f)
                    throws JessException
Find a Fact object in working memory, given a Fact object that is identical to it. This find is fast, and can be used to find out quickly if a given fact is on the fact-list and if so, obtain a reference to it. The argument doesn't have to be a fact in working memory -- only a Fact object identical to one that is.

Parameters:
f - a fact
Returns:
a fact from working memory, or null if none
Throws:
JessException - if something goes wrong

mark

public WorkingMemoryMarker mark()
Return a marker for the current state of working memory. The marker can later be used to retract all facts asserted since the marker was placed using resetToMark().

Returns:
a marker
See Also:
resetToMark(WorkingMemoryMarker)

resetToMark

public void resetToMark(WorkingMemoryMarker marker)
                 throws JessException
Restore working memory by retracting all facts asserted after the given marker was placed.

Parameters:
marker - the marker
Throws:
JessException - if anything goes wrong
See Also:
mark()

getObjects

public java.util.Iterator getObjects(Filter filter)
Return a subset of Java objects (definstances) in working memory. The Iterator will include only those objects for which the Filter.accept(java.lang.Object) method returns true.

Parameters:
filter - a filter to apply to working memory
Returns:
an Iterator over the selected objects

ppFacts

public void ppFacts(java.lang.String head,
                    java.io.Writer output)
             throws java.io.IOException
Pretty-print all the facts with the given head to the Writer. Output is in Jess rule language format.

Parameters:
head - the name or "head" of the facts of interest
output - the Writer to send the data to
Throws:
java.io.IOException - if anything goes wrong

ppFacts

public void ppFacts(java.lang.String head,
                    java.io.Writer output,
                    boolean inXML)
             throws java.io.IOException
Pretty-print all the facts with the given head to the Writer. Output is either in Jess rule language format or in XML, depending on the value of the inXML parameter. XML files will be a complete well-formed document with a "fact-list" root element.

Parameters:
head - the name or "head" of the facts of interest
output - the Writer to send the data to
inXML - true for XML output, false for Jess language output
Throws:
java.io.IOException - if anything goes wrong

ppFacts

public void ppFacts(java.io.Writer output)
             throws java.io.IOException
Pretty-print all the facts in working memory to the Writer. Output is in the Jess rule language format.

Parameters:
output - the Writer to send the data to
Throws:
java.io.IOException - if anything goes wrong

ppFacts

public void ppFacts(java.io.Writer output,
                    boolean inXML)
             throws java.io.IOException
Pretty-print all the facts in working memory to the Writer. Output is either in Jess rule language format or in XML, depending on the value of the inXML parameter. XML files will be a complete well-formed document with a "fact-list" root element.

Parameters:
output - the Writer to send the data to
inXML - true for XML output, false for Jess language output
Throws:
java.io.IOException - if anything goes wrong

listDeffacts

public java.util.Iterator listDeffacts()
Return an Iterator over all the deffacts in this engine.

Returns:
the iterator

findDeffacts

public Deffacts findDeffacts(java.lang.String name)
Return the named deffacts object.

Parameters:
name - the name of a deffacts construct
Returns:
a Deffacts, or null if none

listDeftemplates

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

Returns:
the iterator

listDefrules

public java.util.Iterator listDefrules()
Return an Iterator over all the defrules in this engine.

Returns:
the iterator

listFacts

public java.util.Iterator listFacts()
Return an Iterator over all the facts currently in working memory. The facts are returned in fact-id order.

Returns:
the iterator

listDefinstances

public java.util.Iterator listDefinstances()
Return an Iterator over all the Java objects currently represented by shadow facts in working memory.

Returns:
the iterator

containsObject

public boolean containsObject(java.lang.Object o)
Indicates whether a given object is being held in working memory. Will return true only for the same physical object, and not for distinct but equal() objects.

Parameters:
o - the object
Returns:
true if the object is in working memory

listDefclasses

public java.util.Iterator listDefclasses()
Return an Iterator over all the names of all defclasses. You can use each name to look up the corresponding template using findDeftemplate, or the corresponding Java class using javaClassForDefclass.

Returns:
the iterator
See Also:
findDeftemplate(java.lang.String), javaClassForDefclass(java.lang.String)

listDefglobals

public java.util.Iterator listDefglobals()
Return an Iterator over all the defglobals in this engine.

Returns:
the iterator

listFunctions

public java.util.Iterator listFunctions()
Return an Iterator over all user-defined functions and deffunctions in this engine.

Returns:
the iterator

findDefrule

public final HasLHS findDefrule(java.lang.String name)
Find a defrule or defquery object with a certain name.

Parameters:
name - the name
Returns:
the found rule or query, or null.

javaClassForDefclass

public java.lang.Class javaClassForDefclass(java.lang.String name)
Return the Java Class corresponding to a given Defclass name, or null if the name was not found.

Parameters:
name - the name of a defclass
Returns:
the Class object used to define that defclass

findDeftemplate

public Deftemplate findDeftemplate(java.lang.String name)
                            throws JessException
Find a deftemplate object with a certain name.

Parameters:
name - the name
Returns:
the deftemplate, or null
Throws:
JessException

createDeftemplate

public Deftemplate createDeftemplate(java.lang.String name)
                              throws JessException
Find or create the deftemplate by the given name. If there is no such deftemplate, an ordered template is created.

Parameters:
name - the "head" of the template
Returns:
a Deftemplate object
Throws:
JessException - if the template name is invalid

addDeftemplate

public Deftemplate addDeftemplate(Deftemplate dt)
                           throws JessException
Creates a new deftemplate in this rule engine. Ensures that every deftemplate has a unique name by rejecting duplicates.

Parameters:
dt - a new Deftemplate
Returns:
the argument
Throws:
JessException - if the deftemplate is already defined

addDeffacts

public Deffacts addDeffacts(Deffacts df)
                     throws JessException
Add a deffacts construct to this rule engine.

Parameters:
df - a new Deffacts object
Returns:
the argument
Throws:
JessException - If an error occurs during event broadcasting

addDefglobal

public Defglobal addDefglobal(Defglobal dg)
                       throws JessException
Creates a new Defglobal in this rule engine. This defglobal will be reset immediately, regardless of the setting of resetGlobals.

Parameters:
dg - a new Defglobal object
Returns:
the argument
Throws:
JessException - if an error occurs

addDefglobals

public java.util.List addDefglobals(java.util.List dg)
                             throws JessException
Adds a list of Defglobals to this object, as if by addDefglobal().

Parameters:
dg - a List of Defglobals
Returns:
the argument
Throws:
JessException - if an error occurs

findDefglobal

public Defglobal findDefglobal(java.lang.String name)
Look up a defglobal by name. The name should include the leading and trailing asterisk required for defglobals.

Parameters:
name - the name of the defglobal
Returns:
the Defglobal, if found, or null

removeUserDefinedFunctions

public void removeUserDefinedFunctions()
Removes all user-defined functions from this engine. Only the built-in functions and static methods from java.lang will remain.


addUserfunction

public Userfunction addUserfunction(Userfunction uf)
Creates a new function in this rule engine. Any existing function by the same name will be replaced. Built-in functions can be redefined this way.

Parameters:
uf - a new Userfunction
Returns:
the parameter, or null if call rejected by event handler

removeUserfunction

public void removeUserfunction(java.lang.String name)
Remove any currently defined function by the given name. Built-in functions can be removed this way.

Parameters:
name - the name of the function to remove

addUserpackage

public Userpackage addUserpackage(Userpackage up)
Add a Userpackage to this engine. A Userpackage is a collection of Userfunctions. 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 by the given name.

Parameters:
name - the name of the function
Returns:
the Userfunction object, if there is one, or null.

addDefrule

public final HasLHS addDefrule(HasLHS dr)
                        throws JessException
Add a rule or query to this engine. The rule is compiled and added to the Rete network. Any existing rule or query by the same name is removed first.

Parameters:
dr - a Defrule or Defquery
Returns:
the added object
Throws:
JessException - if anything goes wrong

unDeffacts

public final Value unDeffacts(java.lang.String name)
Remove a deffacts from the engine. If the given name is "*", remove all deffacts.

Parameters:
name - the name of an existing deffacts construct, or "*"
Returns:
the symbol TRUE

unDefrule

public final Value unDefrule(java.lang.String name)
                      throws JessException
Remove a rule or query from this Rete object. Removes all subrules of the named rule as well.

Parameters:
name - the name of the rule or query
Returns:
the symbol TRUE
Throws:
JessException - if anything goes wrong

addDefmodule

public void addDefmodule(Defmodule module)
                  throws JessException
Define a new module, which becomes current. The current module is the one to which new constructs will be added.

Parameters:
module - a new Defmodule object
Throws:
JessException

addDefmodule

public void addDefmodule(java.lang.String name)
                  throws JessException
Deprecated. As of Jess 7, use addDefmodule(Defmodule).

Define a new module, which becomes current. The current module is the one to which new constructs will be added.

Throws:
JessException

addDefmodule

public void addDefmodule(java.lang.String name,
                         java.lang.String comment)
                  throws JessException
Deprecated. As of Jess 7, use addDefmodule(Defmodule).

Define a new module, which becomes current. The current module is the one to which new constructs will be added.

Throws:
JessException

getCurrentModule

public java.lang.String getCurrentModule()
Return the name of the current module. The current module is the one to which new constructs will be added.


setCurrentModule

public java.lang.String setCurrentModule(java.lang.String name)
                                  throws JessException
Change the current module. The current module is the one to which new constructs will be added.

Parameters:
name - the name of the new current module
Returns:
the old current module
Throws:
JessException - if the name is not a module

listModules

public java.util.Iterator listModules()
                               throws JessException
List all modules.

Returns:
an iterator over the names of all modules
Throws:
JessException

getFocus

public java.lang.String getFocus()
Query the focus module. The focus module is the one from which rules are being fired.

Returns:
the name of the current focus module

setFocus

public void setFocus(java.lang.String name)
              throws JessException
Change the focus module. The focus module is the one from which rules are being fired.

Parameters:
name - the module that should get focus
Throws:
JessException

listFocusStack

public java.util.Iterator listFocusStack()
                                  throws JessException
Iterate over the module focus stack, from bottom to top. The current focus module is returned last. The focus module is the one from which rules are being fired.

Returns:
the iterator
Throws:
JessException

clearFocusStack

public void clearFocusStack()
Empty the module focus stack. The focus module is the one from which rules are being fired.


popFocus

public java.lang.String popFocus(java.lang.String expected)
                          throws JessException
Remove the top module from the focus stack, and return it. If expected in non-null, then this is a no-op unless expected names the top module on the stack. The focus module is the one from which rules are being fired.

Parameters:
expected - the expected module, or null
Returns:
the name of the module on top the focus stack
Throws:
JessException

verifyModule

public void verifyModule(java.lang.String moduleName)
                  throws JessException
Throw an exception if the argument isn't the name of a module.

Parameters:
moduleName - a proposed module name
Throws:
JessException

resolveName

public java.lang.String resolveName(java.lang.String name)
Decorate the name with the current module name, if it doesn't already contain a module name.

Parameters:
name - a module name

listActivations

public java.util.Iterator listActivations()
Return an Iterator over all the activiations for the current module. Note that some of the activations may be cancelled or already fired; check the return value of "isInactive()"for each one to be sure. This is an expensive operation.

Returns:
an iterator over the agenda for the current module

listActivations

public java.util.Iterator listActivations(java.lang.String moduleName)
                                   throws JessException
Return an Iterator over all the activiations for the named module. Asterisk ("*") is not accepted. Note that some of the activations may be cancelled or already fired; check the return value of "isInactive()" for each one to be sure. This is an expensive operation.

Parameters:
moduleName - the name of a module
Returns:
an iterator over the agenda for the named module
Throws:
JessException - if the module name is invalid
See Also:
Activation.isInactive()

peekNextActivation

public Activation peekNextActivation()
                              throws JessException
Return the next activation record from the agenda. It's possible that this rule will be wrong if something happens to change the agenda before this rule fires.

Returns:
the next activation that will fire
Throws:
JessException - if anything goes wrong

</