First I should point out that your terminology is incorrect here. "red" and "blue" aren't facts, they're merely symbols; and they're not stored in working memory, but rather in an area simply called "storage". Only actual facts are stored in working memory, and this is done solely by using assert (or definstance, etc.)

Storage is intended for transferring things between Jess and Java, as you've done here. It's merely a HashMap; the first argument to "store" or "fetch" is the key to the map. Therefore if you store two things with the same key, the second one erases the first. That's what's happening in your code.

You could go two ways here. If "red" and "blue" are intended only for transmitting back to Java, then using storage makes sense; you just need to store things in a way that doesn't discard values. For example, you could store an ArrayList, then add items to that list; then the whole ArrayList would be available to Java code:

;; In Jess

(store first (new java.util.ArrayList))
...
((fetch first) add red)

// In Java
ArrayList firsts = (ArrayList) rete.fetch("first");


Alternatively, you could use actual facts instead of storage, and retrieve things from Java using either defqueries, or Rete.listFacts () with a filter.

On Dec 3, 2006, at 6:38 AM, Venkat Kasuganti wrote:

I have the following rules and facts in Jess:

(defrule ruleone (enter name) => (store first red) (assert (enter place))) (defrule ruletwo (enter place) => (store first blue) (assert (enter animal)))
(reset)
(assert (enter name))

I have the following code in Java to retrieve the facts red and blue
and print them.

import jess.*;

public class ReteFirst {



      public static String forwardQuestions() throws Exception {

              Rete engine = new Rete();
              engine.executeCommand ("(batch firstrules.clp)");

              //System.out.println ("New Rete is created");
              engine.run();

              Value myValue = engine.fetch("first");

String s = myValue.stringValue(engine.getGlobalContext ());

              return s;
      }



      public static void main(String args[]) throws Exception {

              //ReteFirst a = new ReteFirst();


              System.out.println(ReteFirst.forwardQuestions());




      }
}

When I execute this code I get only the last fact ie blue printed.  I
need both facts printed. Is there a specific function to search the
working memory to test the existence of fact based on the head?

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