使用 drools Expert 和动态决策表

发布于 2024-09-05 10:52:24 字数 230 浏览 7 评论 0原文

这就是我想做的事情。

我想将“规则”放入数据库表中。这有点像 drools xls 决策表格式,只不过所有规则都是表中的行。这样我就可以轻松修改规则了。我需要将其放入表格而不是 xls 中,因为我的规则可能会经常更改。流口水可以做到这一点吗?我可以使用从数据库(而不是 DRL 或 xls 文件)检索的规则来构建知识库吗?每次规则更改时,我可以从头开始重建知识库(或者可能只是知识库的一部分,本质上只更新那些已更改的规则) ..)

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 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..)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2024-09-12 10:52:24

这取决于您心中的规则。如果您有许多具有相同结构且仅根据某些“参数”而变化的规则,则数据库支持的方法是有意义的。在这种情况下,您可以编写单个通用规则,并使用数据库来存储所有适用的组合。例如,假设您有一个规则来计算某个订单的每个国家/地区的运费,例如,

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

// Similar rules for other countries…

您可以替换数据库中的这些规则数据,其中每个 CountryShippingRate 指定一个国家/地区的费率。然后,将所有 CountryShippingRate 行作为事实对象插入规则会话中,并插入一条规则,例如:

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

在实践中,事实证明,可以通过这种方式重写许多决策表类型规则。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文