剪辑。我如何检查事实列表是否与已经给出的事实相匹配?

CLIPS. How can I check if a list of facts matching facts already given?

我需要创建一个规则来检查我输入的事实列表是否与已经给出的事实相匹配。然后显示对应于至少一个输入的事实/事实。

这是我的:

(deftemplate rule (multislot problem) (slot cause))
(deffacts info
(rule (problem one) (cause one1))
(rule (problem two) (cause two2))
(rule (problem three) (cause three3))
 
 (defrule reading-input
 =>
 (printout t "Enter your problems: " )
 (assert (problem (read))))

 (defrule checking-input
 (problem $?problem)
 (rule (problem $?problem1) (cause ?cause1))
 (test (eq ?problem ?problem1))
  =>
 (printout t "cause: " ?cause1 crlf))

这应该如何工作:

CLIPS> Enter your problems: one two
CLIPS> cause: one1
       cause: two2

使用读取函数只会从您的输入中检索一个值。您需要结合使用 readline 函数和 explode$ 函数:

         CLIPS (6.4 2/9/21)
CLIPS> (assert (problem (read)))
one two
<Fact-1>
CLIPS> (assert (problem (readline)))
one two
<Fact-2>
CLIPS> (assert (problem (explode$ (readline))))
one two
<Fact-3>
CLIPS> (facts)
f-1     (problem one)
f-2     (problem "one two")
f-3     (problem one two)
For a total of 3 facts.
CLIPS>

然后您可以使用多字段通配符来隔离规则中的个别问题:

CLIPS> (clear)
CLIPS> 
(deftemplate rule
   (multislot problem)
   (slot cause))
CLIPS> 
(deffacts info
   (rule (problem one) (cause one1))
   (rule (problem two four) (cause two2))
   (rule (problem one three five) (cause three3)))
CLIPS>  
(defrule reading-input
   =>
   (printout t "Enter your problems: " )
   (assert (problem (explode$ (readline)))))
CLIPS> 
(defrule checking-input
   (problem $? ?problem $?)
   (rule (problem $? ?problem $?) (cause ?cause))
   =>
   (printout t "Problem: " ?problem " cause: " ?cause crlf))
CLIPS> (reset)
CLIPS> (run)
Enter your problems: one two
Problem: one cause: three3
Problem: one cause: one1
Problem: two cause: two2
CLIPS>