On Mar 21, 2007, at 11:19 AM, ricktee wrote:


Hi Dr Hill,

Thank you very much for your reply. I should have done more research before
doing this project, looks like I'm in big trouble now...

No, you're not in trouble at all. There's no problem doing any of what you need to do; it's just as I stated before that the more you describe your goals rather than specific technical problems, the easier it would be to guide you. You (and I) can't solve a problem before you define what the problem is.


Could you please help me to suggest a suitable method to get these facts out of Jess? My Java program passes a "user" fact with health information to
Jess for processing. Afterwhich "recommended exercises" facts will be
created. I need to find a way for Java to pull up these facts and display
them in a table format in Java GUI.


You haven't told us how membership in the set of "recommended exercises" facts is defined. Is it all the facts belonging to a specific set of templates? Is is all the facts defined after a certain point in time? Is it all the facts that aren't input facts? The solution for each of these would be a little bit different, but a general technique would be to use the Rete.listFacts() method to get an Iterator over all of working memory after your run, and simply collect those facts that are of interest (put them in a Collection of some kind.)

Then as far as displaying your facts in a table: since your templates all have different slots, I don't know what this table will look like, exactly. But that you will have to work out for yourself. For any given fact, to get a list of "slot, value" pairs, you can call getDeftemplate() on the Fact to get a Deftemplate object, use the public methods of Deftemplate to find out how many slots and what their names are, and then get the corresponding values from the Fact with that class's own API.

Stepping back further, a general principle of programming of all kinds is that rather than searching for stuff, it's often better not to lose it in the first place. In this case, rather than asserting results as facts that will never be used in Jess for anything, you could instead report the results from Jess code directly to your Java code, so that you'd never have to query for anything. If the Jess code had an object of type "ResultsReporter" which had methods like, for example,

addMuscleMachine(String bodyPart, String[] station)

then your Jess rules could call this like

(?reporter addMuscleMachine arms-upperfront (create$ A2 A5 A7))

instead of asserting results as facts.

Thank you so very much again
Rick

Below is a sample of the real facts created in the Jess working memory after
processing
1 match-cardio-machine fact
2 program-toning facts
9 match-muscle-machine facts

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

(match-cardio-machine
        (purpose cardio)
        (station C1 C2 C8 C9))

(program-toning
        (ident condition)
(dura 3) (rm 25) (rep 10-15) (set 1) (rest 0.5) (explanation "This is the
conditioning stage"))

(program-toning
        (ident improve)
(dura 6) (rm 30) (rep 15-20) (set 2-3) (rest 0.5-1) (explanation "This is
the improving stage"))

(match-muscle-machine (body-part arms-upperfront) (station A2 A5 A7)) (match-muscle-machine (body-part arms-upperback) (station A2 A9 A10))
(match-muscle-machine (body-part shoulders)             (station A4 W3 C6))
(match-muscle-machine   (body-part chest)               (station O1))   
(match-muscle-machine   (body-part abs)                 (station O5 O3))
(match-muscle-machine   (body-part back)                (station L3 L5))
(match-muscle-machine   (body-part butt)                (station A2 L0 L9))
(match-muscle-machine (body-part legs-upperfront) (station X10 T10))
(match-muscle-machine   (body-part legs-upperback)      (station D2))

********************************************************************** ******************
Below is their template

(deftemplate match-cardio-machine
        (slot purpose)
        (multislot station)     );;close

(deftemplate program-toning
        (slot ident)
        (slot dura)
        (slot rm)
        (slot rep)
        (slot set)
        (slot rest)
        (slot explanation)      );;close

(deftemplate match-muscle-machine
        (slot body-part)
        (multislot station)     );;close

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



Ernest Friedman-Hill wrote:

No, you can't. This was asked on this very list just a few weeks ago;
see here for the explanation:

http://www.mail-archive.com/[email protected]/msg09159.html

On Mar 20, 2007, at 11:52 PM, ricktee wrote:


Hi Dr Hill,
I just read your eg on queries at
http://herzberg.ca.sandia.gov/jess/docs/61/language.html#queries

Im wonder if it's possible to search query via the fact's name
instead of
its slots and multislots


*****This is my "program-cardio" and "user" fact template
(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


****this is my rule that asserts "program-cardion" fact if the user
answer
is "poor"
(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


****** This is my query search taken from
http://herzberg.ca.sandia.gov/jess/docs/61/language.html#queries
(defquery search
(declare (variables  ?tofind ))
(program-cardio (ident ?tofind)
        (stageA-intesity% ?a-int)       (stageA-duration-wks ?a-wks)
        (stageB-intesity% ?b-int)       (stageB-duration-wks ?b-wks)))


I try to replace  "program-cardio" with ?tofind but I will get an
error. Is
there a way for me to query facts via its own name? like

(defquery search
(declare (variables  ?tofind ))
( ?tofind (ident ?id)
        (stageA-intesity% ?a-int)       (stageA-duration-wks ?a-wks)
        (stageB-intesity% ?b-int)       (stageB-duration-wks ?b-wks)))

below is the java code to run it, I need to replace "cardio-low" with
"program-cardio"

//...
        engine.store("RESULT", engine.runQuery("search",
new ValueVector().add(new Value("cardio- low" ,
RU.ATOM))));

        engine.executeCommand("(store RESULT (run-query search
cardio-low))");
                
                // Fetch the result (an Iterator).
        Iterator e = (Iterator)
engine.fetch("RESULT").externalAddressValue(null);
//...

Thank you very much
rick


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




--
View this message in context: http://www.nabble.com/Retrieve-Fact- from-Java-tf3432213.html#a9596326
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]
--------------------------------------------------------------------

Reply via email to