[rules-users] Delimited Number groups filtering ?

Maxim Veksler maxim.veksler at gmail.com
Mon Jan 5 02:55:40 EST 2009


Obviously I can.
Thank you very much David for you motivation to help.


Here is the relevant set of rules as it's looks in My Drools3 .drl file:
(Please see comments after the drl).

"""
rule "4" // Campaign Age Range Groups
        no-loop

    when
        $f : FilteringStateConnector(connectorIndex == 4,
            $campaignId : campaignId, $subscriberId : subscriberId)

        eval ($f.getCampaign().getAgeRangeGroups().size() > 0)

        $subscriber : DynaSubscriber(id == $subscriberId,
            age != null,
            $subscriberAge : age
        )
        eval(com.ml.common.utils.BooleanLogging.trace(log,  "common.drl R:4
**** DynaSubscriber()  " + $subscriber))

        // Locate age group(s) subscriber is categorized within.
        $ageGroup : AgeGroup(lowValue <= $subscriberAge, highValue >=
$subscriberAge,
            $ageGroupCode : code
        )
        eval(com.ml.common.utils.BooleanLogging.trace(log,  "common.drl R:4
******** AgeGroup()  " + $ageGroup))

        // Check if campaign contains this AgeRange Group.
        DynaCampaign(
            code == $campaignId,
            ageRangeGroups contains $ageGroupCode
        )
        eval(com.ml.common.utils.BooleanLogging.trace(log,  "common.drl R:4
AgeGroup verified for Subscriber: " + $subscriberId + " at Campaign: " +
$campaignId))

    then
        $f.setPassedRuleRecord("4");

        $f.setConnectorIndex(500);
        modify($f);
end

rule "[XOR NO COUNTING RULE] 4" // Campaign AgeGroup
    when
        $f : FilteringStateConnector(connectorIndex == 4,
            $campaignId : campaignId, $subscriberId : subscriberId)

        eval ($f.getCampaign().getAgeRangeGroups().size() == 0)

        eval(com.ml.common.utils.BooleanLogging.trace(log,  "common.drl R:4
AgeGroup NOT CHECKED for Subscriber: " + $subscriberId + " at Campaign: " +
$campaignId))

    then
        $f.setPassedRuleRecord("4");

        $f.setConnectorIndex(500);
        modify($f);
end
"""

What I'm trying to do with these 2 rules is check if I need to verify age
ranges for subscriber, if so [rule "4"] is firing, I already know the
campaign I'm checking so I would like to first locate it, then fetch it's
ageRangeGroups and only then check of each of the groups if it matches by
it's ranges to the subscriber age range - 1 match is enough to stop the
search.

What I'm doing now is first location all the AgeGroup objects that match the
subscriber and then check (for each) of the groups is it matches the
campaign collection.

Please again note that I'm using Drools 3, we're considering here Drools4
but for now It's hard core 3.


Thank you,
Maxim.

On Wed, Dec 31, 2008 at 7:05 PM, David Sinclair <
dsinclair at chariotsolutions.com> wrote:

> I'm not quite sure if I understand your question. Could you write out the
> rule(even pseudo-code if necessary), or the something as to try and clarify
> what you are trying doing?
>
> On Wed, Dec 31, 2008 at 11:38 AM, Maxim Veksler <maxim.veksler at gmail.com>wrote:
>
>> Hello Again David / List,
>>
>>
>> I should have probably mentioned that I'm working with Drools 3, I'm not
>> sure how or "if" this can be implemented in Drools 3 syntax. I've tried to
>> search Drools 3 documentation and googled for this.
>>
>> Currently I'm using contains with first finds the age groups then follows
>> to find the matching Campaing but as I already know what campaign I'm
>> checking and my intention is to check if this campaign can accept this age
>> group I would like to reverese the search order...
>>
>> Ideas are very welcome.
>>
>>
>>
>> Happy new year everyone !
>>
>>
>>
>>
>> On Sun, Dec 21, 2008 at 10:20 PM, David Sinclair <
>> dsinclair at chariotsolutions.com> wrote:
>>
>>> u almost had it. This should do it.
>>>
>>> Subscriber($age : age)
>>> Campaign($campaignAgeRangs : listOfAgeRangeCodes)
>>>  AgeRange(minAge <= $age, max >= $age, code memberOf $campaignAgeRangs)
>>>
>>> As far as performance, i would think the former would be faster. This one
>>> will look at all campaigns regardless if they have an AgeRange that matches.
>>> The former just looks for an AgeRange, then joins back to the Campaign.
>>>
>>> dave
>>>
>>>
>>> On Sun, Dec 21, 2008 at 2:18 PM, Maxim Veksler <maxim.veksler at gmail.com>wrote:
>>>
>>>> Thank you very much for the fast and accurate reply David,
>>>>
>>>>
>>>> Is it also possible to use the opposite positioning?, something like:
>>>>
>>>> Subscriber($age : age)
>>>> Campaign($campaignAgeRangs : listOfAgeRangeCodes)
>>>> AgeRange(minAge <= $age, max >= $age, $campaignAgeRangs contains code)
>>>>
>>>>
>>>> Please don't try the above as this tries to create a field extractor for
>>>> $campaignAgeRangs on the AgeRange object which fails for obvious reasons..
>>>>
>>>> I would like to to filter first by Subscriber, then by Campaign and last
>>>> by age range. This is obviously a simplification of the actual filtering
>>>> rules.
>>>>
>>>>
>>>>
>>>> On Sun, Dec 21, 2008 at 7:28 PM, David Sinclair <
>>>> dsinclair at chariotsolutions.com> wrote:
>>>>
>>>>> Subscriber($age : age)
>>>>> AgeRange(minAge <= $age, max >= $age, $code : code)
>>>>> Campaign(listOfAgeRangeCodes contains $code)
>>>>>
>>>>> On Sun, Dec 21, 2008 at 12:17 PM, Maxim Veksler <
>>>>> maxim.veksler at gmail.com> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>>
>>>>>> The dataModel is as following:
>>>>>>
>>>>>> class AgeRange() {
>>>>>> Integer code;
>>>>>> int minAge;
>>>>>> int maxAge;
>>>>>> }
>>>>>>
>>>>>> Campaign() {
>>>>>> List<Integer> listOfAgeRangeCodes;
>>>>>> }
>>>>>>
>>>>>> Subscriber() {
>>>>>> int age;
>>>>>> }
>>>>>>
>>>>>> AgeRange()'s and Campaign()'s are pre-populated into the WM.
>>>>>> Subscriber() is asserted right before fireAllRules is called.
>>>>>>
>>>>>> I need a rule that would allow me to check if Subscriber() is within
>>>>>> one of the defined on the Campaign() AgeRange()'s.
>>>>>>
>>>>>> What would be the most efficient way to enforce this constraint?
>>>>>> The other possibility I see is to store the list of AgeRange()'s in
>>>>>> each Campaign() and then use eval() to iterate over the list...
>>>>>>
>>>>>>
>>>>>> Advice and ideas are appreciated.
>>>>>>
>>>>>>
>>>>>> Thank you,
>>>>>> Maxim.
>>>>>> --
>>>>>> Cheers,
>>>>>> Maxim Veksler
>>>>>>
>>>>>> "Free as in Freedom" - Do u GNU ?
>>>>>>
>>>>>> _______________________________________________
>>>>>> rules-users mailing list
>>>>>> rules-users at lists.jboss.org
>>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> rules-users mailing list
>>>>> rules-users at lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Cheers,
>>>> Maxim Veksler
>>>>
>>>> "Free as in Freedom" - Do u GNU ?
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>>
>> --
>> Cheers,
>> Maxim Veksler
>>
>> "Free as in Freedom" - Do u GNU ?
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090105/c1915c27/attachment.html 


More information about the rules-users mailing list