【问题标题】:How to assert the opposite value from that of the matching?如何断言与匹配值相反的值?
【发布时间】:2021-04-13 02:34:43
【问题描述】:

我有一个规则,它有一个与两种颜色进行匹配的插槽,只要匹配后它会变为相反的颜色,它将匹配哪一种并不重要。但是,当我写这个时,我得到一个语法错误:

(defrule colour
?col <- (colorTemp(color ?color&white|black))
=>
(modify ?col (color ?colorOpposite&~?color))
)

谢谢

【问题讨论】:

  • 你得到什么错误?请在问题中包含它。 “反色”是什么意思?你如何定义一种颜色与另一种颜色相反?
  • 感谢您的回答,我在修改部分遇到语法错误,所以如果它与黑色匹配,那么我想将其修改为白色,反之亦然
  • 请复制粘贴问题中的整个错误消息。请参阅how to ask SO 参考。系统如何知道黑色与白色相反?您是否在某处将其定义为规则?

标签: regex rules clips expert-system


【解决方案1】:

语法 ?colorOpposite&~?color 在规则的操作中无效,并且变量 ?colorOpposite 未绑定在规则中的任何位置,因此这两个问题都会产生错误。您还需要添加一些指定颜色对立面的代码。为防止从一个对面循环到另一个循环,您需要以某种方式指出颜色已更改。

         CLIPS (6.31 6/12/19)
CLIPS> 
(deftemplate colorTemp
   (slot color)
   (slot changed (default no)))
CLIPS>    
(deffacts opposites
   (opposite white black))
CLIPS> 
(defrule colour
   ?col <- (colorTemp (color ?color&white|black)
                      (changed no))
   (or (opposite ?color ?opposite)
       (opposite ?opposite ?color))
   =>
   (modify ?col (color ?opposite)
                (changed yes)))
CLIPS> (reset)
CLIPS> (assert (colorTemp (color white)))
<Fact-2>
CLIPS> (facts)
f-0     (initial-fact)
f-1     (opposite white black)
f-2     (colorTemp (color white) (changed no))
For a total of 3 facts.
CLIPS> (agenda)
0      colour: f-2,f-1
For a total of 1 activation.
CLIPS> (run)
CLIPS> (facts)
f-0     (initial-fact)
f-1     (opposite white black)
f-3     (colorTemp (color black) (changed yes))
For a total of 3 facts.
CLIPS> 

【讨论】:

    猜你喜欢
    • 2021-03-16
    • 1970-01-01
    • 2017-08-11
    • 2019-12-05
    • 2019-12-04
    • 2015-02-01
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    相关资源
    最近更新 更多