0

ルールの LHS で一致するファクトのスロットをどのように逆参照しますか? 変数がファクトに一致する場合、そのファクト内のスロットに一致する条件をさらに作成する方法がわかりません。

たとえば、以下のコードでは、"(do (action ?action))" という形式のファクトがある場合にテキストを出力したいと考えています。ただし、 ?action はそれ自体が事実であり、その事実の「名前」スロットが「実行」である場合にのみルールをトリガーする必要があります。どうすればこれを達成できますか?

(deftemplate do 
        (slot action) 
) 
(deftemplate action 
        (slot name) 
) 
(defrule find-do "" 
        ?do <- (do (action ?action)) 
        (test (eq ?action.name "run")) ; This causes a syntax error. 
        => 
        (printout t "doing " ?action crlf) 
) 
(deffacts startup (do (action (action (name "running")))))
4

1 に答える 1

1

Clips Reference マニュアルを検索すると、最終的に、私がやりたいと思われる関数 "fact-slot-value" を見つけました。

(deftemplate do 
        (slot action) 
) 
(deftemplate action 
        (slot name) 
) 
(defrule find-do "" 
        ?do <- (do (action ?action)) 
        (test (eq (fact-slot-value ?action name) "run"))
        => 
        (printout t "doing " ?action crlf) 
) 
(deffacts startup (do (action (action (name "running")))))
于 2010-08-11T21:10:35.253 に答える