|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--JESSCommunicator
The JESSCommunicator is a shell around the JESS engine. All JESS rules are created in this class.
This is also the class that is called from the JESS engine for the feedback of the conclusions of
the rules. These conclusion are then passed to the SituationRecognizer. The methods that are called
from the engine are setSituationState(java.lang.String, java.lang.String)
and addPerformedAction(java.lang.String)
.
Field Summary | |
protected jess.Rete |
engine_
The inference engine of Jess. |
protected SituationRecognizer |
situationRecognizer
The situation recognizer. |
protected java.util.HashMap |
variableMap
The variables with the values that have been stored in the JESS engine. |
Constructor Summary | |
JESSCommunicator(SituationRecognizer sitRec)
This constructor initiates the engine, resets the factbase and adds itself as an instance of an object to the engine, so that the engine can call the methods of this class. |
Method Summary | |
protected void |
addClassTemplate(java.lang.String className)
The method addClassTemplate adds a template of the given class to the factbase. |
protected void |
addObjectFact(java.lang.Object obj)
The method addObjectFact adds a shadow fact of the given object to the factbase. |
void |
addPerformedAction(java.lang.String situationName)
This method is called from the JESS engine when one of the action rules fire. |
void |
addSituationRules(java.util.HashMap situations)
This method is called by the situationRecognizer after the xml file has been parsed. |
void |
bindVariable(java.lang.String variableName,
java.lang.String variableValue)
This method is called from the VariableReader to add a fact to the knowledge base that states the value of one of the flight sim variables. |
protected java.lang.String |
convertValueToRule(java.lang.String variableName,
java.lang.String val,
boolean trueIfNotPresent)
This method creates a rule that checks the value of the given variable. |
protected java.lang.String |
formatRule(java.lang.String variableName,
java.lang.String condition,
boolean trueIfNotPresent)
This method returns a condition formatted like a rule in JESS. |
protected java.lang.String |
getActionName(java.lang.String situationName,
int index)
Create a unique name for the action variable. |
java.lang.Object[][] |
getFacts()
The method showFacts reads the facts from Jess and returns them. |
java.util.Vector |
getGlobals()
Returns the names of the global variables in the engine and their values. |
java.lang.Object[][] |
getRules()
The method showRules reads the rules from Jess and returns them. |
void |
reset()
The method reset resets the rulebase, but leaves the values of the global variables intact. |
void |
resetEngine()
The method resetEngine resets the rulebase including the global variables. |
void |
resetSituation(Situation situation)
This method is called when the end of a situation is detected. |
void |
runEngine()
The method runEngine evaluates the rules in the rulebase. |
void |
setSituationState(java.lang.String situationName,
java.lang.String state)
This method is called from the JESS engine when one of the start or end conditions fire. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected jess.Rete engine_
protected SituationRecognizer situationRecognizer
protected java.util.HashMap variableMap
Constructor Detail |
public JESSCommunicator(SituationRecognizer sitRec)
sitRec
- The situation recognizer.Method Detail |
public void runEngine()
public void resetEngine()
reset
.
public void reset()
public void addSituationRules(java.util.HashMap situations)
Situation
objects to JESS rules and export them to the JESS engine.
For every Situation in the given HashMap the conditions are formatted to condition rules first.
Two global variables are created for every situation that state whether or not the start or
end conditions have been satisfied. A condition rule checks the values of all the variables
of a condition and sets the global condition variable to true if all the variables have the
correct values. The conditions are only evaluated if the global variable has not already been
set. The end condition is furthermore only evaluated if the global start variable has been set
to true, because and end condition can only end if the situation has already started. Furthermore,
when one of the condition rules fires, the method setSituationState(java.lang.String, java.lang.String)
is called to notify
the JESSCommunicator that the state of the situation has changed.
A condition rule is built up in the following way:
IF the condition rule has not yet fired AND
the values of all the variables of the condition are correct THEN
call the setSituationState method of the JESSCommunicator AND
set the global condition variable
After the conditions have been converted to rules the actions belonging to the siutations are
interpreted and converted to another set of rules. For every action a rule and a global action
variable are created. The global action variable contains a string that identifies whether or
not an action has been performed yet. The action rule sets the global action variable to the
performed state if the start conditions of the situation have been satisfied, the action has
not been performed yet and the flight sim variable belonging to the action has the correct value
that was specified in the xml file. If the rule fires the global action variable is set and the
method addPerformedAction(java.lang.String)
is called to notify the JESSCommunicator that an action has
been performed. An action rule is built up in the following way:
IF the start condition rule has fired AND
the action has not been performed yet AND
the value of the variable belonging to the action is correct THEN
call the addPerformedAction method of the JESSCommunicator AND
set the global action variable>
situations
- A HashMap containing all the situations that have been parsed from the XML file.addPerformedAction(java.lang.String)
,
setSituationState(java.lang.String, java.lang.String)
public void resetSituation(Situation situation)
situation
- The situation that has ended.public void bindVariable(java.lang.String variableName, java.lang.String variableValue)
variableName
- The name of the flight sim variable.variableValue
- The value of the flight sim variable.public java.util.Vector getGlobals()
JessViewer
which can be used to take a look in the engine. This is very useful
for debugging.
public java.lang.Object[][] getFacts()
public java.lang.Object[][] getRules()
public void setSituationState(java.lang.String situationName, java.lang.String state)
situationName
- The name of the situation.state
- The new state of the situation.public void addPerformedAction(java.lang.String situationName)
situationName
- The name of the situation.protected java.lang.String getActionName(java.lang.String situationName, int index)
situationName
- The name of the situation.index
- The number of the action.
protected void addClassTemplate(java.lang.String className)
className
- The name of the class the template is based on.protected void addObjectFact(java.lang.Object obj)
obj
- The Object that has to be added to the factbase.protected java.lang.String formatRule(java.lang.String variableName, java.lang.String condition, boolean trueIfNotPresent)
condition = value (lop value)*
lop = & or |, these can not both be used in one condition!!!
value = (op)val
op = ! or < or > or <= or >=
First the kind of lop will be determined, this is either a &, a | or nothing. Then the string
will be split with the lops as separators. The parts will then be converted to a rule in the
method convertValueToRule(java.lang.String, java.lang.String, boolean)
.
variableName
- The name of the flight sim variablecondition
- The condition on the value of the variabletrueIfNotPresent
- If true then the rule must evaluate to true if no value for the variable is known, to false otherwise.convertValueToRule(java.lang.String, java.lang.String, boolean)
protected java.lang.String convertValueToRule(java.lang.String variableName, java.lang.String val, boolean trueIfNotPresent)
val = (op)value
op = ! or < or > or <= or >=
First the val will be checked to see if it starts with one of the ops. If so it is stripped from the val. What remains is the value. The value can be either a String or a Number, which will be determined by trying to convert the string representation to a double. If that conversion succeeds the numerical operators will be used in the JESS rule (=, >, < etc.), otherwise the rule will just check if the fact corresponding to the variable value is present in the fact base.
variableName
- The name of the flight sim variableval
- The condition on the value of the variabletrueIfNotPresent
- If true then the rule must evaluate to true if no value for the variable is known, to false otherwise.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |