Another way to obtain what you are looking for could be this:
rule "Remove all but one"
when
$f1: Fact(id == "aaa")
$f2: Fact(id == "aaa", this != $f1)
then
retract($f2);
end
The difference with this approach is the number of activations you will
have.
Best Regards,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
- Blog @
http://ilesteban.wordpress.com
On Fri, Nov 30, 2012 at 10:06 AM, Wolfgang Laun <wolfgang.laun(a)gmail.com>wrote:
It seems you are using dialect "mvel"? This doesn't
work
in 5.2.0, 5.3.0 and 5.4.0. (I haven't tried 5.5)
Use dialect java.
-W
On 30/11/2012, Martin Minka <martin.minka(a)gmail.com> wrote:
> I was using ArrayList before and I don't think this is the real problem.
> collect() will return object compatible with List interface so it is
valid
> to use size() and get() methods on $removeUs.
> I have helper method myhelper.log() with accepts any object and *
> myhelper.log($removeUs.get(i))* works for me, unfortunately
> *retract($removeUs.get(i))
> *doesn't work with error:
>
> Error: unable to resolve method using strict-mode:
> org.drools.spi.KnowledgeHelper.drools()] [Near : {...
> drools.retract($removeUs ....}]
>
> It looks like it is not even compiled.
>
> 2012/11/30 Wolfgang Laun <wolfgang.laun(a)gmail.com>
>
>> On 30/11/2012, Martin Minka <martin.minka(a)gmail.com> wrote:
>> > Thank you for the tip. What solution would you suggest to solve my
>> problem
>> > ?
>>
>> Look into the javadoc of java.util to find any class implementing List
>> :-)
>> -W
>>
>> >
>> > Martin
>> >
>> >
>> > 2012/11/30 Wolfgang Laun <wolfgang.laun(a)gmail.com>
>> >
>> >> You cannot use an interfact (List) to instantiate an object, which
>> >> is happening due to the collect.
>> >> --W
>> >>
>> >> On 30/11/2012, Martin Minka <martin.minka(a)gmail.com> wrote:
>> >> > I want to keep only 1 fact with id=="aaaa". But this is
not
working:
>> >> >
>> >> > rule "leave only one"
>> >> > when
>> >> > $removeUs : java.util.List(size>1)
>> >> > from collect(Fact(id=="aaaa")
>> >> > then
>> >> > size = $removeUs.size();
>> >> > for (int i=1; i < size; i++) {
>> >> > retract($removeUs.get(i));
>> >> > }
>> >> > end
>> >> >
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> rules-users(a)lists.jboss.org
>> >>
https://lists.jboss.org/mailman/listinfo/rules-users
>> >>
>> >
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users