我正在用 CLIPS 为专家系统编写一个程序,该程序将诊断症状并得出影响西瓜植物的疾病类型。现在我想用.NET 来设计一个图形用户界面。这样用户只需使用复选框来选择症状并按下分析按钮即可查看影响西瓜植物的预测疾病。我已经在使用控制台执行任务,用户将对症状做出是或否的响应,此后系统将诊断影响西瓜植物的疾病种类。所以现在我想停止使用控制台并想使用.NET。但我对 .NET 有一点了解。我现在下载了Microsoft visual studio,想设计界面。
(deftemplate symptom
(slot id)
(slot question)
(slot indicative (default yes)))
(deffacts symptoms
(symptom (id ows)
(question "Is the plant showing a symptom of Oily and water-soaked cotyledons?"))
(symptom (id yhp)
(question "Is the plant showing a symptom of Yellow halo paralleling veins?"))
(symptom (id sda)
(question "Is the plant showing a symptom of Small dark and angled lesion on leaves?"))
(symptom (id dgb)
(question "Is the plant showing a symptom of Dark green blotch on the upper surface of developing fruit?"))
(symptom (id corky)
(question "Is the plant showing a symptom of corky, dry necrosis?"))
(symptom (id misshaping)
(question "Is the plant showing a symptom of misshapen?"))
(symptom (id dark)
(question "Is the plant showing a symptom of dark, water-soaked depression?"))
(symptom (id shiny)
(question "Is the leaf showing a symptom of shiny, chlorotic halo?"))
(symptom (id sil)
(question "Does the leaf shows a symptom of small irregular lesions and became angular later?"))
(symptom (id owb)
(question "Is the plant showing a symptom of clorotic on watermelon boaders?"))
(symptom (id olb)
(question "Is the plant showing a symptom of Older lesions that is usually brown, dry and tear to produce a tattered appearance on leaf ?"))
(symptom (id sri)
(question "Is the leaf showing a symptom of Small, round to irregular, watersoaked spots appear on infected leaves?"))
(symptom (id sou)
(question "Is the leaf showing a symptom of spots on the upper leaf surfaces turn whitish gray to brown and die?"))
(symptom (id oll)
(question "Is the leaf showing a symptom of gummy and shiny On the lower leaf surfaces?"))
)
(deftemplate disease
(slot id)
(multislot symptoms))
(deffacts diseases
(disease (id "bacterial fruit blotch")
(symptoms ows yhp sda dgb))
(disease (id "bacterial rind necrosis")
(symptoms corky misshaping dark))
(disease (id "angular leaf spot")
(symptoms shiny sil owb olb sri sou oll))
)
(deftemplate answer
(slot id)
(slot value))
(deftemplate conclusion
(slot id))
(defrule conclude-disease
;; There is a disease
(disease (id ?disease))
;; For every symptom of that disease
(forall (disease (id ?disease)
(symptoms $? ?symptom $?))
(symptom (id ?symptom)
(indicative ?value))
;; There is a response indicative
;; of a problem
(answer (id ?symptom)
(value ?value)))
=>
;; Conclude the plant has the disease
(assert (conclusion (id ?disease))))
(deffunction ask-question (?question $?allowed-values)
(printout t ?question " " ?allowed-values " ")
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer)))
(while (not (member$ ?answer ?allowed-values)) do
(printout t ?question " " ?allowed-values " ")
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer))))
?answer)
(defrule ask-symptom
;; There is a symptom
(symptom (id ?symptom)
(question ?question))
;; For a disease
(disease (id ?disease)
(symptoms $? ?symptom $?))
;; That we have not determined
(not (answer (id ?symptom)))
;; And there is no prior response to a symptom
;; of that disease that is non-indicative.
(not (and (disease (id ?disease)
(symptoms $? ?other-symptom $?))
(symptom (id ?other-symptom)
(indicative ?value))
(answer (id ?other-symptom)
(value ~?value))))
=>
;; Ask the user the symptom question
(bind ?value (ask-question ?question yes no))
;; And assert the response.
(assert (answer (id ?symptom)
(value ?value))))
(defrule print-conclusion
(declare (salience -10))
(conclusion (id ?disease))
=>
(printout t "The plant is showing symptoms of " ?disease " watermelon disease." crlf))
(defrule print-no-conclusion
(declare (salience -10))
(not (conclusion))
=>
(printout t "The plant is not showing all symptoms of a watermelon disease." crlf))