It depends on what rules you have in mind. The approach supported by the database makes sense if you have many rules that have the same structure and which depend only on certain “parameters”. In this case, you can write one general rule and use the database to store all applicable combinations. For example, suppose you have rules for calculating country delivery rates for an order, for example,
rule "Shipping rates to France" when $order : Order(country == 'fr') then $order.setShippingRate(10.0); update(order); end // Similar rules for other countries…
You can replace this rule data from your database, where each CountryShippingRate indicates the speed for one country. Then you insert all CountryShippingRate rows as fact objects in the rules session and one rule, for example:
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 many rules such as decision tables can be rewritten in this way.
Peter Hilton
source share