检查输入以匹配剪辑中的事实 [英] Checking the input to match fact in Clips

查看:60
本文介绍了检查输入以匹配剪辑中的事实的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试获取输入并使用断言的事实中的症状进行事实检查时遇到问题.

I have a problem with trying to get an input and fact-check it with symptoms in the asserted facts.

(deftemplate disease
(slot name)
(multislot symptom ))

(assert (disease 
(name nitro-def) (symptom stunted-growth pale-yellow reddish-brown-leaf)))
(assert (disease 
(name phosphor-def) (symptom stunted-root-growth spindly-stalk purplish-colour)))
(assert (disease 
(name potassium-def) (symptom purple-colour weakened-stems shriveled-seeds)))

(defrule reading-input
(disease (name ?name1) (symptom ?symptom1))
=>
(printout t "Enter the symptom your plant exhibits: " )
(assert (var (read))))

(defrule checking-input
?vars <- (var)
(disease (name ?name1) (symptom ?symptom1))
(disease (symptom ?vars&:(eq ?vars ?symptom1)))
=>
(printout t "Disease is " ?name1 crlf))

因此,基本上,您输入一种症状,然后Clips返回与该症状匹配的疾病.问题是,在作为批处理加载文件并运行它之后,什么也没发生.事实被认定,但不需要任何输入.什么都没有触及第一条规则.

So basically you input a symptom and Clips returns the disease that matches that symptom. Problem is, that after Loading the file as Batch and running it, nothing happens. The Facts are asserted but no input is required. Nothing even touches the first rule.

如果有人能在这个问题上帮助我,我将不胜感激!

If anyone can help me in this issue, I would be dully grateful!

谢谢!

推荐答案

您已将症状定义为多字段插槽(一个包含零个或多个字段的插槽),但是与这些插槽匹配的模式仅在该插槽包含一个单一领域.使用多字段变量(例如$?symptom1)而不是单个字段变量(例如?symptom1)来检索多个值.

You've defined symptom as a multifield slot (a slot containing zero or more fields), but your patterns matching those slots will only match if the slot contains a single field. Use a multifield variable such as $?symptom1 instead of a single field variable such as ?symptom1 to retrieve multiple values.

CLIPS> 
(deftemplate disease
   (slot name)
   (multislot symptom))
CLIPS> 
(deffacts diseases
   (disease (name nitro-def) 
            (symptom stunted-growth pale-yellow reddish-brown-leaf))
   (disease (name phosphor-def) 
            (symptom stunted-root-growth spindly-stalk purplish-colour))
   (disease (name potassium-def) 
            (symptom purple-colour weakened-stems shriveled-seeds)))
CLIPS> 
(defrule reading-input
   =>
   (printout t "Enter the symptom your plant exhibits: " )
   (assert (var (read))))
CLIPS> 
(defrule checking-input
   (var ?symptom)
   (disease (name ?name1) (symptom $?symptom1))
   (test (member$ ?symptom ?symptom1)) 
   =>
   (printout t "Disease is " ?name1 crlf))
CLIPS> (reset)
CLIPS> (run)
Enter the symptom your plant exhibits: stunted-growth
Disease is nitro-def
CLIPS> (reset)
CLIPS> (run)
Enter the symptom your plant exhibits: purplish-colour
Disease is phosphor-def
CLIPS> (reset)
CLIPS> (run)
Enter the symptom your plant exhibits: spindly-stalk
Disease is phosphor-def
CLIPS>

这篇关于检查输入以匹配剪辑中的事实的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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