[rules-users] Managing Collection Facts

Yuri de Wit ydewit at gmail.com
Tue Jun 19 22:23:08 EDT 2007


Hi,

I have to create a set of rules that group facts together based on a
dynamic criteria X basd on fact data. So I created a rule to create a
first collection for the criteria X when no collection exist. I
created a second rule to add a fact to an existing collection, but I
cant get my head around how to create a rule that takes facts out of
the collection if a fact is updated and no longer satisfies X. Note
that the criteria X is a combination of 7-10 field equality.

rule
  when
     f:Fact1(var1: a, var2:b)
     not FactCollection( a == var1, b == var2, fs:facts ->
(fs.contains(f) == true) )
  then
    ...
    assert(new FactCollection(f));
end

rule
   when
     f:Fact1(var1: a)
     c:FactCollection( a == var1 )
   then
     c.add(f);
     modify(c);
     modify(f);
end

rule
   when
      f:Fact1(id:id, type=UPDATE, var1: a)
      f2:Fact1(id == id, a == var1, b == var2)
      fs:FactCollection( not(a == var1, b == var2), fs:facts ->
(fs.contains(f2) == true)
   then
      fs.remove(f2);
      modify(fs);
end

Since I dont want to create a rule for each combination of a != var1,
b == var2, a == var1, b != var2 (I have 7-10 individual conditions),
but I do want to check whether the collection contains f2 what else to
do? any ideas?



More information about the rules-users mailing list