流口水从对象属性收集列表 [英] Drools collect list from object property

查看:92
本文介绍了流口水从对象属性收集列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个学生,有课程清单。
我也有一个讲座,我需要检查学生课程列表和他访问的讲座课程列表是否相同

I have a student, who have list of courses. Also I have a lectures and I need to check that student courses list and list of courses of lectures that he visits are same

我增加了大小写规则,当学生参观讲座时,他没有在课程列表中:

I added rule for case, when student visits lecture, that he doesn't have in courses list:

    when
        $student:Student ($courses:courses) 
        LectureAssignment(student == $student, course not memberOf $courses)
    then
        scoreHolder.addHardConstraintMatch(kcontext, -1);

但是我还需要检查,学生是否参加了所有演讲,以及他在课程清单中的显示

But I also need to check, that student visits all lecture, that he have in courses list

    $student:Student ($courses:courses)
    $rightCourses: collect (LectureAssignment(student == $student)) // and get courses list

在这里,我获得了讲座,分配给当前学生,所有讲座都有属性当然,我需要将它们收集到$ rightCourses列表中,然后在这
之后比较$ courses和$ rightCourses(在这种情况下,我认为我不需要第一条规则)

here I get lectures, that assigned to current student , all lectures have property course and I need to collect them into list $rightCourses and after this compare $courses and $rightCourses (in this case I think I don't need first rule)

推荐答案

您可以使用forall运算符。请参阅此处的文档[1]。如果这对您不起作用,则可以使用累加[2],检查学生分配的讲座数是否正确,并结合检查您的学生没有分配不属于该课程的第一条规则课程列表。

You could use forall operator. See documentation here [1]. If that doesn't work for you, you could use accumulate [2], checking that the lecture count a student has assigned is correct, with a combination of your first rule that checks that a student has not assigned a course that is not part of the courses list.

[1] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_forall

[2] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_accumulate

这篇关于流口水从对象属性收集列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆