gpt4 book ai didi

java - drools - 具有多个条件的数组列表访问

转载 作者:太空宇宙 更新时间:2023-11-04 12:58:32 24 4
gpt4 key购买 nike

我有一个对象 A,其中包含对象 B 的列表。

Class A{
List<B> bList;
}

Class B{
String code;//Values QT1,QT2.....QT5
Boolean answer;
}

B 就像一个问卷对象。 A 保留所有问卷,总会有 5 个问题(将来可能会添加)QT1 到 QT5,答案为 true、false 或 null。当任何 QTx 答案为 null 或 QT1、QT2 为 true 时,我需要触发逻辑。我已经实现如下,但它不起作用。这有什么问题吗?

rule "validateQuestions"
ruleflow-group "validate"
dialect "mvel"
when
$a : A(bList.empty == false)
B(code == "QT1",answer == true) from $a.bList
B(code == "QT2",answer == true) from $a.bList
B(code == "QT3",answer == null) from $a.bList
B(code == "QT4",answer == null) from $a.bList
B(code == "QT5",answer == null) from $a.bList
then
//("Logic Here")

总会有 5 个 QTx,这可以是 true false 或 null 答案的任意组合。

最佳答案

rule "validateQuestions"
when
$a: A()
B( code in ("QT1", "QT2") && answer == true ||
code in ("QT3", "QT4", "QT5") && answer == null ) from $a.bList
then

您不需要测试 List.empty。

请务必阅读有关规则的 when 部分中“模式”语义的文档 - 我不会在这里重复所有内容(与事实绑定(bind)、隐含连词……)。另外,请检查有关约束运算符(&&、||、in、not in、...)的文档。

关于java - drools - 具有多个条件的数组列表访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35145415/

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