我有这些模板,
(deftemplate classroom
(slot classroom_number (type INTEGER))
(multislot students (type SYMBOL))
)
(deftemplate students_to_classroom_lookup
(multislot students (type SYMBOL))
)
这些事实代表了教室和属于该教室的学生。
(deffacts classrooms
(classroom (classroom_number 1) (students Paul Lucy Peter Sebastian))
(classroom (classroom_number 2) (students Peter Paul Lucy Sebastian Arthur))
(classroom (classroom_number 3) (students Paul Lucy Peter))
(classroom (classroom_number 4) (students Lucy Peter Paul))
)
然后我有这个事实,它遵循“students_to_classroom_lookup”模板,并在程序运行时通过键盘输入。
(students_to_classroom_lookup (students Paul Peter Sebastian Lucy))
我想找到恰好有这些学生且只有这些学生的教室号。
请注意,内容,
(students_to_classroom_lookup (students Paul Peter Sebastian Lucy))
基于用户输入,在程序的另一次运行中,“学生”的内容可能是 Paul Sebastian Lucy Peter 或只是 Lucy Peter Paul。
我尝试过这个规则:
(defrule match_classroom_and_students
(classroom (classroom_number ?number) (students $?students))
(students_to_classroom_lookup (students $?students_lookup&:(subsetp $?students $?students_lookup)))
=>
(printout t "Classroom number " ?number crlf)
)
输出:
Classroom number 1
Classroom number 3
Classroom number 4
预期输出:
Classroom number 1
我感谢所有的帮助。
对于集合 A 和 B 的精确匹配,A 必须是 B 的子集,B 必须是 A 的子集: