There's an example of this in section 2.8.2 of the Jess 5.0 (final
version) manual. Here it is:

  import jess.*;
  import java.util.*;

  public class ExQuery
  {
    public static void main(String [] argv) throws JessException
    {
      // Create engine, define query and data
      Rete r = new Rete();
      r.executeCommand("(defquery search (declare (variables ?X)) (foo ?X ?Y))");
      r.executeCommand("(deffacts data" +
                         "(foo blue red)" +
                         "(bar blue green)" +
                         "(foo blue pink)" +
                         "(foo red blue)" +
                         "(foo blue blue)" +
                         "(foo orange yellow)" +
                         "(bar blue purple))");

      // Assert all the facts                         
      r.reset();
      // Run the query, store the result
      r.executeCommand("(store RESULT (run-query search blue))");
      
      // Fetch the result (an Enumeration).
      Enumeration e = (Enumeration) r.fetch("RESULT").externalAddressValue(null);
      Vector v = new Vector(); 

      // Pick each element of the Enumeration apart and store the
      // interesting part in the Vector v.
      while (e.hasMoreElements())
      {
        Token t = (Token) e.nextElement();  

        // We want the second fact in the token - the first is the query trigger
        Fact f = t.fact(1);

        // The first and only slot of this fact is the __data multislot.
        ValueVector multislot = f.get(0).listValue(null);

        // The second element of this slot is the datum we're interested in.
        v.addElement(multislot.get(1).stringValue(null));
      }
      for (Enumeration answers = v.elements(); answers.hasMoreElements();)
        System.out.println(answers.nextElement());
    }
  }
  C:\> java ExQuery
  
    red
    pink
    blue
  
 


I think Maren Zubizarreta wrote:
> Hi again:
>      While embedding jess in java code,
>      I'm trying to retrieve the enumeration generated by a run-query
> command
>      into an enumeration I can use in my java code and not like a jess
> command.
>      Does anybody know what method  to use?
>      Thanx
> 
> 
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
> 



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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