On Wednesday 25 April 2007 11:09:48 am Jim Yates wrote: > So how do I combine conditional elements? If I build one line like this > it works > (test(or(= ?amount 4.17)(and(= ?servicecode 847314565)(> ?quantity > 1))))
That says "Either amount is 4.17, or servicecode is 847314565 and quantity is more than 1". > But a line like this, won't work. > (test(and(= ?servicecode 847314565)(> ?quantity 1)(or(= ?amount 4.17)))) That says "Servicecode is 847314565 and quantity is more than 1 and amount is 4.17". > > The intended behavior is to match (servicecode = 847314565 and quantity > > > 1) OR amount = 4.17 So your first way to do it is correct. > > This is part of an application that lets users define their own rules, > so I don't know ahead of time what comparison operators and conditional > elements they will choose. They also have the ability to modify a rule > once it's created. If I'm forced to rearrange the OR's together up > front, the rule won't look the same as they entered it, when they start > to modify it. That's not necessarily so; but the transformation between the Jess code and the user interface rendering of it won't be quite as simple as you've made it out to be. You basically need to transform the user's input into a tree structure of some kind, and then be able to emit it in prefix form (for Jess) or infix form (for the user, again.) > > Ernest Friedman-Hill wrote: > > I don't see any variable ?rvu in your rule, so I don't think we have > > all the necessary information to explain why. But we can do something > > better, which is to help you understand how Jess interprets your rule. > > > > Each conditional element on the left hand side is separate, and all > > have to match for the rule to match. In your first rule, you had > > > > (test (or (= ?amount 4.17))) > > > > This one line would match if and only if ?amount was exactly 4.17. The > > "or" is redundant.; it would be exactly the same if you had just > > written > > > > (test (= ?amount 4.17)) > > > > I'm concerned that you're thinking the "or" affects the relationship > > of this conditional element to previous ones; it does not. The > > expressions inside the "or" are alternatives, and one or more of them > > must be true for the "or" function to return true. > > > > Now, I should also tell you that using "test" conditional elements and > > function calls is a lot less efficient than matching directly. A > > vastly better (and shorter and clearer, too!) version of your first > > rule would look like this: > > > > defrule Jim_Rule "Jim Rule Comment" > > (BTransactions > > (amount 4.17) > > (quantity 1) > > (servicecode 847314565) > > ) > > => > > (printout t "Rule Matched" crlf) > > ) > > > > As Yuping pointed out, you might have intended something else, but > > this is exactly equivalent to what your original rule actually says. -- --------------------------------------------------------- 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] --------------------------------------------------------------------