Re: [rules-users] Filtering inside the LHS

2012-02-23 Thread Wolfgang Laun
Using queries doesn't solve the Hezi's problem which is the selection
of an operator based on some property value.

Relying on Java and evel, you can always write an expression such as

eval( $ctxt.state == SContextState.ONE ?
 $ds.sentence.equals( $someSentence ) :
 $ds.sentence.memberOf( $sentenceSet ) )

(Sorry, I did not try to stick to your complex class structures.)

-W


On 23/02/2012, Mark Proctor  wrote:
> On 23/02/2012 03:38, Hezi Stern wrote:
>>
>> Hi All,
>>
>> I am seeking some kind of filtering (if statement) inside the LHS.
>>
>> I have the following example rule (note: $attributeFilteredSentences
>> and $cmdescriptor are defined in the extends rule which is not presented):
>>
>> *rule*" choose message sentence example"extends "
>> attributeFilteredSentences  collection"
>>
>> *when*
>>
>>   SContextState(state == SContextState.ONE)
>>
>> $sentences:   ArrayList()
>>
>> *from**collect*(Sentences.Sentence(
>>
>>
>>descriptor.meanings.meaning == $cmdescriptor.meanings.meaning
>>
>>  )
>> *from*  $attributeFilteredSentences)
>>
>> *then*
>>
>> logger.info("RULE: entered rule:
>> "+drools.getRule().getName());
>>
>> //some logic...
>>
>> *end*
>>
>> **
>>
>> as can be seen I am filtering sentences based on the meanings, and the
>> meaning collection must be identical as in $cmdescriptor (this is the
>> case when SContextState.ONE)
>>
>> Now to my question: I have cases ((this is the case when
>> SContextState.TWO) where I do not need exact validation but rather
>> superset of (for this I have a supersetOf operator implemented)
>>
>> I would like to avoid duplicating  this rule (as I have similar
>> condition in many other rules) and being able to filter once with "=="
>> and once with "supersetOf" depending on the SContextState.
>>
> I have found that query's can be used to provide re-usable rule
> fragments. In the example below I could have inlined the intentory LHS
> in the updateInventory rule, but instead I separated it out into a query
> so that multiple rules can re-use it. There is a small performance
> overhead from using queries, compared to normal patterns, but in most
> cases this is compensated by more maintainable and readable code.
>
> query inventory(Character $char, List $inventory)
>  $char := Character()
>  $inventory := List() from accumulate( Holding( $char, $thing; ),
>collectList( $thing ) )
> end
>
> rule updateInventory salience 5 when
>  SessionCharacter( $char : character, $us : session )
>  inventory( $char, $things; )
> then
>  $us.channels["inventory"].send( $things );
> end
>
>
> Mark
>>
>> Any ideas how to do this?
>>
>> Thanks,
>>
>> Hezi
>>
>>
>>
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Filtering inside the LHS

2012-02-22 Thread Mark Proctor

On 23/02/2012 03:38, Hezi Stern wrote:


Hi All,

I am seeking some kind of filtering (if statement) inside the LHS.

I have the following example rule (note: $attributeFilteredSentences 
and $cmdescriptor are defined in the extends rule which is not presented):


*rule*" choose message sentence example"extends " 
attributeFilteredSentences  collection"


*when*

  SContextState(state == SContextState.ONE)

$sentences:   ArrayList()

*from**collect*(Sentences.Sentence(

  
   descriptor.meanings.meaning == $cmdescriptor.meanings.meaning


 ) 
*from*  $attributeFilteredSentences)


*then*

logger.info("RULE: entered rule: 
"+drools.getRule().getName());


//some logic...

*end*

**

as can be seen I am filtering sentences based on the meanings, and the 
meaning collection must be identical as in $cmdescriptor (this is the 
case when SContextState.ONE)


Now to my question: I have cases ((this is the case when 
SContextState.TWO) where I do not need exact validation but rather 
superset of (for this I have a supersetOf operator implemented)


I would like to avoid duplicating  this rule (as I have similar 
condition in many other rules) and being able to filter once with "==" 
and once with "supersetOf" depending on the SContextState.


I have found that query's can be used to provide re-usable rule 
fragments. In the example below I could have inlined the intentory LHS 
in the updateInventory rule, but instead I separated it out into a query 
so that multiple rules can re-use it. There is a small performance 
overhead from using queries, compared to normal patterns, but in most 
cases this is compensated by more maintainable and readable code.


query inventory(Character $char, List $inventory)
$char := Character()
$inventory := List() from accumulate( Holding( $char, $thing; ),
  collectList( $thing ) )
end

rule updateInventory salience 5 when
SessionCharacter( $char : character, $us : session )
inventory( $char, $things; )
then
$us.channels["inventory"].send( $things );
end


Mark


Any ideas how to do this?

Thanks,

Hezi



___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Filtering inside the LHS

2012-02-22 Thread Hezi Stern
Hi All,

 

I am seeking some kind of filtering (if statement) inside the LHS.

I have the following example rule (note: $attributeFilteredSentences and
$cmdescriptor are defined in the extends rule which is not presented):

 

rule " choose message sentence example" extends " attributeFilteredSentences
collection"

  when

 


  SContextState(state == SContextState.ONE)



$sentences:   ArrayList()

from collect (Sentences.Sentence(

 
descriptor.meanings.meaning == $cmdescriptor.meanings.meaning

 ) from
$attributeFilteredSentences)




  then

logger.info("RULE: entered rule: "+drools.getRule().getName());

 

//some logic.

 

end

 

as can be seen I am filtering sentences based on the meanings, and the
meaning collection must be identical as in $cmdescriptor (this is the case
when SContextState.ONE)

 

Now to my question: I have cases ((this is the case when SContextState.TWO)
where I do not need exact validation but rather superset of (for this I have
a supersetOf operator implemented)

I would like to avoid duplicating  this rule (as I have similar condition in
many other rules) and being able to filter once with "==" and once with
"supersetOf" depending on the SContextState.

 

Any ideas how to do this?

 

Thanks,

Hezi

 

 

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users