gpt4 book ai didi

drools - 从 drool 文件中触发选择性规则

转载 作者:行者123 更新时间:2023-12-02 07:09:58 26 4
gpt4 key购买 nike

是否可以通过规则名称触发 drool 文件中的规则?我的要求是,我的规则文件将包含所有规则的列表 (S)。但我有一个单独的配置,其中包含要触发的规则名称列表 (A)。注意 (A) 是 (S) 的子集。在运行时,我只想触发名称为 (A) 来自 (S) 的规则。

谢谢。

最佳答案

您可以为此使用 AgendaFilters。

这里是你如何设置它:

StatelessSession session = ruleBase.newStatelessSesssion();

session.setAgendaFilter( new RuleNameMatches("<regexp to your rule name here>") );

这将只允许触发一个具有指定名称的规则。

在您的情况下,您需要编写自己的 AgendaFilter:

public class CustomAgendaFilter extends AgendaFilter{

private final Set<String> ruleNamesThatAreAllowedToFire;

public CustomAgendaFilter(Set<String> ruleNamesThatAreAllowedToFire){
this.ruleNamesThatAreAllowedToFire=ruleNamesThatAreAllowedToFire;
}

boolean accept(Activation activation){
return ruleNamesThatAreAllowedToFire.contains(activation.getRule().getName());
}
}

关于drools - 从 drool 文件中触发选择性规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7021354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com