首页 > 解决方案 > 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 有人能告诉我有什么问题吗?

标签: rule-engine

解决方案


您似乎将规则和您未显示的外部规则的返回联系起来。如果您尝试访问内部规则的返回值,那么您需要类似地链接 get() 调用。

我会尝试“解开”规则,看看会产生什么。


推荐阅读