简体   繁体   English

使用无状态知识会话在LHS中改变状态

[英]Drools changing state in LHS using Stateless Knowledge session

I am listing my problem here. 我在这里列出我的问题。

  1. Persons can enter or exit a room. 人员可以进入或离开房间。
  2. Person can be a student or a teacher or HOD. 人可以是学生,也可以是教师或HOD。
  3. Students have an attribute called status which can be updated manually as well as automatically. 学生有一个名为status的属性,可以手动更新,也可以自动更新。

These are my events: 这些是我的活动:

  1. People entering the room. 进入房间的人。
  2. Attribute status updated for each student. 为每个学生更新属性状态。

These are my rules. 这些是我的规则。

  1. If a person entering a room is Teacher then print teacher entered. 如果进入房间的人是教师,则输入打印教师。
  2. If the number of persons entering the room has gone beyond 30 alert me. 如果进入房间的人数超过30,请提醒我。
  3. If a student has attended more than 20 hours of the class then update status to complete. 如果学生上课时间超过20小时,则更新状态以完成。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM