Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserted fact not available for next rule #12

Open
psantann opened this issue Feb 21, 2015 · 1 comment
Open

Inserted fact not available for next rule #12

psantann opened this issue Feb 21, 2015 · 1 comment

Comments

@psantann
Copy link

I have a sequence of rules as below. Even though I'm inserting a new AlarmFact and I can see it was created with the proper name, the next rule "We got a new alarm" is still executed so I end up with two AlarmFacts one with count=2 and another with count=1

rule "Process an incoming alarm":
agenda-group "process alarm 1"
when:
$alarm := Alarm()
then:
log("We got an alarm with name {0}".format($alarm.name))
attribute current_alarm_name = $alarm.name
forget $alarm

rule "We got an alarm already existent":
agenda-group "process alarm 2"
when:
$alarm_fact := AlarmFact( name == current_alarm_name)
then:
log("We got another alarm with name {0}".format($alarm_fact.name))
modify $alarm_fact:
count = $alarm_fact.count + 1

rule "We got a new alarm":
agenda-group "process alarm 3"
when:
not exists $alarm_fact := AlarmFact( name == current_alarm_name)
then:
log("We got a new alarm with name {0}".format(current_alarm_name))
insert AlarmFact(current_alarm_name)

@psantann
Copy link
Author

The problem seems to be that a "not" before an exists does not apply to the whole expression:
DEBUG:intellect:intellect.Node.When :: Filter using the following list comprehension: matches = [fact for fact in policy.intellect.knowledge if reflection.is_instance(fact, klazz) and not (fact.name == current_alarm_name)]
So if I have another AlarmFact with the attribute name set to something different, it will evaluate the when clause to True and add one more instance of AlarmFact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant