Suppressing reciprocal matches

5 messages Options
Embed this post
Permalink
D Brock

Suppressing reciprocal matches

Reply Threaded More More options
Print post
Permalink
I have defined the following rule to detect when duplicate objects (in this example, Widgets) exist.  This always produces two matches, and therefore two messages.  I understand why this occurs, but I would like for only one message to be reported.  I cannot retract one of the widgets after a match b/c all are needed for additional rules matching.  Is the a conventional way for accomplishing the elimination of the reciprocal match?

rule "Do not allow duplicate widgets"
        when
                $w : Widget( $name : name )
                Widget( this != $w, name == $name )
        then
                System.out.println( "Duplicate widgets found with name =  " + $name );
end
Mark Proctor

Re: Suppressing reciprocal matches

Reply Threaded More More options
Print post
Permalink
D Brock wrote:

> I have defined the following rule to detect when duplicate objects (in this
> example, Widgets) exist.  This always produces two matches, and therefore
> two messages.  I understand why this occurs, but I would like for only one
> message to be reported.  I cannot retract one of the widgets after a match
> b/c all are needed for additional rules matching.  Is the a conventional way
> for accomplishing the elimination of the reciprocal match?
>
> rule "Do not allow duplicate widgets"
> when
> $w : Widget( $name : name )
> Widget( this != $w, name == $name )
> then
> System.out.println( "Duplicate widgets found with name =  " + $name );
> end
>  
We are looking into a new conditional element that can achieve this. The
idea is when you use this CE, it ensures only a single permutation will
be propagated. In the meantime you can probably try something like:

$w : Widget( $name : name )
     Widget( this != $w, hashCode < $w.hashCode, name == $name )




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Edson Tirelli-4

Re: Suppressing reciprocal matches

Reply Threaded More More options
Print post
Permalink

   Yap, that or, in case you want to do it automatically for ALL your rules, you could use:

KnowledgeBaseConfiguration conf = ...
conf.setOption( RemoveIdentitiesOption.YES );

   Javadocs:

http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/apidocs/org/drools/KnowledgeBaseConfiguration.html
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/apidocs/org/drools/conf/RemoveIdentitiesOption.html

   Edson

2009/11/6 Mark Proctor <[hidden email]>
D Brock wrote:
> I have defined the following rule to detect when duplicate objects (in this
> example, Widgets) exist.  This always produces two matches, and therefore
> two messages.  I understand why this occurs, but I would like for only one
> message to be reported.  I cannot retract one of the widgets after a match
> b/c all are needed for additional rules matching.  Is the a conventional way
> for accomplishing the elimination of the reciprocal match?
>
> rule "Do not allow duplicate widgets"
>       when
>               $w : Widget( $name : name )
>               Widget( this != $w, name == $name )
>       then
>               System.out.println( "Duplicate widgets found with name =  " + $name );
> end
>
We are looking into a new conditional element that can achieve this. The
idea is when you use this CE, it ensures only a single permutation will
be propagated. In the meantime you can probably try something like:

$w : Widget( $name : name )
    Widget( this != $w, hashCode < $w.hashCode, name == $name )




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
D Brock

Re: Suppressing reciprocal matches

Reply Threaded More More options
Print post
Permalink
In reply to this post by Mark Proctor
Thanks Mark, sounds good.  And the hashCode trick works.  Wow, I would have never thought of that!

Mark Proctor wrote:
D Brock wrote:
> I have defined the following rule to detect when duplicate objects (in this
> example, Widgets) exist.  This always produces two matches, and therefore
> two messages.  I understand why this occurs, but I would like for only one
> message to be reported.  I cannot retract one of the widgets after a match
> b/c all are needed for additional rules matching.  Is the a conventional way
> for accomplishing the elimination of the reciprocal match?
>
> rule "Do not allow duplicate widgets"
> when
> $w : Widget( $name : name )
> Widget( this != $w, name == $name )
> then
> System.out.println( "Duplicate widgets found with name =  " + $name );
> end
>  
We are looking into a new conditional element that can achieve this. The
idea is when you use this CE, it ensures only a single permutation will
be propagated. In the meantime you can probably try something like:

$w : Widget( $name : name )
     Widget( this != $w, hashCode < $w.hashCode, name == $name )




_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
Swindells, Thomas

Re: Suppressing reciprocal matches

Reply Threaded More More options
Print post
Permalink
There is a bug here though if the hashcodes are equals.

You need to make it
 $w : Widget( $name : name )
     Widget( this != $w, hashCode <= $w.hashCode, name == $name )

And live with the fact there is a chance that the rule does fire twice - which is probably a better scenario that it failing to fire at all.  Be particularly careful if your widget overrides the equals() method as it should also override the hashcode operator to make it the case that if a.equals(b) then a.hashcode()==b.hashcode().

Thomas

> -----Original Message-----
> From: [hidden email] [mailto:rules-users-
> [hidden email]] On Behalf Of D Brock
> Sent: 07 November 2009 16:04
> To: [hidden email]
> Subject: Re: [rules-users] Suppressing reciprocal matches
>
>
> Thanks Mark, sounds good.  And the hashCode trick works.  Wow, I would
> have
> never thought of that!
>
>
> Mark Proctor wrote:
> >
> > D Brock wrote:
> >> I have defined the following rule to detect when duplicate objects
> (in
> >> this
> >> example, Widgets) exist.  This always produces two matches, and
> therefore
> >> two messages.  I understand why this occurs, but I would like for
> only
> >> one
> >> message to be reported.  I cannot retract one of the widgets after a
> >> match
> >> b/c all are needed for additional rules matching.  Is the a
> conventional
> >> way
> >> for accomplishing the elimination of the reciprocal match?
> >>
> >> rule "Do not allow duplicate widgets"
> >> when
> >> $w : Widget( $name : name )
> >> Widget( this != $w, name == $name )
> >> then
> >> System.out.println( "Duplicate widgets found with name =  "
> + $name );
> >> end
> >>
> > We are looking into a new conditional element that can achieve this.
> The
> > idea is when you use this CE, it ensures only a single permutation
> will
> > be propagated. In the meantime you can probably try something like:
> >
> > $w : Widget( $name : name )
> >      Widget( this != $w, hashCode < $w.hashCode, name == $name )
> >
> >
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context: http://old.nabble.com/Suppressing-
> reciprocal-matches-tp26230834p26241896.html
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users

**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the [hidden email] and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users