rule-engine - RuleBook 返回空结果
问题描述
我正在使用规则书来创建规则链,如下所示:
RuleBookBuilder.create()
.withResultType(Boolean.class)
.addRule(
RuleBuilder.create()
.withFactType(Double.class)
.withResultType(Boolean.class)
.when(facts -> facts.get("amount_gt").getValue() > new Double(600))
.then((facts, result) -> {
result.setValue(true);
System.out.println(result.getValue()); //1st print statement
})
.addRule()
....
.build())
NameValueReferableMap facts = new FactMap();
facts.setValue("amount_gt", new Double(700));
rule.run(facts);
System.out.println(rule.getResult()); //2nd print statement
第一个 print 语句打印 true (例外),但第二个语句给出 Optional.empty 有人能告诉我有什么问题吗?
解决方案
您似乎将规则和您未显示的外部规则的返回联系起来。如果您尝试访问内部规则的返回值,那么您需要类似地链接 get() 调用。
我会尝试“解开”规则,看看会产生什么。
推荐阅读
- android - VideoView 内存泄漏?
- jenkins - Jenkins SCM 轮询未轮询正确的分支
- node.js - 使用 nodejs 将聊天机器人从自定义网站切换到 Zendesk 消息
- node.js - 如何覆盖默认环回模型 API 路径
- apache-kafka - Spring KafkaEmbedded - 消费消息的问题
- vba - 您可以中断 vba 代码以进行工作表选择吗?
- javascript - 无法在动态添加的元素上显示 mCustomScrollBar
- r - 从 geom_point 和 scale_fill_gradient 向图例添加一个点
- javascript - ArcGis 4.8 Javascript:地图状态边界上的悬停效果
- mysql - 从 mysql 查询中创建列表