Hi,
I am trying to create an interactive (Q & A)
application using Java and Jess. Jess determines which
question needs to be asked, stores the question. Java
code then fetches the question and shows it to user.
User's answer is read by Java code and stored again so
Jess can fetch and use it.
However I am facing a problem in that - after the
first question is stored, Jess transfers control to
Java, and it never regains it (never activates any
rules further, even if I assert some facts to trigger
the activation).
Can you help me solve this problem?
------------ Here is the JESS code : ----------------
(defrule init-rule
(initial-fact)
=>
(printout t "Writing Question" crlf)
(store Question "Is this a question?")
)
(defrule AssertAnswer
(jess state resume)
=>
(printout t "Asserting answer...." crlf)
(assert (answer is (fetch Answer)))
)
(defrule EvaluateAnswer
(answer is y|Y|Yes|yes)
=>
(printout t "You are passed, JESS" crlf)
)
---------- Here is the Java code : --------------
import jess.*;
public class JessTrial
{
public static void main(String args[])
{
try
{
Rete rete = new Rete();
rete.clear();
Context context = rete.getGlobalContext();
rete.watch(WatchConstants.FACTS);
rete.watch(WatchConstants.ACTIVATIONS);
Value v1 = rete.batch("trial.clp");
rete.reset();
System.out.println("Running...");
int v2 = rete.run();
System.out.println("run() returned ..." + v2);
String Question =
(rete.fetch("Question")).symbolValue(context);
System.out.println("Java received :: " +
Question);
String Answer = "Yes";
Value stored = rete.store("Answer", Answer);
System.out.println("Java Answered :: " +
stored);
rete.assertFact(new Fact("jess state resume",
rete)); // This should activate "AssertAnswer" rule
- but it never does
System.out.println("Done");
}
catch(Exception e) {
System.out.println("Exception " + e); }
}
}
---------- Here is the output : --------------------
E:\Aarati>java JessTrial
==> f-0 (MAIN::initial-fact)
==> Activation: MAIN::init-rule : f-0
Running...
Writing Question
run() returned ...1
Java received :: Is this a question?
Java Answered :: null
==> f-1 (MAIN::jess state resume)
Done
------------------ END ------------------------------
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------