[英]Drools changing state in LHS using Stateless Knowledge session
I am listing my problem here. 我在这里列出我的问题。
These are my events: 这些是我的活动:
These are my rules. 这些是我的规则。
Now I want 1 and 3 combined together. 现在我希望将1和3组合在一起。
like: 4. Alert the Teacher if a student who has attribute status complete enters the room. 如:4。如果具有完成属性状态的学生进入房间,则提醒教师。
Now as I told earlier both events come separately. 现在正如我之前所说的那样,两个事件分别来了 So handling it in 2 different rules was easier. 因此,在2个不同的规则中处理它更容易。 But when I want to create a rule which is a combination of 1 and 3 as in rule 4 then I have to verify if a person enters a room is a student and if he has attribute "complete". 但是当我想创建一个规则,它是规则4中的1和3的组合,那么我必须验证一个人进入一个房间是否是一个学生,如果他的属性“完整”。
But, loading the status attribute even before validating if he is a student, sounds bad to me. 但是,即使在验证他是否是学生之前加载状态属性,对我来说听起来也不好。 So, I want to call a method for loading the attribute only if 所以,我想调用一个只在加载属性的方法
"a person is a student and there is a rule trying to load the attribute status". “一个人是学生,并且有一条规则试图加载属性状态”。
I am planning to do it by a method call in LHS, which is not straightforward. 我打算通过LHS中的方法调用来完成它,这不是直截了当的。
Is there any other way, I could handle this? 还有其他方法,我可以处理吗?
Having small rules identifying specific situation in most of the times is better than having complex rules trying to identify mixed situations. 在大多数时间内制定识别特定情况的小规则比使用复杂规则来识别混合情况要好。 What is not clear to me is whether your want to replace rule 3 with rule 4 or not. 我不清楚的是你是否想用规则4取代规则3。 I would leave rule 3 and create rule 4 as follow: 我将离开规则3并创建规则4如下:
when
PersonEnteringRoom($p: person, $r: room, person.type == "Student", person.status == "Complete") // status was set by rule 3.
Room(this == $r, $t: currentTeacher != null) //the relation could be stablished by rule 1
then
Notifier.notify($t, "The student has completed the course", $p);
end
Of course, whether this rule works for you or not depends in other factors like your execution cycle. 当然,此规则是否适合您取决于其他因素,如执行周期。
Hope it helps, 希望能帮助到你,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.