首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CLIPS录入与比较

CLIPS录入与比较
EN

Stack Overflow用户
提问于 2015-06-02 05:34:34
回答 1查看 801关注 0票数 1

我需要接收用户输入的颜色,然后输出包含该颜色的标志。到目前为止我有这个。我很确定我的模板的设置是正确的。我只是对输入和比较输出部分有问题。任何帮助都将不胜感激。我看了几个其他的帖子,用了我能用的东西-它仍然不起作用。谢谢。

代码语言:javascript
复制
(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)
)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-02 15:55:58

代码语言:javascript
复制
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> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30588104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档