2

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

因为涉及到相当多的插槽,并且函数中需要所有插槽,所以我在想是否可以将整个事实传递给函数并访问其中的插槽,如下所示:

(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 ... )
)

我在这个例子中看到了这个?fact-adrres:slot-name并认为它会起作用,但它没有。那么,是否有可能以及如何做到这一点?

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

使用剪辑 6.3。

4

1 回答 1

7

使用事实槽值函数。

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>
于 2011-07-02T21:46:07.813 回答