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

fact-slot-value 関数を使用します。

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 に答える