jess
Class Defrule

java.lang.Object
  extended by jess.Node
      extended by jess.HasLHS
          extended by jess.Defrule
All Implemented Interfaces:
java.io.Serializable, Modular, Named, Visitable

public class Defrule
extends HasLHS
implements java.io.Serializable

A Defrule is a specific action meant to be taken when certain conditions are met in working memory. Although you can construct Defrules from the Java API, they are almost always parsed from "defrule" constructs in the Jess language. Building a Defrule from Java is very complicated.

(C) 2013 Sandia Corporation

See Also:
Serialized Form

Field Summary
 
Fields inherited from class jess.Node
TYPE_ADAPTER, TYPE_NODE1, TYPE_NODE2, TYPE_NODENOT2, TYPE_NONE, TYPE_TERMINAL, TYPE_TEST
 
Constructor Summary
Defrule(java.lang.String name, java.lang.String docstring, Rete engine)
           
 
Method Summary
 java.lang.Object accept(Visitor jv)
          Defrule participates in the Visitor pattern.
 void addAction(Funcall fc)
          Add an action to this defrule
 void addCE(jess.ConditionalElementX ce, Rete engine)
          Add a conditional element (a pattern or group of patterns) to this rule.
 void callNodeLeft(int tag, Token token, Context context)
          An implementation detail, public only because Java requires methods that implement an interface to be public.
 int evalSalience(Rete engine)
          Evaluate the salience of this rule.
 Funcall getAction(int idx)
          Fetch the idx-th RHS action of this rule.
 boolean getAutoFocus()
          Indicate whether this rule will automatically focus its module when it is activated.
 java.lang.String getConstructType()
          Return the type of this construct
 int getNActions()
          Fetch the number of actions on this rule's RHS
 int getSalience(Rete engine)
          Fetch the current salience value for this rule.
 Value getSalienceValue()
          Fetch the raw salience for this rule as a jess.Value.
 java.util.Set getTestedSlotInfo()
          Test probe only, do not use
 boolean hasNonDefaultSalience()
          Indicate whether this rule's salience is different from the default value.
 boolean isNoLoop()
          Indicate whether this rule can activate itself through actions it takes on its RHS.
 boolean isRelevantChange(int factIndex, Token token, Context context)
          Implementation detail.
 void setAutoFocus(boolean autoFocus)
          Tell this rule whether to automatically focus the module it appears in when the rule is activated.
 void setNoLoop(boolean b)
          Specify whether this rule can activate itself through actions it takes on its RHS.
 void setSalience(Value v, Rete engine)
          Set the salience of this rule.
 java.lang.String toString()
          Returns a brief description of this rule
 
Methods inherited from class jess.HasLHS
addNode, getBindingNames, getConditionalElements, getDisplayName, getDocstring, getGroupSize, getModule, getName, getNext, getNodeCount, getNodeIndexHash, getNodes, getNodeType, getPatternCount, listNodes, setLHS, setNodeIndexHash
 
Methods inherited from class jess.Node
addJessListener, decrementUseCount, getSuccessors, getUseCount, incrementUseCount, removeJessListener, successors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Defrule

public Defrule(java.lang.String name,
               java.lang.String docstring,
               Rete engine)
        throws JessException
Throws:
JessException
Method Detail

getSalience

public final int getSalience(Rete engine)
                      throws JessException
Fetch the current salience value for this rule. This method won't re-evaluate the salience unless it's never been evaluated before; the last value previously computed will be returned.

Returns:
the salience of this defrule
Throws:
JessException

getSalienceValue

public Value getSalienceValue()
Fetch the raw salience for this rule as a jess.Value. For rules with dynamic salience, the Value returned will be a jess.FuncallValue.

Returns:
the salience of this defrule

setSalience

public void setSalience(Value v,
                        Rete engine)
                 throws JessException
Set the salience of this rule. The value van be a fixed integer, or it can be a function call. The default salience is 0.

Parameters:
v - the salience expression
engine - a Rete object to provide an execution context
Throws:
JessException - if anything goes wrong

evalSalience

public int evalSalience(Rete engine)
                 throws JessException
Evaluate the salience of this rule. If the salience was set to a Funcall value during parsing, then this function may return different values over time. If the salience is constant, this is equivalent to getSalience. The computed value will be the next value returned by getSalience().

Parameters:
engine - The Rete engine the rule belongs to
Returns:
The evaluated salience
Throws:
JessException - If something goes wrong

hasNonDefaultSalience

public boolean hasNonDefaultSalience()
Indicate whether this rule's salience is different from the default value.

Returns:
true if this rule's salience is not the default.

getAutoFocus

public boolean getAutoFocus()
Indicate whether this rule will automatically focus its module when it is activated.

Returns:
the value of this property

setAutoFocus

public void setAutoFocus(boolean autoFocus)
Tell this rule whether to automatically focus the module it appears in when the rule is activated. The default value is false.

Parameters:
autoFocus - the desired value of this property.

addCE

public void addCE(jess.ConditionalElementX ce,
                  Rete engine)
           throws JessException
Add a conditional element (a pattern or group of patterns) to this rule. Normally this will only be called by the Jess parser or the XML parser, but it is theoretically possible for users to build their own rules this way.

Overrides:
addCE in class HasLHS
Parameters:
ce - the conditional element to add
engine - the rule engine that provides the execution context
Throws:
JessException - if anything goes wrong

callNodeLeft

public void callNodeLeft(int tag,
                         Token token,
                         Context context)
                  throws JessException
An implementation detail, public only because Java requires methods that implement an interface to be public.

Throws:
JessException

getNActions

public int getNActions()
Fetch the number of actions on this rule's RHS

Returns:
The number of actions

getAction

public Funcall getAction(int idx)
Fetch the idx-th RHS action of this rule.

Parameters:
idx - The zero-based index of the action to fetch
Returns:
the action as a function call

addAction

public void addAction(Funcall fc)
Add an action to this defrule

Parameters:
fc - the action as a function call

accept

public java.lang.Object accept(Visitor jv)
Defrule participates in the Visitor pattern. Will call accept(this) on the Visitor.

Specified by:
accept in interface Visitable
Specified by:
accept in class HasLHS
Parameters:
jv - a Visitor
Returns:
whatever jv.accept(this) returns

toString

public java.lang.String toString()
Returns a brief description of this rule

Overrides:
toString in class java.lang.Object
Returns:
the String "Defrule rule-name"

setNoLoop

public void setNoLoop(boolean b)
Specify whether this rule can activate itself through actions it takes on its RHS. If this property is set to true, then modifying a fact on the RHS of this rule can't reactivate the same rule, even if that fact is matched by this rule. The default value is false.

Parameters:
b - the desired value of the property.

isNoLoop

public boolean isNoLoop()
Indicate whether this rule can activate itself through actions it takes on its RHS. If this property is true, then modifying a fact on the RHS of this rule can't reactivate the same rule, even if that fact is matched by this rule.

Returns:
the current value of the property.

getConstructType

public final java.lang.String getConstructType()
Return the type of this construct

Specified by:
getConstructType in interface Named
Returns:
the String "defrule"

isRelevantChange

public boolean isRelevantChange(int factIndex,
                                Token token,
                                Context context)
Implementation detail. Public only because Java requires methods that implement an interface to be public.


getTestedSlotInfo

public java.util.Set getTestedSlotInfo()
Test probe only, do not use


© 2013 Sandia Corporation