取消引用剪辑中匹配事实中的槽

发布于 2024-09-12 01:06:16 字数 554 浏览 3 评论 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")))))

How do you dereference a slot in a fact matched in the LHS of a rule? If a variable
matches a fact, I can't find how to create further conditions that
match slots within that fact.

For example, in the code below, I want to print some text if there's a fact of the form "(do (action ?action))". However, ?action is itself a fact, and I only want the rule to trigger if that fact's "name" slot is "run". How would I accomplish this?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

郁金香雨 2024-09-19 01:06:16

搜索剪辑参考手册,我终于找到了“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")))))

Searching through the Clips Reference manual, I finally found the function "fact-slot-value" that seems to do what I want.

(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")))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文