Well, Hopefully my answers are right, since I'm new to drools as well... But I'll give it my best shot.

On 10/31/06, Charles Chan < [EMAIL PROTECTED]> wrote:
HI, I am new to Drools (and rule engine in general). I was trying to
write a very simple rule but was stuck. I hope someone here can help
me with my questions:

1. How do I write a condition such that it is a comparison between two
(or more) columns of a fact? For example,

rule "BuyWhenMarketPriceAndVolumeMatchesRule"
        when
                offer : StockOffer( price >= simpleMovingAverage )
        then
                offer.setAction(StockOffer.Action.ACTION_BUY );
end

where price and simpleMovingAverage are both attributes of the
StockOffer object.

  I'd say what you've written above is fine, as a comparison. If you need to make multiple comparisons then use a ',' in between them.

        offer: StockOffer(price >= simpleMovingAverage, price<=someMaxValue)

  Assuming that is what you asked in the first place. If its not, then I guess I'm not clear on what you need.

 

2. How do I compare between a BigDecimal and a literal numeral? For example,

rule "BuyWhenMarketPriceAndVolumeMatchesRule"
        when
                offer : StockOffer( price >= 90 )
        then
                offer.setAction(StockOffer.Action.ACTION_BUY);
end


  Not too sure about this one.
 

where price is a java.math.BigDecimal.

3. How do I "pass" variables into the working memory so that it can be
used for rule conditions? For example:

rule "BuyWhenMarketPriceAndVolumeMatchesRule"
        when
                offer : StockOffer( price >= $someVariableSetInWorkingMemory )
        then
                offer.setAction(StockOffer.Action.ACTION_BUY);
end

where $someVariableSetInWorkingMemory is a variable passed into the
working memory.


  You can use the workingmemory.setGlobal () function to pass values from the main program into your working memory.


Please let me know if some of my questions doesn't make sense in a
rule engine...

Thanks
Charles




--
http://del.icio.us/chancharles

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Ramesh

--
http://www.rameshbhaskar.com

Reply via email to