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))))
But a line like this, won't work.
(test(and(= ?servicecode 847314565)(> ?quantity 1)(or(= ?amount 4.17))))
The intended behavior is to match (servicecode = 847314565 and quantity
> 1) OR amount = 4.17
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.
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.
begin:vcard
fn:Jim Yates
n:Yates;Jim
email;internet:[EMAIL PROTECTED]
tel;work:214-244-4285
tel;cell:214-244-4285
x-mozilla-html:TRUE
version:2.1
end:vcard