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 <[email protected]
> 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 <[email protected]>
>
>> 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
>> [email protected]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>
> Esteban Aliverti
>



-- 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

Reply via email to