RE: JESS: Defining an order
I think that Sven wrote: >>that's also exactly what I tried to realize. I thought it could be shorter ;-) Hi Sven, Like I said, I'm just "holding down the fort" here. :-D I'm glad that my solution helped you out -- I'm sure there are several good ways to do it. If you want the one-line solutions, you have to wait for Ernest to return! ;-) Cheers, Jason Jason Morris Morris Technical Solutions [EMAIL PROTECTED] www.morristechnicalsolutions.com fax/phone: 503.692.1088 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]
Re: JESS: Defining an order
Hello Bob. > I may have misinterpreted your problem with my last response. I assumed > that there > can be many of the same encodings with different qualities and you need the > best of > these. Correct? No, it is a 1 to 1 relationship between the encoding and the quality rank. That means there are no equal encodings with different qualities. I just wanted to model the trivial relationship "encoding A is better than encoding B". I'm not sure if that's really a good solution... > (defrule find-best-quality > (device > (encoding ?encoding)) > (encodingQualityOrder > (encoding ?encoding) > (qualityRank ?qualityRank)) > (not (encodingQualityOrder > (encoding ?encoding) >(qualityRank ?qo&:(> ?qo ?qualityRank > > => > > (printout t "Encoding: " ?encoding crlf) > ) I tried that before, but the problem with this approach was that it is firing for every single device encoding. There should be more than one device encodings possible. But the rule then behaves like this: "Find the best/highest encoding for every seperate device-encoding asserted". And this is always this single device-encoding, because there is no comparison with several encodingQualityOrders. I guess that is the case here, correct me if i'm wrong... Thank you for your answers. I just noticed the other solutions from Johannes Echterhoff and Jasen Morris, which look like solving the problem. But not as short as I thought it could be ;-) Regards Sven > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of [EMAIL PROTECTED] > Sent: Tuesday, August 24, 2004 11:36 AM > To: [EMAIL PROTECTED] > Subject: JESS: Defining an order > > > Hello, > > i'm new to jess. I try to define an order with the following template: > > (deftemplate encodingQualityOrder > (slot encoding) > (slot qualityRank)) > > Example Facts look like this: > > (encodingQualityOrder > (encoding AVI) > (qualityRank 1)) > > (encodingQualityOrder > (encoding RM) > (qualityRank 2)) > > > > 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] > 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]
Re: JESS: Defining an order
Hello Johannes, that's exactly what I tried to realize. Thank you Sven Am Dienstag, 24. August 2004 23:44 schrieb Johannes Echterhoff: > Hi. > > I'm not quite sure if i got you right, but let me suppose following > solution: > > At first, make a (reset) > then enter this: > > > (deftemplate encodingQualityOrder > (slot encoding) > (slot qualityRank)) > > (deftemplate device > (slot devicename) > (multislot encodinglist)) > > (defrule find-best-quality > (device > (devicename ?devicename) > (encodinglist $?encodinglist)) > (encodingQualityOrder > (encoding ?encoding&:(member$ ?encoding $?encodinglist)) > (qualityRank ?qualityRank)) > (not (encodingQualityOrder (encoding ?coding&:(member$ ?coding > $?encodinglist)) (qualityRank ?qo&:(> ?qo ?qualityRank > > => > > (printout t "Best encoding for device " ?devicename " is: " ?encoding > crlf) ) > > ;;--- > > (assert (device (devicename d1) (encodinglist (create$ AVI RM MPG > (assert (device (devicename d2) (encodinglist (create$ RM AVI > (assert (device (devicename d3) (encodinglist (create$ RM > (assert (encodingQualityOrder (encoding AVI) (qualityRank 1))) > (assert (encodingQualityOrder (encoding RM) (qualityRank 2))) > (assert (encodingQualityOrder (encoding MPG) (qualityRank 3))) > > > Finally (run) the engine. > > Output is: > Best encoding for device d3 is: RM > Best encoding for device d2 is: RM > Best encoding for device d1 is: MPG > > I hope this helps a bit though again i am not sure if this exactly is what > you need and as I am still a Jess-Newbie I guess that this problem could be > solved in a better way. :-) > > Greetings, > Johannes Echterhoff > > > > > 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] > 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]
Re: JESS: Defining an order
Hello Jason, that's also exactly what I tried to realize. I thought it could be shorter ;-) Thank you Sven Am Mittwoch, 25. August 2004 00:48 schrieb Jason Morris: > I think that Sven wrote: > >> How can i modify my rule so that it really picks out the right encoding? > > Hi Sven, > > Bob may have already given you what you need, but here's another thought. > Try this batch file and see if it's the behavior that you want. > Note that I changed your templates a bit. > > ;; best.clp > (clear) > ;;(watch all) ;;you can toggle this on/off > > ;; Devices have multiple encodings, which have their own details. > (deftemplate device > (slot id) > (multislot encoding-ids)) ;; a list of encoding "id"s. > > ;; Acts like a "linking table" in a RDBMS > (deftemplate encoding > (slot id) > (slot type) > (slot rank)) > > ;; Returns the minimum value of a numeric list. > (deffunction min-value (?list) > (bind ?min (nth$ 1 (first$ ?list))) > (foreach ?n (rest$ ?list) > (if (numberp ?n) then > (if (< ?n ?min) then > (bind ?min ?n)) > else > (printout t "Non-numeric list" crlf) > (return nil))) > (return ?min)) > > ;; Load a test factbase > (deffacts devices-and-encodings > (device (id 1) (encoding-ids 1 3 4)) > (device (id 2) (encoding-ids 1 3 4)) > (device (id 3) (encoding-ids 2 5)) > (device (id 4) (encoding-ids 1 3 5)) > (device (id 5) (encoding-ids 2 4)) > (encoding (id 1) (type MP3) (rank 1)) > (encoding (id 2) (type RM) (rank 2)) > (encoding (id 3) (type AVI) (rank 3)) > (encoding (id 4) (type WAV) (rank 4)) > (encoding (id 5) (type AU) (rank 5)) > ) > ;; This fires for each device in inventory, printing its best quality > encoding. > (defrule find-best-encoding-for-each-device > "For each device, print its best (lowest) encoding rank." > (device (id ?dev-id) (encoding-ids $?enc-ids)) > (encoding (id ?id) (type ?t) (rank =(min-value $?enc-ids))) > => > ;; Get the best encoding for this device > (printout t "The best quality encoding for device id " ?dev-id " is " ?t > crlf)) > > (reset) > (run) > ;;== > > Jess prints out... > Jess> (batch best.clp) > The best quality encoding for device id 5 is RM > The best quality encoding for device id 3 is RM > The best quality encoding for device id 4 is MP3 > The best quality encoding for device id 2 is MP3 > The best quality encoding for device id 1 is MP3 > 5 > Jess> > > > Hope this helps! > Cheers, > > Jason > > > Jason Morris > Morris Technical Solutions > [EMAIL PROTECTED] > www.morristechnicalsolutions.com > fax/phone: 503.692.1088 > > > > > > 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] > 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]
RE: JESS: Defining an order
I think that Sven wrote: >> How can i modify my rule so that it really picks out the right encoding? Hi Sven, Bob may have already given you what you need, but here's another thought. Try this batch file and see if it's the behavior that you want. Note that I changed your templates a bit. ;; best.clp (clear) ;;(watch all) ;;you can toggle this on/off ;; Devices have multiple encodings, which have their own details. (deftemplate device (slot id) (multislot encoding-ids)) ;; a list of encoding "id"s. ;; Acts like a "linking table" in a RDBMS (deftemplate encoding (slot id) (slot type) (slot rank)) ;; Returns the minimum value of a numeric list. (deffunction min-value (?list) (bind ?min (nth$ 1 (first$ ?list))) (foreach ?n (rest$ ?list) (if (numberp ?n) then (if (< ?n ?min) then (bind ?min ?n)) else (printout t "Non-numeric list" crlf) (return nil))) (return ?min)) ;; Load a test factbase (deffacts devices-and-encodings (device (id 1) (encoding-ids 1 3 4)) (device (id 2) (encoding-ids 1 3 4)) (device (id 3) (encoding-ids 2 5)) (device (id 4) (encoding-ids 1 3 5)) (device (id 5) (encoding-ids 2 4)) (encoding (id 1) (type MP3) (rank 1)) (encoding (id 2) (type RM) (rank 2)) (encoding (id 3) (type AVI) (rank 3)) (encoding (id 4) (type WAV) (rank 4)) (encoding (id 5) (type AU) (rank 5)) ) ;; This fires for each device in inventory, printing its best quality encoding. (defrule find-best-encoding-for-each-device "For each device, print its best (lowest) encoding rank." (device (id ?dev-id) (encoding-ids $?enc-ids)) (encoding (id ?id) (type ?t) (rank =(min-value $?enc-ids))) => ;; Get the best encoding for this device (printout t "The best quality encoding for device id " ?dev-id " is " ?t crlf)) (reset) (run) ;;== Jess prints out... Jess> (batch best.clp) The best quality encoding for device id 5 is RM The best quality encoding for device id 3 is RM The best quality encoding for device id 4 is MP3 The best quality encoding for device id 2 is MP3 The best quality encoding for device id 1 is MP3 5 Jess> Hope this helps! Cheers, Jason Jason Morris Morris Technical Solutions [EMAIL PROTECTED] www.morristechnicalsolutions.com fax/phone: 503.692.1088 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]
Re: JESS: Defining an order
Hi. I'm not quite sure if i got you right, but let me suppose following solution: At first, make a (reset) then enter this: (deftemplate encodingQualityOrder (slot encoding) (slot qualityRank)) (deftemplate device (slot devicename) (multislot encodinglist)) (defrule find-best-quality (device (devicename ?devicename) (encodinglist $?encodinglist)) (encodingQualityOrder (encoding ?encoding&:(member$ ?encoding $?encodinglist)) (qualityRank ?qualityRank)) (not (encodingQualityOrder (encoding ?coding&:(member$ ?coding $?encodinglist)) (qualityRank ?qo&:(> ?qo ?qualityRank => (printout t "Best encoding for device " ?devicename " is: " ?encoding crlf) ) ;;--- (assert (device (devicename d1) (encodinglist (create$ AVI RM MPG (assert (device (devicename d2) (encodinglist (create$ RM AVI (assert (device (devicename d3) (encodinglist (create$ RM (assert (encodingQualityOrder (encoding AVI) (qualityRank 1))) (assert (encodingQualityOrder (encoding RM) (qualityRank 2))) (assert (encodingQualityOrder (encoding MPG) (qualityRank 3))) Finally (run) the engine. Output is: Best encoding for device d3 is: RM Best encoding for device d2 is: RM Best encoding for device d1 is: MPG I hope this helps a bit though again i am not sure if this exactly is what you need and as I am still a Jess-Newbie I guess that this problem could be solved in a better way. :-) Greetings, Johannes Echterhoff 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]
RE: JESS: Defining an order
I may have misinterpreted your problem with my last response. I assumed that there can be many of the same encodings with different qualities and you need the best of these. Correct? Bob Orchard National Research Council Canada Conseil national de recherches Canada Institute for Information Technology Institut de technologie de l'information 1200 Montreal Road, Building M-50 M50, 1200 chemin Montrial Ottawa, ON, Canada K1A 0R6Ottawa (Ontario) Canada K1A 0R6 (613) 993-8557 (613) 952-0215 Fax / tilicopieur [EMAIL PROTECTED] Government of Canada | Gouvernement du Canada -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, August 24, 2004 11:36 AM To: [EMAIL PROTECTED] Subject: JESS: Defining an order Hello, i'm new to jess. I try to define an order with the following template: (deftemplate encodingQualityOrder (slot encoding) (slot qualityRank)) Example Facts look like this: (encodingQualityOrder (encoding AVI) (qualityRank 1)) (encodingQualityOrder (encoding RM) (qualityRank 2)) 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]
RE: JESS: Defining an order
Check your 'not' pattern. It does not restrict the matching to the same encoding as the one matched in the previous patters. so it requires that the ranking be better than ANY encoding. Change as follows: (defrule find-best-quality (device (encoding ?encoding)) (encodingQualityOrder (encoding ?encoding) (qualityRank ?qualityRank)) (not (encodingQualityOrder (encoding ?encoding) (qualityRank ?qo&:(> ?qo ?qualityRank => (printout t "Encoding: " ?encoding crlf) ) Bob Orchard National Research Council Canada Conseil national de recherches Canada Institute for Information Technology Institut de technologie de l'information 1200 Montreal Road, Building M-50 M50, 1200 chemin Montrial Ottawa, ON, Canada K1A 0R6Ottawa (Ontario) Canada K1A 0R6 (613) 993-8557 (613) 952-0215 Fax / tilicopieur [EMAIL PROTECTED] Government of Canada | Gouvernement du Canada -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, August 24, 2004 11:36 AM To: [EMAIL PROTECTED] Subject: JESS: Defining an order Hello, i'm new to jess. I try to define an order with the following template: (deftemplate encodingQualityOrder (slot encoding) (slot qualityRank)) Example Facts look like this: (encodingQualityOrder (encoding AVI) (qualityRank 1)) (encodingQualityOrder (encoding RM) (qualityRank 2)) 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]