[rules-users] How to write a rule that fires when it matches against specific facts in working memory.

Bruno Freudensprung bruno.freudensprung at temis.com
Thu Jan 20 08:33:52 EST 2011


Hello,

Maybe could you try the following rule?

rule "Matched Options" 
when
	$o : Option (code == "P1")
	Option (this != $o, code == "P2")
then
	System.out.println ( "Priced using G/S ");
end

Best regards,

Bruno.




groovenarula a écrit :
> Hello,
>
> I have a fact called 'Option' :
>
> public class Option {
> 	private String code;
>
> 	private Item item;
> 	public String getCode() {
> 		return code;
> 	}
> 	public void setCode(String optionCode) {
> 		this.code = optionCode;
> 	}
>
> At any point in time, the working memory can have several Option instances
> with different code values. My rules need to fire specifically when the
> working memory contains a specific set of options. e.g. Rule 1 should fire
> if and only if the working memory contains 2 option instances one with code
> "P1" and the other with "P2" (order should not matter).
>
> I tried to use 'forall' as follows :
>
> rule "Matched Options" 
>    	when
> 		forall (
> 			Option ( code == "P1" || code == "P2" ) 
> 			   )
> 	then
> 		//insert( new IsPriced( i ) );	
> 		System.out.println ( "Priced using G/S ");
> end
>
> However, the rule above never fires. Maybe I should be taking a different
> approach. I'm still learning through how to create rules. So any
> help/suggestions on how to tackle the above will be appreciated.
>
> Thanks
> Gurvinder
>
>   




More information about the rules-users mailing list