[rules-users] facts hierarchy

Giovanni Motta mottagio at gmail.com
Sat May 8 04:53:16 EDT 2010


Hi Esteban,
thank you for the response.
You are assuming i have a property named 'b' that returns fact child 'B'.
This is not so common in tree structures, also, in my sample i forgot to say
that element 'B' might not necessariliy be a direct child of 'A'. Generally
speking, i would like to refer to a descendant node of 'A', this is why i
mentioned 'descendant-of' in my sample.
Also, my sample was misleading because of the 'id' attribute, it should have
been like this, supposing to map the tag name with a 'name' property:

rule "A requires B"
when
$fact1: NodeFact(name == "A", selected == true)
$fact2: NodeFact(name == "B", selected == false, this DESCENDANT-OF $fact1 )
then
$fact2.setSelected(true);
end

The rule could also be reversed like this, holding to the same concept:
rule "A requires B"
when
$fact2: NodeFact(name == "B", selected == false )
$fact1: NodeFact(name == "A", selected == true, this ANCESTOR-OF $fact2)
then
$fact2.setSelected(true);
end

In this case, if the tree is little 'deep' (has few levels), it should be
speedier, because it is supposed that the list of ancestors nodes  should be
shorter than the list of the descendant nodes.
I'm looking at a best practice to deal with tree structures in drools, this
is actually my main concern.
Best regards

2010/5/7 Esteban Aliverti <esteban.aliverti at gmail.com>

> Ups sorry! I forgot to remove your part from the rule
>
> It should be:
>
> rule "A requires B"
> when
> $fact1: NodeFact(id == "A", selected == true, $b: b)
>  $fact2: NodeFact(this == $b, selected == false)
> then
> $fact2.setSelected(true);
> end
>
> Best
>
> On Fri, May 7, 2010 at 2:14 PM, Esteban Aliverti <
> esteban.aliverti at gmail.com> wrote:
>
>> Hi,
>>
>> Is this what you are looking for?
>>
>> rule "A requires B"
>>  when
>> $fact1: NodeFact(id == "A", selected == true, $b: b)
>> $fact2: NodeFact(this == $b, selected == false,  this DESCENDANT-OF
>> $fact1)
>>  then
>> $fact2.setSelected(true);
>> end
>>
>> Best,
>>
>> 2010/5/7 Giovanni Motta <mottagio at gmail.com>
>>
>>> Hi all, i have a question concerning facts hierarchy, i'm looking for
>>> some hint as i suppose the same problem could have been faced by someone on
>>> the list.
>>>
>>> I try to eplain with an example:
>>>
>>> - Suppose to have a tree of facts, each object representing an UI widget.
>>>    <root>
>>>     <A id="1">
>>>           <B />
>>>     </A>
>>>     <A id="2">
>>>           <B />
>>>     </A>
>>>   </root>
>>>
>>> - The individual elements A(1), B, A(2), B are mapped to facts, that are
>>> inserted in a KnowledgeStatefulSession
>>> - A rule exists that states that when an object A is selected, the B
>>> object is automatically selected
>>> - An event occurs that causes selection of node A(1)
>>>
>>> The expected result is, obviously, that only the B element that is
>>> descendant of A(1) must be automatically selected
>>>
>>> I'm trying a way to express the 'descendant' relationship in LHS
>>> construct.
>>> The rule will look like:
>>>
>>> rule "A requires B"
>>> when
>>>  $fact1: NodeFact(id == "A", selected == true)
>>> $fact2: NodeFact(id == "B", selected == false,  this DESCENDANT-OF
>>> $fact1)
>>>  then
>>> $fact2.setSelected(true);
>>> end
>>>
>>>
>>> What is, in your opinion, the best way to handle this situation? What
>>> should replace the fake "DESCENDANT-OF" match?
>>> Do i need to use a function that returns the list of descendant nodes of
>>> $fact1 and then match $fact2 against that?
>>> Will this be fast when dealing with large trees?
>>>
>>> Any suggestion will be appreciated, thank you.
>>> Giovanni
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>>
>> --
>> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>>
>> Esteban Aliverti
>>
>
>
>
> --
> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>
> Esteban Aliverti
>
> _______________________________________________
> 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/20100508/cb9724be/attachment.html 


More information about the rules-users mailing list