clips - 如何使用 CLIPS 读取/使用用户输入
问题描述
我正在做一个 Clips 项目。我试图首先存储事实(这很好)。然后我试图要求用户提供有关存储为事实的 gem 的详细信息,并根据他们的回答为他们提供 gem 的正确名称。
(deftemplate gem
(slot name)
(slot hardness)
(slot density)
(multislot colors))
(deffacts gems
(gem (name diamond) (hardness 10) (density 3.52) (colors yellow, brown, green, blue, white, colorless))
(gem (name corundum) (hardness 9) (density 4) (colors red, pink, yellow, brown, green, blue, violet, black, white, colorless))
(gem (name chrysoberyl) (hardness 8.5) (density 3.72) (colors yellow,brown,green))
(gem (name spinel) (hardness 8) (density 3.6) (colors red, pink, yellow, brown, green, blue, violet, white, colorless)))
(defrule reading-input
=>
(printout t "Enter the hardness of the gem: " )
(assert (var(read)))
(printout t "Enter the density of the gem: " )
(assert (var(read)))
(printout t "Enter the color of the gem: " )
(assert (var(read))))
(defrule checking-input
(var ?hardness)
(var ?density)
(var ?colors)
(gem (name ?name1) (hardness ?hardness1) (density ?density1) (colors $?colors1))
(test (= ?hardness ?hardness1))
(test (= ?hardness ?hardness1))
(test (member$ ?hardness ?hardness1))
=>
(printout t "Gem is " ?name1 crlf))
我是 CLIPS 的初学者,尽管花费了数小时,但无法弄清楚如何使上述代码正常工作。任何帮助将不胜感激。谢谢。
解决方案
CLIPS (6.31 2/3/18)
CLIPS>
(deftemplate gem
(slot name)
(slot hardness)
(slot density)
(multislot colors))
CLIPS>
(deffacts gems
(gem (name diamond) (hardness 10) (density 3.52) (colors yellow brown green blue white colorless))
(gem (name corundum) (hardness 9) (density 4) (colors red pink yellow brown green blue violet black white colorless))
(gem (name chrysoberyl) (hardness 8.5) (density 3.72) (colors yellow brown green))
(gem (name spinel) (hardness 8) (density 3.6) (colors red pink yellow brown green blue violet white colorless)))
CLIPS>
(defrule reading-input
=>
(printout t "Enter the hardness of the gem: " )
(assert (hardness (read)))
(printout t "Enter the density of the gem: " )
(assert (density (read)))
(printout t "Enter the color of the gem: " )
(assert (color (read))))
CLIPS>
(defrule checking-input
(hardness ?hardness)
(density ?density)
(color ?color)
(gem (name ?name1) (hardness ?hardness1) (density ?density1) (colors $?colors1))
(test (= ?hardness ?hardness1))
(test (= ?density ?density1))
(test (member$ ?color ?colors1))
=>
(printout t "Gem is " ?name1 crlf))
CLIPS> (reset)
CLIPS> (run)
Enter the hardness of the gem: 9
Enter the density of the gem: 4
Enter the color of the gem: green
Gem is corundum
CLIPS>
推荐阅读
- python - 使所有用户都可以访问由 pip 安装的程序 (aws cli)
- angular - 如何将对象属性绑定到 page-router-outlet 的 name 属性?
- spring-boot - Spring WebFlux WebClient 挂起并且 Mono.timeout 没有捕捉到它
- javascript - 如何将块按到主窗口底部?
- actionscript-3 - 跟踪 as3 的事件侦听器
- r - 在 r 中查找并提取超过阈值的值
- r - 在插入符号的训练函数中并行调整 xgboost 模型时出错
- firebase - 创建/更新/删除 Firebase 实时数据库规则
- dart - 发生异常。不良状态:Future 已经在颤振列表视图和视频播放器中完成
- r - 如何根据R中元素内字母“A”的数量将元素分配给不同的子集?