如何编写规则来检测剪辑中实例的删除?

发布于 2024-11-27 04:30:31 字数 333 浏览 0 评论 0原文

这就是我目前所拥有的:

(defclass classA (is-a USER) (role concrete))

(defclass classB (is-a USER) (role concrete)
  (slot a (type INSTANCE)))

(defrule classA-delete
  ?binstance <- (object (is-a classB) (a ?a&~:(instance-existp ?a)))
=>
  (send ?binstance delete))

但是当我删除 classA 的实例时,规则不会触发。

This is what I currently have:

(defclass classA (is-a USER) (role concrete))

(defclass classB (is-a USER) (role concrete)
  (slot a (type INSTANCE)))

(defrule classA-delete
  ?binstance <- (object (is-a classB) (a ?a&~:(instance-existp ?a)))
=>
  (send ?binstance delete))

But the rule does not fire when I delete an instance of classA.

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

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

发布评论

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

评论(1

深巷少女 2024-12-04 04:30:31

模式匹配过程并不具体了解什么可能会影响规则 LHS 上谓词函数的评估结果(在本例中为 instance-existp 函数)。在这种情况下,您的规则仅与 classB 的实例匹配,因此只有对该实例的更改才会重新触发模式匹配。当 classB 实例最初匹配时,将对 instance-existp 函数进行评估,要么成功,要么失败。更改 a 槽的值将重新触发 instance-existp 评估,但对规则中模式中未包含的实例或实例槽的更改将不会重新触发模式匹配。如果您使用非条件元素来检查实例,您将得到您想要的行为:

(defclass classA (is-a USER) 
                 (role concrete))

(defclass classB (is-a USER) 
                 (role concrete)
                 (slot a (type INSTANCE)))

(definstances start
   (a of classA)
   (b of classB (a [a])))  

(defrule classA-delete
  ?binstance <- (object (is-a classB) (a ?a))
  (not (object (name ?a)))
  =>
  (send ?binstance delete))

The pattern matching process doesn't have specific knowledge of what may effect the result of the evaluation of a predicate function on the LHS of a rule (in this case the instance-existp function). In this case, your rule only matches against instances of classB, so only changes to that instance are going to retrigger pattern matching. When the classB instance is originally matched, the instance-existp function is evaluated and either succeeds or fails. Changing the value of the a slot will retrigger the instance-existp evaluation, but changes to an instance or instance slot that is not contained within a pattern in the rule will not retrigger pattern matching. If you use the not conditional element to check for the instance, you'll get the behavior you want:

(defclass classA (is-a USER) 
                 (role concrete))

(defclass classB (is-a USER) 
                 (role concrete)
                 (slot a (type INSTANCE)))

(definstances start
   (a of classA)
   (b of classB (a [a])))  

(defrule classA-delete
  ?binstance <- (object (is-a classB) (a ?a))
  (not (object (name ?a)))
  =>
  (send ?binstance delete))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文