I have the following jess code (based on code in JESS in Action):
defglobal ?*a* = (new java.util.ArrayList))
;;(defglobal ?*b* = (new java.util.ArrayList))
(store quest ?*a*)
(deftemplate question (slot ident)(slot text)(slot type))
(deftemplate answer (slot ident) (slot ans))
(deffacts question-data
(question
(ident name)
(text "What is your name?")
(type 1))
(question
(ident age)
(text "What is your age?")
(type 2))
(question
(ident occupation)
(text "What is your occupation?")
(type 1)))
(defmodule ask)
(defrule ask-question
(declare (auto-focus TRUE))
(MAIN::question (ident ?id)(text ?t)(type ?type))
;;(not (answer (ident ?id)))
?ask <- (MAIN::ask ?id)
=>
;;(printout t ?t crlf)
(bind ?b (new java.util.ArrayList))
(?*a* add ?b)
(?b add ?id)
(?b add ?t)
(?b add ?type)
(retract ?ask)
(return))
(defmodule questions)
(defrule request-name
=> (assert (ask name)))
(defrule request-age
=> (assert (ask age)))
(defrule request-occupation
=> (assert (ask occupation)))
And the following java code calls the hashmap handle "quest" to
convert contents of the Value object as a java generic object.
import jess.*;
import java.util.*;
public class Bridge {
public static void main (String args[]) throws Exception {
Rete engine = new Rete();
String s = "(batch taxcube.clp)";
engine.executeCommand(s);
engine.reset();
String t = "(focus interview)";
engine.executeCommand(t);
engine.run();
Value myValue = engine.fetch("quest");
Object o = myValue.javaObjectValue(engine.getGlobalContext());
System.out.println(o);
ArrayList superArray = (ArrayList) o;
System.out.println(superArray);
//System.out.println(superArray.get(0));
}
}
My problem is that the ArrayList that I have fetched in the global
context is returned empty despite rules getting executed and the
arraylist being populated with the question data in the ask module.
How do i get the populated arraylist(s)?
Please help
--------------------------------------------------------------------
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]
--------------------------------------------------------------------