问题描述
对于Clips专家系统
来说我是一个非常陌生的人,我正在寻找一种用于比较以前规则中的文本的语法
I'm very very new to Clips expert systemI'm looking for what is a syntax to use for compare a text from previous rules
像这样
(defrule GetGender
(declare (salience 100))
(printout t "What's your gender ? (Male/Female): ")
(bind ?response (read))
(assert (Gender (gender ?response))))
,当我从上方获得男性的答案时,我希望下面的规则有效。
and when I get answer from above like "Male" I want the rule below active.
(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和=)似乎不是字符串比较的语法,而我英语还不够好,我什至不知道代码中的?l是什么意思
But seem (test and =) is not a syntax for string compare, and my English is not good enough, I don't even know about what "?l" in the code means
有人可以帮我解决这个问题吗?
could somebody help me to fix this out please ?
T谢谢。
推荐答案
使用=来比较数字,用eq来比较任何类型的值。在您的GetShirt规则中,标记?l是绑定到性别槽值的变量,以便可以在表达式中使用(=?l Male)。对常数进行简单比较时,无需使用测试条件元素。您可以在模式中简单地使用常量:
Use = for comparing numbers and eq for comparing values of any type. In your GetShirt rule, the token ?l is a variable that is bound to the value of the gender slot so that it can be used in the expression (= ?l Male). When making simple comparisons to constants, it's not necessary to use the test conditional element. You can simply use the constant within the pattern:
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>
这篇关于剪辑使用字符串进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!