剪辑使用字符串进行比较条件 [英] clips use string to make a compare condition

查看:34
本文介绍了剪辑使用字符串进行比较条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm very very new to Clips expert system I'm looking for what is a syntax to use for compare a text from previous rules

like this

(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))))

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 ?

Thank you.

解决方案

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> 

这篇关于剪辑使用字符串进行比较条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆