[rules-users] Truth maintenance and RHS variables
Wolfgang Laun
wolfgang.laun at gmail.com
Tue Feb 7 09:53:41 EST 2012
Absence of facts (and events) is not a good foundation for rules, as you
have discovered.
Consider that the arrival of an event with some specific itemName is
another fact, and you want to monitor the aging of that secondary fact, or
cancel it as soon as yet another one arrives.
rule "start monitoring"
when
$se: StateEvent( $in: itemName )
then
Monitor m = new Monitor( $se, $in );
insert( m );
end
rule "stop monitoring"
when
$se: StateEvent( $in: itemName )
$m: Monitor( stateEvent != $se, itemName == $in )
then
retract( $m );
end
rule "nothing for 1m"
timer( int: 1m )
when
$m: Monitor( $in: itemName )
then
System.out.println( "not working: " + $in );
retract( $m );
end
Untested!
-W
2012/2/7 Juanker Atina <juankera at gmail.com>
> Hi there,
>
> I'm working on a rule that will alert me when there is no events from the
> sensors for a while.
>
> So, first idea was to use time window and matches in condition side, to
> match all types of sensors, and then to print that something is wrong.
>
> rule "Alert if there is no activity"
> when
> not StateEvent(itemName matches "door.*|presence.*|luminosity.*") over
> window:time( 1m ) from entry-point "EventStream"
> then
> System.out.println("Alert: one sensor is not working");
> end
>
> First change was to add a timer, as truth maintenance will fire this rule
> the first time, but not forever. So i add a timer to fire the rule every 20
> seconds, for example.
>
> rule "Alert if there is no activity"
> timer (cron:0/20 * * * * ?)
> when
> not StateEvent(itemName matches "door.*|presence.*|luminosity.*") over
> window:time( 1m ) from entry-point "EventStream"
> then
> System.out.println("Alert: one sensor is not working");
> end
>
> The second thing i want to achieve is to print what specific sensor is not
> working, but i understand that as there is no StateEvent, i can't declare a
> variable, for example.
>
> rule "Alert if there is no activity"
> timer (cron:0/20 * * * * ?)
> when
> not $event: StateEvent(itemName matches
> "door.*|presence.*|luminosity.*") over window:time( 1m ) from entry-point
> "EventStream"
> then
> System.out.println("Alert: one sensor is not working: " +
> $event.getItemName());
>
> So, do you know how can i know which sensor is not working? must i rewrite
> the rule to achieve this? is this possible?
>
>
> Thanks for your help.
> end
>
>
> _______________________________________________
> 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/20120207/5719e919/attachment.html
More information about the rules-users
mailing list