我是使用CLIPS开发专家系统的初学者。现在,我通过询问专家系统来设置专家系统的开始,并根据答案提供一个或多个结果。现在我的问题是我必须在程序中编写什么内容,以便有可能选择其中一种结果,并通过专注于该结果并提出详细问题来继续专家系统?
在我的代码下面看一下重点是打印结果
;;************************
;;* REQUIREMENTS SELECTION RULES *
;;************************
(defmodule REQUIREMENT (import MAIN ?ALL))
(deffacts any-attributes
(attribute (name best-color) (value any))
(attribute (name best-ratio) (value any))
(attribute (name best-importancy) (value any))
(attribute (name best-light) (value any))
(attribute (name best-blinds) (value any))
(attribute (name best-kind) (value any))
(attribute (name best-how) (value any))
(attribute (name best-function) (value any)))
(deftemplate REQUIREMENT::component
(slot name (default ?NONE))
(multislot color (default any))
(multislot ratio (default any))
(multislot importancy (default any))
(multislot light (default any))
(multislot blinds (default any))
(multislot kind (default any))
(multislot how (default any))
(multislot function (default any)))
(deffacts REQUIREMENT::the-component-list
(component (name HR-0.5) (color grey))
(component (name HR+-0.26) (color grey) (ratio 50-50) (light natural))
(component (name HR++-0.15) (color grey) (importancy privacy) (light artificial) (blinds unknown))
(component (name Triple-glass-0.8) (color grey) (ratio 50-50) (importancy view) (light combination))
(component (name Safety-glass-0.6) (color grey) (importancy comfortable privacy) (light combination natural))
(component (name Isolation-glass-0.1) (color grey) (importancy view) (light natural artificial) (blinds unknown))
(component (name Soundproof-glass-0.4) (color grey) (ratio 50-50) (importancy privacy comfortable) (light artificial combination))
(component (name Floatglass-0.5) (color grey) (ratio 50-50) (importancy view))
(component (name Hardglass-0.2) (color grey) (ratio 50-50) (importancy comfortable) (light natural combination) (blinds unknown))
(component (name Wire-glass-0.5) (color grey) (importancy privacy))
(component (name Layered-glass-0.7) (color grey) (ratio 50-50) (light natural artificial))
(component (name Glass1-0.5) (color grey) (ratio 50-50) (light combination) (blinds unknown))
(component (name Glass2-0.5) (color grey) (importancy view) (light natural))
(component (name Glass3-0.5) (color grey) (ratio 50-50) (importancy privacy) (blinds unknown))
(component (name Glass4-0.5) (color grey) (light natural) (importancy view))
(component (name Glass5-0.5) (color grey) (ratio 50-50) (light natural artificial)))
(defrule REQUIREMENT::generate-requirements
(component (name ?name)
(color $? ?d $?)
(ratio $? ?c $?)
(importancy $? ?b $?)
(light $? ?s $?)
(blinds $? ?r $?)
(kind $? ?t $?)
(how $? ?w $?)
(function $? ?p $?))
(attribute (name best-ratio) (value ?c) (certainty ?certainty-1))
(attribute (name best-importancy) (value ?b) (certainty ?certainty-2))
(attribute (name best-light) (value ?s) (certainty ?certainty-3))
(attribute (name best-blinds) (value ?r) (certainty ?certainty-4))
(attribute (name best-kind) (value ?t) (certainty ?certainty-5))
(attribute (name best-how) (value ?w) (certainty ?certainty-6))
(attribute (name best-function) (value ?p) (certainty ?certainty-7))
(attribute (name best-color) (value ?d) (certainty ?certainty-8))
=>
(assert (attribute (name component) (value ?name)
(certainty (min ?certainty-1 ?certainty-2 ?certainty-3 ?certainty-4 ?certainty-5 ?certainty-6 ?certainty-7 ?certainty-8)))))
;;*****************************
;;* PRINT SELECTED component RULES *
;;*****************************
(defmodule PRINT-RESULTS (import MAIN ?ALL))
(defrule PRINT-RESULTS::header ""
(declare (salience 10))
=>
(printout t )
(printout t " RESULTS" crlf)
(printout t " TYPE - Tv VALUE MATCH" crlf)
(printout t " -------------------------------" crlf)
(assert (phase print-requirements)))
(defrule PRINT-RESULTS::print-requirements ""
?rem <- (attribute (name component) (value ?name) (certainty ?per))
(not (attribute (name component) (certainty ?per1&:(> ?per1 ?per))))
=>
(retract ?rem)
(format t " %-24s %2d%%%n" ?name ?per))
(defrule PRINT-RESULTS::remove-poor-component-choices ""
?rem <- (attribute (name component) (certainty ?per&:(< ?per 0)))
=>
(retract ?rem))
(defrule PRINT-RESULTS::end-spaces ""
(not (attribute (name component)))
=>
(printout t ))