Unless you've left out some code, the "(focus interview)" should throw an exception, as I see no such module defined here. But aside from that, the other problem is that when the rules fire, the stored ArrayList is not the same one that's in the defglobal. You define the defglobal, which creates an ArrayList; then you store a reference to the ArrayList using the store function. Later, you call "reset", which, by default, resets all defglobals; here, this will create a new ArrayList, so that the one in the defglobal is not the same one that's been stored.

Either 1) wait to do the store after the reset; 2) call reset before loading the Jess code; or 3) use (set-reset-globals FALSE) to change the default behavior. Calling this function will prevent Jess from resetting global variables when reset is called.

On Jan 2, 2007, at 5:59 AM, Venkat Kasuganti wrote:

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 owner-jess- [EMAIL PROTECTED]
--------------------------------------------------------------------

---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com

--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to