Hi Mr Ernest!

Sorry for the confusion, my program is quite lengthy so I did a very scale
down version. I now did a more suitable scale down version.

Im using "TestFrame.java" as a user interface to ask user some questions.
The user reply is stored in a string, and then passed to Jess to be
processed.

Java is to ask the user about his cardio fitness status, the user answers
either "poor" or "good" and is sent to Jess.
The Jess "cardio.clp" will recommend the suitable type of running program
for users with "poor cardio" or "good cardio".

The fact created is named "program-cardio" and it contains the information
of the duration and intensity of the running program.

I hope to use java to retrieve the "program-cardio" fact and print it in a
table format in java GUI.

This is the Jess fact created.
(program-cardio (ident cardio-low)      
                                (stageA-intesity% 30)   (stageA-duration-wks 3)
                                (stageB-intesity% 50)   (stageB-duration-wks 5) 
))

I hope to print it in Java in a format like

                intesity       week
Stage A     30             1
                35             2
                40             3
Stage B     50             1

The Java will do its own increment of +5% intensity per week. I figure if I
could get the fact in a array format it would be easy to retrieve each
number as what it is.

I hope this explains my program... I haven't did any corrections yet, I will
read up on "TekMart" now and will most likely come back again : )

thanks for yer help again
rick


************************************************************************************
//TestFrame.java
public class TestFrame{
private static Rete engine;

public static void main(String[] args)
{
        //program ask user: what is your cardio status? answer=poor/good
        //user enters "poor" and the answer is stored in a string
        String user_answer = "poor";
        
        //the answer is to be send to jess
        String construct_fact = "(assert (user (answer " + user_answer + ")))";

        System.out.println(" Java to send: " + construct_fact );
        
        try 
        {       
                engine = new Rete();
            engine.reset();
                engine.batch("cardio.clp");
                engine.reset();
                
                engine.executeCommand(construct_fact);
                engine.run();
                
                
                ValueVector get_fact = engine.findFactByFact("program-cardio");
                Vector temp                  = 
get_fact.factValue(engine.getGlobalContext());
        }
                
        catch (JessException ex) 
        {       System.err.println("ERROR");    }

        //some method to print out the retreived fact in a table format

} //close main
}//close class

*************************************************************************************
;;cardio.clp

;;;; template for a cardio exercise program ;;;;

(deftemplate program-cardio
(slot ident)
(slot stageA-intesity%)
(slot stageA-duration-wks)
        (slot stageB-intesity%)
        (slot stageB-duration-wks)      );;close


(deftemplate user
(slot answer)   );;close


;;rules to recommend 2 types of cardio programs

(defrule recommend-program-poor
(user (answer poor))
=> (assert (program-cardio      (ident cardio-low)      
                                (stageA-intesity% 30)   (stageA-duration-wks 3)
                                (stageB-intesity% 50)   (stageB-duration-wks 
5)))
(printout t " Jess: recommends low-cardio running schedule " )  );close


(defrule recommend-program-good
(user (answer good))
=> (assert (program-cardio      (ident cardio-high)     
                                (stageA-intesity% 70)   (stageA-duration-wks 7)
                                (stageB-intesity% 90)   (stageB-duration-wks 
9))) 
(printout t " Jess: recommends high-cardio running schedule " ) );close

*****************************************************************************************


Ernest Friedman-Hill wrote:
> 
> It would be helpful, I think, if you told us what you wanted to do in  
> terms of business logic, rather than as "how do I do X in Jess",  
> because the questions you really need answered are about the proper  
> way to use Jess itself.
> 
> In this case, note that if you used Rete.assertString() instead of  
> executeCommand() to assert the fact, then that method returns the  
> jess.Fact object itself. You can then get the individual slot values  
> from that Fact object using its getSlotValue() method. But it's a  
> mystery to me why you want to do this -- you've just asserted the  
> fact, so why would you want to look at it?
> 
> The proper way to find facts that are created as a result of running  
> some rules is to use a defquery, as detailed in the "TekMart" section  
> of the book.
> 
> 
> On Mar 20, 2007, at 4:34 AM, ricktee wrote:
> 
>>
>> Good day,
>>
>> Im using java to load the "cardio.clp" file then java ex-commend a  
>> string to
>> create ththe following fact in jess.
>>
>> (program-cardio
>> (ident cardio-low)
>>          (cond-inte 40)   (cond-dura  6)
>>          (impr-inte 70)    (impr-dura 20)
>>          (main-inte 70)   (main-dura  1)))
>>
>> I read in the "Jess in action" book (p311) there is a  
>> "findFactByFact()"
>> method, but I dont know how to use it. Can you please help me? How  
>> do I get
>> the (program-cardio) fact out of Jess? Is ValueVector the correct  
>> format to
>> store the fact? Or should I use vectors?
>>
>> And is there a way to auto format the retrieved fact in a array for  
>> easy
>> using? Or something similar? Like-
>>
>> String [] [] cardio_program = {
>> ("ident", "cardio-low"),
>> ("cond-inte", "40"),    ("cond-dura", "6"),
>> ("impr-inte",  "70"),    ("impr-dura", "20"),
>> ("main-inte", "70"),   ("main-dura",  "1")  }
>>
>> The "cond-inte 40" stands for "conditioning intensity at 40%" which Im
>> suppose to use it for some java caculation.
>>
>> Thank you very much for your help
>> rick
>>
>>
>> Below is the scale down program
>> http://www.geocities.com/t_web_design/TestFrame.java
>> http://www.geocities.com/t_web_design/cardio.txt
>>
>> ********************************************************************** 
>> ******
>> //TestFrame.java
>>
>> import jess.*;
>> import java.util.*;
>>
>> public class TestFrame{
>> private static Rete engine;
>>
>> public static void main(String[] args)
>> {
>>      String assert_fact = "(assert (program-cardio (ident cardio-low) 
>> (cond-inte
>> 40)  (cond-dura  6)(impr-inte 70)  (impr-dura 20)(main-inte 70)   
>> (main-dura
>> 1))  )";
>>
>>      try
>>      {       
>>              engine = new Rete();
>>              engine.reset();
>>              engine.batch("cardio.clp");
>>              engine.reset();
>>              
>>              engine.executeCommand(assert_fact);
>>              engine.run();
>>              
>>              ValueVector get_fact = engine.findFactByFact("program-cardio");
>>              Vector temp                  = 
>> get_fact.factValue(engine.getGlobalContext());
>>      }
>>              
>>      catch (JessException ex)
>>      {       System.err.println("ERROR");    }
>>
>> } //close main
>> }
>>
>> ********************************************************************** 
>> *********
>> ;; cardio.clp
>>
>> ;;;; template for a cardio exercise program ;;;;
>>
>> (deftemplate program-cardio
>> (slot ident)
>> (slot cond-inte)
>> (slot cond-dura)
>>      (slot impr-inte)
>>      (slot impr-dura)
>>              (slot main-inte)
>>              (slot main-dura)        
>> (slot explanation)           );;close
>>
>>
>> ;;;; rule , to say the fact has been created by Java ;;;;;;;;
>> (defrule access-by-java
>> (program-cardio (ident cardio-low))
>> =>
>> (printout t "The jess file has been accessed by Java, (program- 
>> cardio) fact
>> created" crlf ) );;close
>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Retrieve-Fact- 
>> from-Java-tf3432213.html#a9567941
>> Sent from the Jess mailing list archive at Nabble.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 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]
> --------------------------------------------------------------------
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Retrieve-Fact-from-Java-tf3432213.html#a9574392
Sent from the Jess mailing list archive at Nabble.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