剪辑规则与多个条件元素的不一致匹配
我有这条规则:
(defrule tio-varon
(hermano-de (persona1 ?tio)(persona2 ?padremadre));
(or
(padre-de (padre ?padremade)(hijo ?hijo))
(madre-de (madre ?padremade)(hijo ?hijo))
)
(varon (persona ?tio))
(not (tio-de(tio ?tio)(sobrino ?hijo)))
=>
(assert (tio-de(tio ?tio)(sobrino ?hijo)))
)
这条规则与这样的事实相匹配:
(hermano-de (persona1 <b>John</b>)(persona2 Maria))
(padre-de (padre <b>John</b>)(hijo Michael))
(varon John)
给出事实作为结果 (tio-de (John)(Michael))
为什么,如果 John 和 Maria 在 (hermano-de) 事实上分别与 ?tio 和 ?padremade 匹配,那么 John 的值就像 ?padremadre 在 (padre-德)事实?我希望玛丽亚的值与事实相匹配(madre-de)或 (德雷神父)
I have this rule:
(defrule tio-varon
(hermano-de (persona1 ?tio)(persona2 ?padremadre));
(or
(padre-de (padre ?padremade)(hijo ?hijo))
(madre-de (madre ?padremade)(hijo ?hijo))
)
(varon (persona ?tio))
(not (tio-de(tio ?tio)(sobrino ?hijo)))
=>
(assert (tio-de(tio ?tio)(sobrino ?hijo)))
)
This rule is matching with facts like these:
(hermano-de (persona1 <b>John</b>)(persona2 Maria))
(padre-de (padre <b>John</b>)(hijo Michael))
(varon John)
giving as result the fact
(tio-de (John)(Michael))
Why, if John and Maria are matching with ?tio and ?padremade respectively over the (hermano-de) fact, later it's John the value that acts like ?padremadre over the (padre-de) fact? I hoped it was the value Maria the matched value with the fact (madre-de) or
(padre-de)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的变量名称不匹配。你在hermano-de事实中使用?padremadre,但在padre-de和padre-me事实中使用?padremade。第二个“r”丢失了。
当您加载代码时,您可以看到出现意外激活。
对于规则的 padre-de 析取,您可以从 matches 命令中看到 f-1 和 f-2 成功匹配规则的前两个模式,这是不应该发生的。因此,排除 CLIPS 模式匹配算法中的错误,规则的前两个模式一定有问题。 ?padremadre 变量是前两个模式共享的唯一变量,因此这是要检查的变量,因为它应该阻止前两个模式的匹配。
Your variable names don't match. You use ?padremadre in the hermano-de fact, but ?padremade in the padre-de and padre-me facts. The second 'r' is missing.
When you load your code, you can see that there's an unexpected activation.
For the padre-de disjunct of the rule, you can see from the matches command that f-1 and f-2 are successfully matching the first two patterns of the rule, which should not be happening. So excluding a bug in the CLIPS pattern matching algorithm, there must be something wrong in the first two patterns of the rule. The ?padremadre variable is the only variable shared by the first two patterns, so that's the one to examine since it should be preventing a match for the first two patterns.