我对剪辑专家系统非常新我正在寻找用于比较以前规则的文本的语法
喜欢这个
(defrule GetGender
(declare (salience 100))
(printout t "What's your gender ? (Male/Female): ")
(bind ?response (read))
(assert (Gender (gender ?response))))
,当我从上面得到答案时,我希望以下规则有效。
(defrule GetShirt
(declare (salience 99))
(Gender (gender ?l))
(test (= ?l Male))
=>
(printout t "What's your shirt color ? (Blue/Black): ")
(bind ?response (read))
(assert (Shirt (shirt ?response))))
,但看起来(test and =(不是字符串比较的语法,而我的英语还不够好,我什至不知道代码中的"?l"是指
有人可以帮我解决这个问题吗?
谢谢。
使用=用于比较数字和等式以比较任何类型的值。在您的盖衫规则中,令牌是一个与性别插槽值绑定的变量,因此可以在表达式中使用(=?l雄性(。与常数进行简单的比较时,不必使用测试条件元素。您可以简单地在模式中使用常数:
CLIPS>
(deftemplate response
(slot attribute)
(slot value))
CLIPS>
(defrule GetGender
=>
(printout t "What's your gender ? (Male/Female): ")
(bind ?response (read))
(assert (response (attribute gender) (value ?response))))
CLIPS>
(defrule GetShirt
(response (attribute gender) (value Male))
=>
(printout t "What's your shirt color ? (Blue/Black): ")
(bind ?response (read))
(assert (response (attribute shirt) (value ?response))))
CLIPS> (reset)
CLIPS> (run)
What's your gender ? (Male/Female): Male
What's your shirt color ? (Blue/Black): Blue
CLIPS>
=
用于比较数字。
对于字符串,您需要使用eq
函数。
In [1]: (eq "foo" "bar")
FALSE
In [2]: (eq "foo" "foo")
TRUE