JESS and JAVA

View: New views
2 Messages — Rating Filter:   Alert me  

JESS and JAVA

by Daniella Touvet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I have the following code:

                Rete Engine = new Rete ();
                Engine.batch ( "c: \ \ example.clp");

As a result of the execution of this program java, an undetermined number of facts with the following structure:

(Deftemplate Student
        (Slot name (type string))
        (Slot age (integer))  )
 
Will be loaded in the working memory .

After the execution of these two instructions, I want to be able to view this set of facts in the console JAVA in the following manner:

The students are:  name     age

    Brian      18
        Steven   21
          Charly    23
          Jessy     19
                             .          .
                             .          .
                             .          .

Thanks in advance.

Re: JESS: JESS and JAVA

by Ksawi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello!


You can define query:


(defquery printStudents

       (Student (name ?x) (age ?y)))

To define it from Java you need to execute the following code:


rete.eval("(defquery printStudents (Student (name ?x) (age ?y)))"));


Now you have to execute the query:


QueryResult qs = rete.runQueryStar("printStudents", new ValueVector());


and then you can print the result in Java console:


System.out.println("The students are:        name        age");

while(result.next())

{

       try 

       {

               System.out.println("\t\t" + result.getString("x") + "\t" + result.getString("y"));

       } catch (JessException e) 

       {

                       e.printStackTrace();

       }

}


That's all. It should works.


-- 

Best regards,

 Jaroslaw Bak, http://www.put.poznan.pl