开发者

Using drools expert with dynamic decision tables

Here's what I had like to do.

I had like to put "rules" in a database table. This is sort of like the drools xls decision table format except that all the rules will be rows in a table. This way I can开发者_如何学Python modify the rules easily . I need to put this in a table and not an xls because my rules could be frequently changing. Is this possible with drools? Can I build a knowledgebase with rules retrieved from a DB (instead of a DRL or a xls file) and every time rules change can I rebuild the knowledge base from scratch (or maybe just parts of the knowledgebase, essentially update only those rules that's changed..)


It depends on what kind of rules you have in mind. A database-backed approach makes sense if you have lots of rules that have the same structure, and which only vary according to certain 'parameters'. In this case you can write a single generic rule, and use the database to store all of the combinations that apply. For example, suppose you have a rules to calculate shipping rates per country, for an order, e.g.

rule "Shipping rates to France"
when
    $order : Order(country == 'fr')
then
    $order.setShippingRate(10.0);
    update(order);
end

// Similar rules for other countries…

You could replace these rules data from your database where each CountryShippingRate specifies the rate for one country. Then you insert all of the CountryShippingRate rows as fact objects in the rule session, and a single rule, like:

rule "Shipping rates"
when
    $order : Order($country : country)
    CountryShippingRate($rate : rate, country == $country)
then
    $order.setShippingRate($rate);
    update(order);
end

In practice, it turns out that lots of decision table type rules can be rewritten this way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜