CLIPS输入获取和比较 [英] CLIPS input taking and comparison

查看:92
本文介绍了CLIPS输入获取和比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从用户那里输入哪种颜色,然后输出包含该颜色的标志.到目前为止,我已经知道了.我很确定模板的设置是正确的.我似乎在输入以及比较和输出部分中遇到了问题.任何帮助,将不胜感激.我查看了其他几篇文章,并使用了仍然无法正常工作的内容. 谢谢你.

I need to take in input from the user which color and then output the flags that contain that color. I have this so far. I am pretty sure that the setup of my templates is correct. I just seem to be having issues with the input and the comparison and output part. Any help would be appreciated. I looked at a couple of other posts and used what I could be it still is not working. Thank you.

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

这篇关于CLIPS输入获取和比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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