Dear Ernest,
I tried to build up a GUI-Interface for Jess.
I experimented a bit with the samples you gave in the online documentation.
I have some questions:
Executing this command: getRete().executeCommand(" (facts) ")
Throws an exception Nomethodnamed'hasMoreElements'found
What can be the cause for this?
I use eclipse for Java developing:
For a protoype it works well
//For the output I use something like this:
ta = new TextArea();
taw = new MyTextAreaWriter2(ta);
//For Input:
bRun = new MyButton("Run");
bRun.addActionListener(al);
//Inner class:
public class Al implements ActionListener {
public void actionPerformed (ActionEvent e) {
try{
bRun.setEnabled(false);
StringBuffer g1 = new StringBuffer();
g1.append("(deffacts inputstage (stage " );
//g1.append(" (tp " );
g1.append(tfin1.getTextExt());
//g1.append(" ) ");
//g1.append(" ( cm ");
g1.append(tfin2.getTextExt());
//g1.append(" )" );
//g1.append(" ( cyldia ");
g1.append(tfin3.getTextExt());
//g1.append(" )" );
//g1.append(" ( stageno ");
g1.append(tfin4.getTextExt());
//g1.append(" )" );
// g1.append(" ( pstat ");
g1.append(tfin5.getTextExt());
// g1.append(" )" );
// g1.append(" ( pdyn ");
g1.append(tfin6.getTextExt());
// g1.append(" )" );
if ( !(tfin5.getText().compareTo("")== 0) && !(tfin6.getText().compareTo("")== 0 )){
g1.append(" ( pges ");
double d = Double.parseDouble(tfin5.getText());
double d2 = Double.parseDouble(tfin6.getText());
d=d+d2;
g1.append(Double.toString(d)); //
g1.append(" )" );
}
//g1.append(" ( tdis ");
g1.append(tfin7.getTextExt()); //tdis
//g1.append(" )" );
g1.append(" )" ); //Ende Stage
//g1.append(" (spec (gases \"H2\" )(luboption dry)) ) " );
g1.append(" (spec (gases ");
g1.append(" \"");
g1.append(cGases.getSelectedItem());
g1.append("\" )(luboption ");
g1.append(cLub.getSelectedItem() );
g1.append(")) ) " );
// g1.append("\" )(luboption dry)) ) " );
Value v1 = getRete().executeCommand(g1.toString());
getRete().executeCommand(" (reset) ");
taw.clear();
getRete().executeCommand("(printout t \"BEGIN RULE FIRING \" crlf crlf)");
getRete().executeCommand(" (run) ");
// tried to retract facts with functions
// after that with rules, but every time I run this command
// one fact more remains
getRete().executeCommand(" (f_retract_factstages) ");
getRete().executeCommand(" (f_retract_factspecs) ");
//getRete().executeCommand(" (facts) ");
//Exception why ?
getRete().executeCommand(" (reset) ");
bRun.setEnabled(true);
getRete().executeCommand(" (printout t \"RULE FIRING FINISHED\" ) ");
//getRete().executeCommand(" (view) "); //not useful to see
}
catch (JessException ex){
bRun.setEnabled(true);
String exStr = "(printout t " +"crlf " + ex.getMessage() +" crlf " + " ) " ;
try{
getRete().executeCommand(exStr);
}
catch (JessException ex2){
}
}
}
This code generates something like this:
(deffacts all
(stage
(tp 30)
(cm 2.2)
(cyldia 130)
(stageno 2)
(pstat 30)
(pdyn 29)
(pges 59)
(tdis 100)
)
(spec (gases "H2")
(luboption dry)
)
)
After showing the values in the output
the follwing rule should retract the facts
(defrule retractstage (declare (salience -120))
?fact <- (stage ) =>(retract ?fact))
(defrule retractspec (declare (salience -120))
?fact <- (spec ) =>(retract ?fact))
Is something wrong with my code? Do you have an idea?
Do you have comments to improve it?
Thank you
Andreas Ruetzel
Software Engineer
KIT/ 1557
Sulzer Markets and Technology Ltd
CH-8401 Winterthur, Switzerland
Phone +41 (0)52 262 82 96, Fax +41 (0)52 262 03 13
E-Mail mailto:[EMAIL PROTECTED]
Internet http://www.innotec.ch
