CLIPS input taking and comparison

亡梦爱人 提交于 2019-12-11 12:56:56

问题


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

回答1:


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> 


来源:https://stackoverflow.com/questions/30588104/clips-input-taking-and-comparison

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!