CLIPS 输入获取和比较
CLIPS input taking and comparison
我需要接收用户输入的颜色,然后输出包含该颜色的标志。到目前为止我有这个。我很确定我的模板设置是正确的。我似乎只是在输入以及比较和输出部分遇到问题。任何帮助,将不胜感激。我查看了其他几个帖子并使用了我能做的但仍然无法正常工作。
谢谢你。
(deftemplate country-info
(slot country)
(multislot color)
)
; setting the template for flags taking the country name and color of the flags
(deffacts country
(country-info (country usa) (color red | white | blue))
(country-info (country belgium) (color black | yellow | red))
(country-info (country poland) (color white | red))
(country-info (country monaco) (color white | red))
(country-info (country sweden) (color yellow | blue))
(country-info (country Panama) (color white | blue | red))
(country-info (country jamacia) (color black | yellow | green))
(country-info (country colombia) (color blue | yellow | red))
(country-info (country italy) (color black | yellow | red))
(country-info (country ireland) (color green | white | orange))
(country-info (country botswana) (color blue | white | black))
)
(defrule color
(color ? name)
(not (color ? name ?))
=>
(printout t "What color is it you are looking for?")
(defrule check-input
(var ?color)
(country-info (country ?country1) (color $?color1))
(test (member$ ?color ?color1))
=>(printout t "Countries are" ? country crlf)
)
CLIPS> (clear)
CLIPS>
(deftemplate country-info
(slot country)
(multislot color))
CLIPS>
(deffacts country
(country-info (country USA) (color red white blue))
(country-info (country Belgium) (color black yellow red))
(country-info (country Poland) (color white red))
(country-info (country Monaco) (color white red))
(country-info (country Sweden) (color yellow blue))
(country-info (country Panama) (color white blue red))
(country-info (country Jamacia) (color black yellow green))
(country-info (country Colombia) (color blue yellow red))
(country-info (country Italy) (color black yellow red))
(country-info (country Ireland) (color green white orange))
(country-info (country Botswana) (color blue white black)))
CLIPS>
(defrule color
=>
(printout t "Color? ")
(assert (color (read))))
CLIPS>
(defrule check-input
(color ?color)
(country-info (country ?country) (color $? ?color $?))
=>
(printout t " " ?country crlf))
CLIPS> (reset)
CLIPS> (run)
Color? red
Italy
Colombia
Panama
Monaco
Poland
Belgium
USA
CLIPS>
我需要接收用户输入的颜色,然后输出包含该颜色的标志。到目前为止我有这个。我很确定我的模板设置是正确的。我似乎只是在输入以及比较和输出部分遇到问题。任何帮助,将不胜感激。我查看了其他几个帖子并使用了我能做的但仍然无法正常工作。 谢谢你。
(deftemplate country-info
(slot country)
(multislot color)
)
; setting the template for flags taking the country name and color of the flags
(deffacts country
(country-info (country usa) (color red | white | blue))
(country-info (country belgium) (color black | yellow | red))
(country-info (country poland) (color white | red))
(country-info (country monaco) (color white | red))
(country-info (country sweden) (color yellow | blue))
(country-info (country Panama) (color white | blue | red))
(country-info (country jamacia) (color black | yellow | green))
(country-info (country colombia) (color blue | yellow | red))
(country-info (country italy) (color black | yellow | red))
(country-info (country ireland) (color green | white | orange))
(country-info (country botswana) (color blue | white | black))
)
(defrule color
(color ? name)
(not (color ? name ?))
=>
(printout t "What color is it you are looking for?")
(defrule check-input
(var ?color)
(country-info (country ?country1) (color $?color1))
(test (member$ ?color ?color1))
=>(printout t "Countries are" ? country crlf)
)
CLIPS> (clear)
CLIPS>
(deftemplate country-info
(slot country)
(multislot color))
CLIPS>
(deffacts country
(country-info (country USA) (color red white blue))
(country-info (country Belgium) (color black yellow red))
(country-info (country Poland) (color white red))
(country-info (country Monaco) (color white red))
(country-info (country Sweden) (color yellow blue))
(country-info (country Panama) (color white blue red))
(country-info (country Jamacia) (color black yellow green))
(country-info (country Colombia) (color blue yellow red))
(country-info (country Italy) (color black yellow red))
(country-info (country Ireland) (color green white orange))
(country-info (country Botswana) (color blue white black)))
CLIPS>
(defrule color
=>
(printout t "Color? ")
(assert (color (read))))
CLIPS>
(defrule check-input
(color ?color)
(country-info (country ?country) (color $? ?color $?))
=>
(printout t " " ?country crlf))
CLIPS> (reset)
CLIPS> (run)
Color? red
Italy
Colombia
Panama
Monaco
Poland
Belgium
USA
CLIPS>