[rules-users] creating a rule regarding an element of list stored in an object in a list

Wolfgang Laun wolfgang.laun at gmail.com
Sat Apr 13 13:00:11 EDT 2013


A solution for this kind of problem depends very much on the data
model and the way the relations between the various entities are
represented, either by collections in some entity or as facts.

What you have "right now" seems to indicate that you rely very much on
collections representing one direction of relationship (e.g., a
teacher's rosters).

Adding (redundant) information may simplify the task of writing rules.
Also, consider representing the relations by separate facts.

-W

On 12/04/2013, Alex Burman <alexburman at gmail.com> wrote:
> So right now I have this:
>
> $teach1 : Teacher($level : Level, $rosters1 : Rosters)
>
> $roster1 : Roster($subject : Subject) from $rosters1
>
> $teachs : ArrayList () from collect ( Teacher(Level == $level) )
>
> Teacher($rosters2 : Rosters) from $teachs
>
> $rosts : ArrayList() from collect ( $roster2 : Roster(Subject != $subject)
> from $rosters2)
>
> I am trying to make a list of all the rosters for different subjects at the
> same grade level, however I am only getting rosters for 1 teacher at a
> time. I realize this is most likely due to the 2nd to last line but I'm not
> sure how to get around that. Any thoughts are helpful.
>
>
>
>
> On Thu, Apr 11, 2013 at 1:44 PM, Stephen Masters
> <stephen.masters at me.com>wrote:
>
>> Look up "Conditional Element collect" in the manual. That provides
>> example
>> code for getting a list of matching facts.
>>
>> For more complex tasks, there's "accumulate".
>>
>> Steve
>>
>>
>> On 11 Apr 2013, at 17:51, Alex Burman <alexburman at gmail.com> wrote:
>>
>> Continuing with this same example, How can I count the number of times a
>> student has received an A across all the classes?
>>
>> I can get it to trigger each time a student appears in the rosters of 2
>> different teachers and that student has an A in both but I can't figure
>> out
>> how to track it across more then that.
>>
>>
>> On Fri, Apr 5, 2013 at 4:50 AM, Stephen Masters
>> <stephen.masters at me.com>wrote:
>>
>>> Just thought I'd mention that I hadn't replied to this, because it looks
>>> way too much like comp-sci homework. Not sure whether that's the same
>>> reason others haven't replied either. ;)
>>>
>>> A hint though to get you started. You can probably use something like...
>>>
>>> $student: Student(grade != null) from $roster
>>>
>>> … with a few lines before that to pick out the roster in a similar
>>> fashion.
>>>
>>> To understand it, check out the Drools Expert manual for the "from"
>>> operator for working with lists/collections.
>>>
>>> Steve
>>>
>>>
>>> On 3 Apr 2013, at 19:59, burmanator <alexburman at gmail.com> wrote:
>>>
>>> > So the example I am working with is this:
>>> > You have a Teacher object
>>> >     that stores a list of Rosters  objects
>>> >           in each Roster is a list of Students objects
>>> >                each Student has a grade value
>>> >
>>> > How would I go about creating a rule to find all the students that got
>>> As
>>> > for a given Teacher across all her Rosters?
>>> >
>>> >
>>> >
>>> > --
>>> > View this message in context:
>>> http://drools.46999.n3.nabble.com/creating-a-rule-regarding-an-element-of-list-stored-in-an-object-in-a-list-tp4023205.html
>>> > Sent from the Drools: User forum mailing list archive at Nabble.com.
>>> > _______________________________________________
>>> > 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
>>>
>>
>>
>>
>> --
>> Sincerely,
>> Alex Burman
>> cell: 908-672-0198
>> _______________________________________________
>> 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
>>
>
>
>
> --
> Sincerely,
> Alex Burman
> cell: 908-672-0198
>



More information about the rules-users mailing list