专家系统-从deffunction中的多字段访问插槽



我有这个函数,它根据多个多字段事实的多个槽来计算一些值。

因为涉及到相当多的槽,并且函数中需要所有的槽,我在想,如果我能将整个事实传递给一个函数并访问它在其中的槽,像这样:

(deftemplate a-fact
    (slot id)
    (slot name)
    (slot ...)
    ...
)
(deffunction a-funciton (?factadr)
    (switch ?factadr:name
        (case bla then ...)
    )
    (return ?calculated-value)
)
(defrule a-rule
    ?factadr <- (a-fact (id ?i))
    =>
    (if (> **(a-function ?factadr) 20) then ... )
)

我看到了这个?事实地址:插槽名称在这个例子中,并认为它会工作,但它没有。那么,这可能吗?如何做到?

(bind ?facts (find-all-facts ((?f attribute))
                               (and (eq ?f:name wine)
                                    (>= ?f:certainty 20))))

使用夹子6.3。

使用事实槽值函数。

CLIPS> 
(deftemplate a-fact
   (slot id)
   (slot name))
CLIPS>  
(defrule a-rule
   ?f <- (a-fact)
   =>
   (printout t (fact-slot-value ?f id) " " (fact-slot-value ?f name) crlf))
CLIPS> (assert (a-fact (id 3) (name x)))
<Fact-1>
CLIPS> (assert (a-fact (id  7) (name y)))
<Fact-2>
CLIPS> (run)
7 y
3 x
CLIPS>

最新更新