[rules-users] Comparing names
Wolfgang Laun
wolfgang.laun at gmail.com
Thu May 14 04:22:38 EDT 2009
Assuming that your facts are structured as the indentation suggests, I would
solve this using a technique you could call "virtual field". So, if a fact
object has fields
String title
List<PropGroup> pgList
and a PropGroup has fields
String name
List<String> pList
I would not try to get at the embedded data from the objects contained
within List<PropGroup>. Rather, I'd add a couple of getters to your Fact
class, each of which would return a Set<String> computed from the contained
List<PropGroup>. Then the rule simply becomes
rule "check-same"
when
$p1 : Fact( $t1 : title, $g1 : groupNames, $p1 : propNames )
$p2 : Fact( this != $p1, $t2 : title, ( groupNames != $g1 ||
propNames != $p1 ) )
then
System.out.println( "mismatch " + $t1 + " and " + $t2 );
end
Notice that this won't find the odd-man-out; it will fire twice for each
unequal pair.
-W
2009/5/14 Ian Spence <ianspence at gmail.com>
> Hello all,
>
> I am new to Drools…
>
>
>
> I have a scenario
>
>
>
> Each fact object will have the structure:
>
>
>
> Title
>
> Proprietor Group
>
> Proprietor Name
>
>
>
> E.g.
>
> 2100-100
>
> J2 ½ share
>
> SMITH, JOHN
>
> JONES, FRED
>
> T ½ share
>
> BROWN, CHARLIE
>
> 2100-101
>
> J2 ½ share
>
> BROWN, CHARLIE
>
> JONES, FRED
>
> T ½ share
>
> SMITH, JOHN
>
> 2100-102
>
> T ½ share
>
> BROWN, CHARLIE
>
> J2 ½ share
>
> JONES, FRED
>
> SMITH, JOHN
>
>
>
> The group names and the proprietor names must be the same across each
> Title. The scenario above is a valid case. A failed case would result for
> Title 2100-100 if we add an extra Proprietor name e.g. WHITE, MARY.
>
>
>
> I anticipate having one rule to cater for this. I am hedging towards the
> ‘collect’ operator but cannot get a clear picture on how to implement it.
>
>
> --
> Regards,
> Ian Spence
>
>
>
> _______________________________________________
> 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/20090514/15d322e3/attachment.html
More information about the rules-users
mailing list