[rules-users] [Column(f1=='v1', f2=='v2')] vs [Column(f1= ='v1') Column(f2== 'v2')]

Edson Tirelli tirelli at post.com
Wed Feb 7 14:46:44 EST 2007


 
   Nope. If you have a rule:

rule A
when
    Column(f1=='v1')
    Column(f2=='v2')
then
    // do something
end

    The rule will activate for tuples:

[1, 3]
[1, 4]
[1, 5]
[2, 3]
[2, 4]
[2, 5]
[3, 4]
[3, 5]

    Remember that the implicit conditional element is AND.
    If you write a rule

rule A
when
    Column(f1=='v1') or Column(f2=='v2')
then
    // do something
end

   Then it will activate for tuples:

[1]
[2]
[3]
[4]
[5]

   []s
   Edson

Olenin, Vladimir (MOH) wrote:

>Hi, Edson.
>
>Thanks for the explanation. Just wanted to clarify one thing. If I have a
>set of following Column fact objects and I put then into workspace using the
>'identity' mode (below are only field values the facts are initialized with,
>one per line, each line is a separate Column fact):
>
>1) f1='v1', f2='v1'
>2) f1='v1', f2='v11'
>3) f1='v1', f2='v2'
>4) f1='v2', f2='v2'
>5) f1='v11', f2='v2'
>6) f1='v11', f2='v22
>
>then the condition
>
>Column(f1=='v1')
>Column(f2=='v2')
>
>will select facts exactly 5 facts: 1, 2, 3, 4, 5, but NOT 6, correct?
>
>Won't the condition above then be the same as:
>
>Column(f1=='v1') or Column(f2=='v2') ?
>
>Thanks.
>
>Vlad
>
>PS: any feedback/hints on some other questions I've sent earlier today would
>be very much appreciated as well!
>
>
>-----Original Message-----
>From: rules-users-bounces at lists.jboss.org
>[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
>Sent: 07 February 2007 13:15
>To: Rules Users List
>Subject: Re: [rules-users] [Column(f1=='v1', f2=='v2')] vs [Column(f1=='v1')
>Column(f2== 'v2')]
>
>
>    Vlad,
>
>    The constructions are semantically different. In 3.0.x as default, 
>JBoss Rules will not allow the same fact to match more than one column. 
>So if you write:
>
>Column(f1=='v1')
>
>Column(f2=='v2')
>
>
>    Your rule will only match if there are 2 different objects that each 
>match one of the constraints. While, if you write:
>
>Column(f1=='v1', f2=='v2')
>
>
>   It will require a single object that matches both constraints.
>
>   Also, the optimizations (indexing, hashing, etc) are done on a field 
>constraint basis.
>
>   So, if you have one rule with :
>
> Column(f1=='v1', f2=='ONE_VAL')
>
>
>   And   another rule with:
>
> Column(f1=='v1', f2=='ANOTHER_VAL')
>
>
>   The constraint f1=='v1' will be evaluated only once. Although, to 
>help optimization, you must keep the constraints that repeat over 
>multiple patterns as the first constraints for each collumn, in the same 
>order.
>
>   []s
>   Edson
>
>
>Olenin, Vladimir (MOH) wrote:
>
>  
>
>>Hi,
>>
>>
>>
>>I wonder what is the difference (performance-wise, etc) between these two
>>constructs:
>>
>>
>>
>>Column(f1=='v1', f2=='v2')
>>
>>
>>
>>And
>>
>>
>>
>>Column(f1=='v1')
>>
>>Column(f2=='v2')
>>
>>
>>
>>?
>>
>>
>>
>>Both of them should select the same 'Column' facts (where Column.f1=='v1'
>>    
>>
>&&
>  
>
>>Column.f2='v2'), correct? Is one construct more preferable then another
>>    
>>
>one?
>  
>
>>Does JBossRules hash only the evaluation result of the 'full column' OR
>>individual field constraints as well? From what I understand, only the full
>>'Column' is defined as an (alpha?) node while individual constraints within
>>the node can not be further optimized, correct? 
>>
>>
>>
>>Meaning, if I have another condition somewhere like this:
>>
>>
>>
>>Column(f1=='v1', f2=='ANOTHER_VAL')
>>
>>
>>
>>[f1=='v1'] constraint would have to be reevaluated again, while if I define
>>constraints through two 'separate' columns and the new constraint as
>>
>>
>>
>>Column(f1=='v1)
>>
>>Column(f2=='ANOTHER_VAL')
>>
>>
>>
>>only the new constraint would have to be reevaluated. Do I understand it
>>right?
>>
>>
>>
>>Thanks!
>>
>>
>>
>>Vlad
>>
>>_______________________________________________
>>rules-users mailing list
>>rules-users at lists.jboss.org
>>https://lists.jboss.org/mailman/listinfo/rules-users
>>
>> 
>>
>>    
>>
>
>
>  
>


-- 
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3124-6000
 Mobile: +55 11 9218-4151
 JBoss, a division of Red Hat @ www.jboss.com





More information about the rules-users mailing list