[rules-users] How to write rules with optional parts?

Edward Johnson ejohnson at coderyte.com
Wed Jul 20 16:21:45 EDT 2011


How do you do rules that are a sequence of events where some of them are optional?

Example:

Alert if DAVID enters a room after ALICE or after ALICE and BOB
If it were a string, this is roughly equivalant to the regex /ALICE( BOB)? DAVID/

So:
Alice then David => alert
Alice then Bob then David => alert
Alice then Charles then David => no alert

I could write this as two rules but as the rules get more complex it could by hard to manage the resulting combatorial explosion.  Here it is as two rules:

Rule 1:
  $p1:person (name=="Alice")
  $p2:person (name=="David", this after[0,1] $p1)

Rule 2:
  $p1:person (name=="Alice")
  $p2:person (name=="Bob", this after[0,1] $p1)
  $p3:person (name=="David", this after[0,1] $p2)



More information about the rules-users mailing list