Hello,
I have some questions around events and integration Jess facts in Java-GUI
Im running Jess Version 6.0. evaluation copy
This is the simple example I like to run:
import jess.*;
import java.net.*;
public class TestMyRete
{
public static void main(String notUsed[]) throws JessException
{
Rete rete = new Rete();
ExMyReteEventHandler eh = new ExMyReteEventHandler();
rete.addJessListener(((JessListener)eh));
//rete.executeCommand("(batch c:/jess60/jess/scriptlib.clp)");
rete.executeCommand("(batch C:/Jess60/jess/examples/trockenlauf/rulesTrockenlauf.clp)");
rete.reset();
rete.run();
Fact fact = new Fact("applmat",rete);
fact.setSlotValue("mat", new Value("APRTEST", RU.STRING));
rete.assert(fact);
rete.run();
}
}
import jess.Activation;
import jess.Defrule;
import jess.Fact;
import jess.JessEvent;
import jess.JessListener;
import jess.Token;
public class ExMyReteEventHandler implements JessListener {
public void eventHappened(JessEvent je)
{
System.out.println("\n\nIn EventHandler: " + je.toString());
int defaultMask = JessEvent.DEFRULE_FIRED;
int type = je.getType();
switch (type){
case JessEvent.DEFRULE_FIRED:
Object obj = je.getObject();
System.out.println( "Obj Name : "+ obj.toString());
Activation activation = (Activation)obj;
Defrule rule = activation.getRule();
System.out.println("Rule DispalyName : "+rule.getDisplayName());
System.out.println("Rule Docstring : "+rule.getDocstring());
System.out.println("Rule Name : "+rule.getName());
System.out.println("Rule NodeIndexHash : "+rule.getNodeIndexHash());
System.out.println("Rule NPatterns : "+rule.getNPatterns());
System.out.println("Rule listNodes : "+rule.listNodes());
System.out.println("Rule toSting : "+ rule.toString());
Token token = activation.getToken();
for(int i=0; i<token.size(); i++)
{
Fact fact = token.fact(i);
System.out.println("Fact Name : "+fact.getName());
}
break;
default:
System.out.println("APR was here");
}
}
}
Without the code rete.executeCommand("(batch c:/jess60/jess/scriptlib.clp)");
This following error is given:
Jess reported an error in routine call
while executing (call (engine) findFactByID ?__fact-id)
while executing (bind ?__fact (call (engine) findFactByID ?__fact-id))
while executing deffunction fact-slot-value
while executing (fact-slot-value ?fact mat)
while executing (bind ?mat (fact-slot-value ?fact mat))
while executing defrule MAIN::APPLmat_H3-202
while executing (run)
while executing (batch C:/Jess60/jess/examples/trockenlauf/rulesTrockenlauf.clp).
Message: No overloading of method 'findFactByID' in class jess.Rete I can call with these arguments: (call (engine) findFactByID ?__fact-id).
Program text: ( batch C:/Jess60/jess/examples/trockenlauf/rulesTrockenlauf.clp ) at line 1.
at jess.w.call(Unknown Source)
at jess.ef.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.FuncallValue.resolveValue(Unknown Source)
at jess.cv.call(Unknown Source)
at jess.ef.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.FuncallValue.resolveValue(Unknown Source)
at jess.Deffunction.call(Unknown Source)
at jess.ef.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.FuncallValue.resolveValue(Unknown Source)
at jess.cv.call(Unknown Source)
at jess.ef.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.Defrule.try(Unknown Source)
at jess.Activation.if(Unknown Source)
at jess.a7.a(Unknown Source)
at jess.a7.int(Unknown Source)
at jess.Rete.run(Unknown Source)
at jess.az.call(Unknown Source)
at jess.ef.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.case(Unknown Source)
at jess.Jesp.parse(Unknown Source)
at jess.Batch.batch(Unknown Source)
at jess.Batch.call(Unknown Source)
at jess.ef.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.case(Unknown Source)
at jess.Jesp.parse(Unknown Source)
at jess.Rete.executeCommand(Unknown Source)
at TestMyRete.main(TestMyRete.java:13)
Exception in thread "main"
1. With the scriptlib the code runs. And rule fire. But no Jessevent is generated. What is wrong with code?
2. Most code examples given by ernest like facts.clp and pumps.clp code Java-GUI inside of Jess.
I prefere to code my GUI in a JAVA-IDE and only the rules and facts inside JESS.
I started and code in Java like this:
Lub = new Choice();
cLub.addItem("lub");
cLub.addItem("dry");
How can I access the items from Jess? Can I access them via Fact-ID-No. or do I have to store and fetch them?
3. And the other way around: Jess produce some facts during the run I like to show in textfields. How can I perform this. Code is appreciated.
4. As I unterstand the JessListener it observes an event like rulefired. Can I observe more specifically only facts and rules I'm interested?
Kindest Regards
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
