[rules-users] How to write rules with optional parts?
Wolfgang Laun
wolfgang.laun at gmail.com
Thu Jul 21 01:57:36 EDT 2011
In this particular case you can do
$p1:person (name=="Alice")
$p3:person (name=="David", this after[0,1] $p1)
not person (name != "Bob", this after[0,1] $p1 && before[0,1] $p3 )
A more general approach should be possible by monitoring states rather than
event sequences, especially if you process events in real time.
1) Alice => state := A
2a) David => OK
2b) Bob => state := AB
2c) Edward => state := _
And so on.
-W
On 20 July 2011 22:21, Edward Johnson <ejohnson at coderyte.com> wrote:
> 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)
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110721/bde180fb/attachment.html
More information about the rules-users
mailing list