查找剪辑中匹配的最佳规则

Find best rule matched in clips

我是 CLIPS 的新手,在个人项目的开发过程中,我想实现一个功能,使我能够在事实插入后看到匹配最多模式的规则。 为了更好地理解:

>(defrule one
        (fact a)
        (fact b)
=>
        (assert (fact i)))

>(defrule two
        (fact b)
        (fact c)
=>
        (assert (fact d) (fact f)))

>(defrule three
        (fact a)
        (fact d)
        (fact c)
=>
        (assert (fact g)))


> (assert (fact a) (fact c))
> (trace-rule)
rule three 
Matches for Pattern 1
f-1
Matches for Pattern 2
None
Matches for Pattern 3
f-2

也许我可以使用 matches 命令,但我不知道如何继续。

谢谢你的时间。

         CLIPS (6.30 3/17/15)
CLIPS> 
(deffunction most-matches ()
   (bind ?rules (create$))
   (bind ?most -1)
   (foreach ?r (get-defrule-list)
      (bind ?matches (nth$ 1 (matches ?r terse)))
      (if (= ?matches ?most)
         then
         (bind ?most ?matches)
         (bind ?rules (create$ ?rules ?r))
         else
         (if (> ?matches ?most)
            then
            (bind ?most ?matches)
            (bind ?rules (create$ ?r)))))
   ?rules)
CLIPS>    
(defrule one
   (fact a)
   (fact b)
   =>
   (assert (fact i)))
CLIPS> 
(defrule two
   (fact b)
   (fact c)
   =>
   (assert (fact d)
           (fact f)))
CLIPS> 
(defrule three
   (fact a)
   (fact d)
   (fact c)
   =>
   (assert (fact g)))
CLIPS> (assert (fact a) (fact c))
<Fact-2>
CLIPS> (most-matches)
(three)
CLIPS> (reset)
CLIPS> (assert (fact b))
<Fact-1>
CLIPS> (most-matches)
(one two)
CLIPS> (reset)
CLIPS> (most-matches)
(one two three)
CLIPS>