Re: JESS: new to jess
nirajkumar motwani wrote: Hi All, I am new to using jess and was having some problems when i wrote a small java code... when i do the following (below is part of the code), i donot get any fired rules, why is that: ... engine.executeCommand("(watch rules)"); String rule3 ="(defrule euality-rule (test (eq 1 1)) => )"; engine.executeCommand(rule3); engine.executeCommand("(run)"); System.out.println("run command executed..."); ... The system.out statement is printed but thw watch rules does not indicate that any rule was fired? what am i doing wrong? Thanks Nirajkumar Motwani Graduate Student Computer Science Department University Of Southern California I'm a newbie too, but I think you should just insert a engine.executeCommand("(reset)"); before the run-command. Then the rule will fire. You find more about the reset-command in Jess in Action section 6.1.1. Johan -- The University of Tokyo Dept. Precision Machinery Engineering Hongo 7-3-1, Bunkyo-ku Tokyo 113-8656 JAPAN 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: new to jess
Hi Nirajkumar, As the saying goes, "...you can't get there from here." First, you'd be better off learning Jess from its command line scripting environment, then move to programming the API when you have the basics mastered. In your example, you have a few things incorrect: 1. You need to use the Jess (reset) command before running the rule engine. 2. Only rules in the module having the focus will activate and fire, provided that their left-hand side (LHS) patterns are satisfied. In this case, your (test ...) fact is always TRUE, but you don't have the right-hand side (RHS) doing anything (so you won't see any effect of the rule firing if it did, other than what the (watch) command produces. 3. Use "eq" to compare symbols, objects, and references. Use plain vanilla "=" for numbers. The danger is that you could write some code like: (bind ?x 2) (bind ?y 2.0) (if (eq ?x ?y) then ... expecting the condition to be TRUE, but it is really FALSE. Jess is comparing both value AND type, and since an INT is never the same type as a FLOAT, the condition is false. If you had said (= ?x ?y) then it would have been TRUE. You can easily prove this yourself by running this program: ;; is-equal-or-not.clp (clear) (watch all) (defrule is-equal-or-not "Will always fire since it matches the (MAIN::initial-fact)" => (bind ?x 2) (bind ?y 2.0) (printout t "x eq y :" (eq ?x ?y) crlf) (printout t "x = y :" (= ?x ?y) crlf)) (reset) (run) Back to your example, I'd recommend this approach instead: 1. Copy this sample code below, and save it as test.clp in the same folder as jess.jar or somewhere on Jess's CLASSPATH. ;; test.clp ; (clear) (defrule equality-test (test (= 1 1)) => (printout t "equality test performed OK" crlf)) (reset) (focus MAIN) (run) ;; 2. Run it by typing (batch test.clp) at the Jess command line. You should see something like: Jess> (batch test.clp) MAIN::equality-test: +1+1+2+t ==> Focus MAIN ==> f-0 (MAIN::initial-fact) ==> Activation: MAIN::equality-test : f-0, FIRE 1 MAIN::equality-test f-0, equality test performed OK <== Focus MAIN 1 Jess> My point is: Keep working many small examples like this until you are comfortable with the Jess language, then try writing Java with the Jess API. You'll learn Jess much better and more quickly. Oh... and buy a copy of "Jess In Action" http://www.manning.com/friedman-hill ! Cheers, -Jason Jason Morris Morris Technical Solutions [EMAIL PROTECTED] www.morristechnicalsolutions.com fax/phone: 503.692.1088 > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of nirajkumar motwani > Sent: Monday, August 02, 2004 2:33 PM > To: [EMAIL PROTECTED] > Subject: JESS: new to jess > > > Hi All, > I am new to using jess and was having some problems when i wrote > a small java code... > when i do the following (below is part of the code), i donot get > any fired rules, why is that: > ... > engine.executeCommand("(watch rules)"); > String rule3 ="(defrule euality-rule (test (eq 1 1)) => )"; > engine.executeCommand(rule3); > engine.executeCommand("(run)"); > System.out.println("run command executed..."); > ... > > The system.out statement is printed but thw watch rules does not > indicate that any rule was fired? what am i doing wrong? > > Thanks > > Nirajkumar Motwani > Graduate Student > Computer Science Department > University Of Southern California > 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]
JESS: new to jess
Hi All, I am new to using jess and was having some problems when i wrote a small java code... when i do the following (below is part of the code), i donot get any fired rules, why is that: ... engine.executeCommand("(watch rules)"); String rule3 ="(defrule euality-rule (test (eq 1 1)) => )"; engine.executeCommand(rule3); engine.executeCommand("(run)"); System.out.println("run command executed..."); ... The system.out statement is printed but thw watch rules does not indicate that any rule was fired? what am i doing wrong? Thanks Nirajkumar Motwani Graduate Student Computer Science Department University Of Southern California begin:vcard n:Motwani;Nirajkumar fn:Nirajkumar Motwani tel;home:323-730-1150 url:http://www-scf.usc.edu/~motwani org:;Computer Science adr:;;1133W 36th Place, Apt # 9;Los Angeles;CA;90007;USA version:2.1 email;internet:[EMAIL PROTECTED] title:Student end:vcard
Re: JESS: Newbie questions
I think Mehta, Chirag (IT) wrote: > Thank you ever so much. > > One more quick question. In my rule I have calculated the following: > > (/ ?mv ?io) > > Is there anyway to save this along with the Fact reference in ?b ?? > Sure -- the same way you might do it in Java, by using a little class to represent the association. For example public class Holder { public double number; public Object fact; public Holder(Object o, double d) { fact = o; number = d; } } Then in Jess (store RESULT (new Holder ?b (/ ?mv ?io))) - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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: Newbie questions
Thank you ever so much. One more quick question. In my rule I have calculated the following: (/ ?mv ?io) Is there anyway to save this along with the Fact reference in ?b ?? Thanks Chirag -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: 02 August 2004 15:31 To: [EMAIL PROTECTED] Subject: Re: JESS: Newbie questions I think Mehta, Chirag (IT) wrote: > > I cannot seem to figure out what is wrong! The things on the left-hand-side of a rule are always conditional elements (patterns or groups of patterns), not function calls. Jess is trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a valid slot value constraint. There's no way to bind a variable on the LHS of a rule and see it on the RHS of a rule other than by directly matching it. You're going to have to compute (/ ?mv ?io) twice, once in the "test" CE and once on the RHS of the rule. I think, by the way, that you've done something else wrong here. Each of the three bondMVMax patterns above can match a difference bondMVMax fact. Since each one matches a different slot, I'm guessing you actually mean for all the patterns to apply to the *same* fact; you're not trying to find sets of three facts, but single facts that pass all these criteria. You need to write all the criteria as one pattern: (defrule calcifnc (bondMVMax (cusip ?c) (mv ?mv) (issue_outstanding ?io&~nil)) (test (> (/ ?mv ?io) 10)) => (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)) > > Also, I wish to save all the facts that meet the tests to a data > structure and then return the data to my java program. What is the best > method to do this?? You can have the rule store a reference to the fact each time it fires; for example , in your Java code Rete engine = ... ArrayList result = new ArrayList(); engine.store("RESULT", result); Then make the rule look like (defrule calcifnc ?b <- (bondMVMax (cusip ?c) (mv ?mv) (issue_outstanding ?io&~nil)) (test (> (/ ?mv ?io) 10)) => (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf) ((fetch RESULT) add ?b)) After running the engine, the ArrayList "result" will contain references to all the jess.Fact objects that match the criteria. - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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] NOTICE: If received in error, please destroy and notify sender. Sender does not waive confidentiality or privilege, and use is prohibited. 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: Newbie questions
I think Mehta, Chirag (IT) wrote: > Thanks a million. > > Any suggestions on my second question? If you scroll down to the very bottom of this message, you'll see in the quoted part that I answered that one too. > > I need to save all the details for each fact which passes the test into > a data structure. > This I need to pass back to my java code, which in turn can save the > results to a db. > > What would be the best way of doing this? > > Chirag > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of [EMAIL PROTECTED] > Sent: 02 August 2004 15:31 > To: [EMAIL PROTECTED] > Subject: Re: JESS: Newbie questions > > I think Mehta, Chirag (IT) wrote: > > > > I cannot seem to figure out what is wrong! > > The things on the left-hand-side of a rule are always conditional > elements (patterns or groups of patterns), not function calls. Jess is > trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that > matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a > valid slot value constraint. > > There's no way to bind a variable on the LHS of a rule and see it on the > RHS of a rule other than by directly matching it. You're going to have > to compute (/ ?mv ?io) twice, once in the "test" CE and once on the RHS > of the rule. > > I think, by the way, that you've done something else wrong here. Each of > the three bondMVMax patterns above can match a difference bondMVMax > fact. Since each one matches a different slot, I'm guessing you actually > mean for all the patterns to apply to the *same* fact; you're not trying > to find sets of three facts, but single facts that pass all these > criteria. You need to write all the criteria as one pattern: > > (defrule calcifnc > (bondMVMax (cusip ?c) > (mv ?mv) > (issue_outstanding ?io&~nil)) > (test (> (/ ?mv ?io) 10)) > => > (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)) > > > > > > Also, I wish to save all the facts that meet the tests to a data > > structure and then return the data to my java program. What is the > best > > method to do this?? > > You can have the rule store a reference to the fact each time it > fires; for example , in your Java code > > Rete engine = ... > ArrayList result = new ArrayList(); > engine.store("RESULT", result); > > Then make the rule look like > > (defrule calcifnc > ?b <- (bondMVMax (cusip ?c) >(mv ?mv) >(issue_outstanding ?io&~nil)) > (test (> (/ ?mv ?io) 10)) > => > (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf) > ((fetch RESULT) add ?b)) > > After running the engine, the ArrayList "result" will contain > references to all the jess.Fact objects that match the criteria. > > - > Ernest Friedman-Hill > Advanced Software Research Phone: (925) 294-2154 > Sandia National LabsFAX: (925) 294-2234 > PO Box 969, MS 9012 [EMAIL PROTECTED] > Livermore, CA 94550 http://herzberg.ca.sandia.gov > > > 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] > > > > NOTICE: If received in error, please destroy and notify sender. Sender does not > waive confidentiality or privilege, and use is prohibited. > > > > 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 Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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: jdk 1.5 support?
I think Ahmed Mohombe wrote: > > > > I really hadn't given it any thought. What features do you suppose > > could use specific support in Jess? > Enumerations seem to be the most obvious to me. The generics stuff is > nice too, but that would be more complicated (I suppose :) ). If you have a chance, give it a try as-is and see what you can and can't do right now, and report back. Jess treats Java objects as typeless, so really I'd be surprised if you had any problem working with generics right now. Enums are basicvally just syntactic sugar over classes, so it's quite likely that you'll be able to do what you need to do with them, as well (although there may be a bit of hackery with names involved that Jess could help by abtracting away.) Speaking of which, I understand that inner classes in 1.5 don't use the old "$" naming convention anymore, which could break Jess language code that assumes it (it will also break reflective Java code that assumes it as well; I don't understand their rationale for making this change.) - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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: Newbie questions
Thanks a million. Any suggestions on my second question? I need to save all the details for each fact which passes the test into a data structure. This I need to pass back to my java code, which in turn can save the results to a db. What would be the best way of doing this? Chirag -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: 02 August 2004 15:31 To: [EMAIL PROTECTED] Subject: Re: JESS: Newbie questions I think Mehta, Chirag (IT) wrote: > > I cannot seem to figure out what is wrong! The things on the left-hand-side of a rule are always conditional elements (patterns or groups of patterns), not function calls. Jess is trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a valid slot value constraint. There's no way to bind a variable on the LHS of a rule and see it on the RHS of a rule other than by directly matching it. You're going to have to compute (/ ?mv ?io) twice, once in the "test" CE and once on the RHS of the rule. I think, by the way, that you've done something else wrong here. Each of the three bondMVMax patterns above can match a difference bondMVMax fact. Since each one matches a different slot, I'm guessing you actually mean for all the patterns to apply to the *same* fact; you're not trying to find sets of three facts, but single facts that pass all these criteria. You need to write all the criteria as one pattern: (defrule calcifnc (bondMVMax (cusip ?c) (mv ?mv) (issue_outstanding ?io&~nil)) (test (> (/ ?mv ?io) 10)) => (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)) > > Also, I wish to save all the facts that meet the tests to a data > structure and then return the data to my java program. What is the best > method to do this?? You can have the rule store a reference to the fact each time it fires; for example , in your Java code Rete engine = ... ArrayList result = new ArrayList(); engine.store("RESULT", result); Then make the rule look like (defrule calcifnc ?b <- (bondMVMax (cusip ?c) (mv ?mv) (issue_outstanding ?io&~nil)) (test (> (/ ?mv ?io) 10)) => (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf) ((fetch RESULT) add ?b)) After running the engine, the ArrayList "result" will contain references to all the jess.Fact objects that match the criteria. - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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] NOTICE: If received in error, please destroy and notify sender. Sender does not waive confidentiality or privilege, and use is prohibited. 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: FYI - using trees in Jess code
I think Jason Morris wrote: > > In fact, by using Swing's trees from my Jess code, I could attach a "user > object" to each DefaultMutableTreeNode and manipulate it via > getUserObject()/setUserObject(). In my case, the user object becomes a Jess > fact reference (or anything else I want to stick in there). Additionally, I > could take advantage of other DefaultTreeModel methods like getPath(), > getPathtoRoot(), and a whole host of useful query and enumeration methods, > which I'd otherwise have to had written from scratch. > > Jess really is the "programmer's rule engine"! > Interesting. I never thought about using DefaultMutableTreeNode as a data structure apart from Swing, but that's actually not a bad idea, certainly for experimentation, anyway. It will certainly be possible to use "accumulate" to populate trees this way. - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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: Newbie questions
I think Mehta, Chirag (IT) wrote: > > I cannot seem to figure out what is wrong! The things on the left-hand-side of a rule are always conditional elements (patterns or groups of patterns), not function calls. Jess is trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a valid slot value constraint. There's no way to bind a variable on the LHS of a rule and see it on the RHS of a rule other than by directly matching it. You're going to have to compute (/ ?mv ?io) twice, once in the "test" CE and once on the RHS of the rule. I think, by the way, that you've done something else wrong here. Each of the three bondMVMax patterns above can match a difference bondMVMax fact. Since each one matches a different slot, I'm guessing you actually mean for all the patterns to apply to the *same* fact; you're not trying to find sets of three facts, but single facts that pass all these criteria. You need to write all the criteria as one pattern: (defrule calcifnc (bondMVMax (cusip ?c) (mv ?mv) (issue_outstanding ?io&~nil)) (test (> (/ ?mv ?io) 10)) => (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)) > > Also, I wish to save all the facts that meet the tests to a data > structure and then return the data to my java program. What is the best > method to do this?? You can have the rule store a reference to the fact each time it fires; for example , in your Java code Rete engine = ... ArrayList result = new ArrayList(); engine.store("RESULT", result); Then make the rule look like (defrule calcifnc ?b <- (bondMVMax (cusip ?c) (mv ?mv) (issue_outstanding ?io&~nil)) (test (> (/ ?mv ?io) 10)) => (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf) ((fetch RESULT) add ?b)) After running the engine, the ArrayList "result" will contain references to all the jess.Fact objects that match the criteria. - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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: the extends clause in deftempates
I think Jason Morris wrote: [Charset iso-8859-1 unsupported, filtering to ASCII...] > What ever became of the "extends" clause in the definition for deftemplates? > It is clearly mentioned in the Jess online docs, but I don't see it > mentioned at all in JIA. Section 13.4 of the Jess61p7 change history > mentions it briefly. I just tried whipping up a sample, and it clearly > works in Jess 61p7. Was it omitted from JIA for a reason? > No particular reason, other than space constraints. The book doesn't document every single feature of Jess; the publisher was uneasy with the length of part II as it is, and would have liked it to be shorter. I vaguely recall a section from the book that *did* talk about deftemplate inheritance being one of the things I edited out at some point. - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov 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]
JESS: Newbie questions
Hi all, I am a newbie to jess and have written this code: (defrule calcifnc (bondMVMax (cusip ?c)) (bondMVMax (mv ?mv)) (bondMVMax (issue_outstanding ?io&~nil)) 5. (bind ?noncomp (/ ?mv ?io)) (test (> ?noncomp 10)) => (printout t ?c " is Non Complaint nc = " ?noncomp crlf) ) At line 5, it gives me the following error: Jess reported an error in routine Jesp.parsePattern while executing (batch jessrules/bondMVMaxPCOutstandingrules.clp). Message: Bad slot value . Program text: ( defrule calcifnc ( bondMVMax ( cusip ?c ) ) ( bondMVMax ( mv ?mv ) ) ( bondMVMax ( issue_outstanding ?io & ~~ nil ) ) ( bind ?noncomp ( at line 5. I cannot seem to figure out what is wrong! Also, I wish to save all the facts that meet the tests to a data structure and then return the data to my java program. What is the best method to do this?? Thanks Chirag NOTICE: If received in error, please destroy and notify sender. Sender does not waive confidentiality or privilege, and use is prohibited.
JESS: the extends clause in deftempates
What ever became of the "extends" clause in the definition for deftemplates? It is clearly mentioned in the Jess online docs, but I don't see it mentioned at all in JIA. Section 13.4 of the Jess61p7 change history mentions it briefly. I just tried whipping up a sample, and it clearly works in Jess 61p7. Was it omitted from JIA for a reason? -JM 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]