On Apr 9, 2007, at 9:13 PM, Jim Yates wrote:


I'm trying to build a rule that matches shadow facts using a Java Bean template. I want to build the following logic: (facilitycode != 'K' and faciltiycode!= 'S' and (amt > 7500 or amt < -7500 or rvu < -500 or rvu > 500) ) OR ( (quantity < -10 or quantity > 10) and costctr in 403 111 702 189 489)
and (servicecode contains 100 and quantity > 1)

I've taken a stab at a re-write, but no guarantees. A few things that might help:

1) 'or' and 'and' are not binary operators, because of the prefix notation they can take multiple boolean expressions. I'd take advantage of that (but doing that is optional).

2) 'test' is a conditional element (CE) for patterns; it's not a function.

3) 'member$' can do the set membership 'in' that you were accomplishing with the 'foreach' loop.

4) Verify that the facility code field is a symbol -- if it is a string, put S and K in double quotes.

What follows *might* possibly be an accurate translation -- but it was a pretty long expression -- so no guarantees :).

(defrule Jim_Rule "Jim Rule Comment"
  (BatchInboundTransactions (inbound_id ?inId))
  (BatchInboundTransactions (facilitycode ?facilitycode))
  (BatchInboundTransactions (amount ?amount))
  (BatchInboundTransactions (rvu ?rvu))
  (BatchInboundTransactions (quantity ?quantity))
  (BatchInboundTransactions (costctr ?costctr))
  (BatchInboundTransactions (servicecode ?servicecode))
  (test
    (and
     (neq ?facilitycode S)
     (neq ?facilitycode K)
     (or (< ?amount -7500) (> ?amount 7500)
         (< ?rvu -500) (> ?rvu 500)
         (< ?quantity -10) (> ?quantity 10)
         (member$ ?costctr (create$ 403 111 702 189 489))) ; NOTE #1, NOTE #2
     (str-index 100 ?servicecode)
     (> ?quantity 1)))
  =>
  (add (new BatchWorkListErrors "New" ?inId 1)))

NOTE 1: In the original rule, it appeared that there was an 'and' just before the foreach test (now a member$ call) that only had one expression (so it wasn't needed).

NOTE 2: If the five numbers in the foreach are used elsewhere, you might want to declare a defglobal for reuse.


This is part of an application that will let users define the rules, 1 condition at a time. The rules will be written to disk and read in at the start of the application. I'm wrapping the OR's in a TEST because I only want to get back one match per rule.

I'm not sure its clear how the 'test' CE and 'or' phrases you have accomplish this. Take a look at the 'exists' CE that Jess provides, if you haven't already -- that might be just what you're looking for.


When I run with a quantity of 10, I get a Jess Exception "Undefined function test". If I use quantity of 11 I get back one match.

'test isn't a function, it's a pattern. It should start a pattern on the LHS. I suspect that a nested 'test' isn't reached due to the (> ? quantity 10) check -- but when ?quantity is within [-10,10], Jess needs to evaluate another part of a boolean expression and tries to evaulate 'test' as a function, not a pattern.

Hope that helps,

- Mike

--------------------------------------------------------------------
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