首页 > 解决方案 > 剪辑编程:如何计算有多少事实是“是”?

问题描述

我是剪辑编程的新手,我目前正在开发一个针对心理健康疾病(焦虑)的专家系统。我的系统的工作方式是在用户回答完所有问题之后,例如“您是否过度担心?”、“您感到孤独吗?”、“您呼吸困难吗?” 以此类推,系统将打印输出。例如:-

;after the user has input all the question about the symptoms...

(defrule MAIN::s-1
(have-anxiety yes)
(or (age 2)
    (age 3))
(heart_palpitation yes)
(excess_sweating yes)
(body_trembling yes)
(dizzy yes)
(difficult_breath yes)
(afraid_crowd yes)
(panic_attack yes)
(short_breath yes)
(panic_arises yes)
(how_long 2)
=>
(printout t crlf)
(printout t "Solution:")
(printout t crlf)
(printout t "You have panic disorder! Please refer specialist now!!!")
(printout t crlf crlf)
(assert (disorder panic)))

我的系统现在的问题是假设所有事实都是“是”,那么这意味着用户有精神障碍。但是,如果只有 1 个事实是“否”,那么用户自动没有混乱,因为它不满足触发规则的要求。从逻辑上讲,如果一个人有 10 种精神疾病症状中的 9 种,则该人一定患有精神疾病。

因此,我想做一个条件,比如如果用户有 4 个或更多症状,那么用户就有了精神疾病。先感谢您!

更新

以下是我的完整代码:-

;;;;;;;;;;;;;;;;;;;;FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction ask-question (?question $?allowed-values)
   (printout t ?question)
   (bind ?answer (read))
   (if (lexemep ?answer) 
       then (bind ?answer (lowcase ?answer)))
   (while (not (member$ ?answer ?allowed-values)) do
      (printout t ?question)
      (bind ?answer (read))
      (if (lexemep ?answer) 
          then (bind ?answer (lowcase ?answer))))
   ?answer)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction yes-or-no-p (?question)
   (bind ?response (ask-question ?question yes no y n))
   (if (or (eq ?response yes) (eq ?response y))
       then yes 
       else no))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction ask-question-number (?question $?allowed-values)
    (printout t ?question)
    (bind ?answer (read))
    (while (not (member$ ?answer ?allowed-values)) do
        (printout t ?question)
        (bind ?answer (read)))
    ?answer)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction number-valid (?question)
    (bind ?response (ask-question-number ?question 1 2 3))
    (if (= ?response 1)
        then 1
    else    (if (= ?response 2)
            then 2
        else 3)
        
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction ask-question-number-2 (?question $?allowed-values)
    (printout t ?question)
    (bind ?answer (read))
    (while (not (member$ ?answer ?allowed-values)) do
        (printout t ?question)
        (bind ?answer (read)))
    ?answer)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction number-valid-2 (?question)
    (bind ?response (ask-question-number-2 ?question 1 2))
    (if (= ?response 1)
        then 1
    else 2)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;START RULE;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defrule MAIN::start
    (declare (salience 10))
    =>
    (printout t crlf crlf)
    (printout t "Anxiety Diagnosis Expert System")
    (printout t crlf crlf)
    (assert (have-anxiety (yes-or-no-p "Do you have an excessive anxiety and worry?:"))))

(defrule f-2
    (have-anxiety yes)
    =>
    (printout t "Choose your citizen category:")
    (printout t crlf crlf)
    (printout t "1. Adolescence")
    (printout t crlf)
    (printout t "2. Adult")
    (printout t crlf)
    (printout t "3. Kid")
    (printout t crlf crlf)
;   (printout t "Type number(1/2/3): ")
;   (assert (age (read))))
    (assert (age (number-valid "Type number: "))))

(defrule MAIN::f-3
    (have-anxiety yes)
    =>
    (assert (heart_palpitation (yes-or-no-p "Heart palpitation?:"))))

(defrule MAIN::f-4
    (have-anxiety yes)
    (heart_palpitation yes)
    =>
    (assert (excess_sweating (yes-or-no-p "Excessive sweating?:"))))

(defrule MAIN::f-5
    (have-anxiety yes)
    (heart_palpitation yes)
    =>
    (assert (body_trembling (yes-or-no-p "Trembling on some parts of body?:"))))

(defrule MAIN::f-6
    (have-anxiety yes)
    (heart_palpitation yes)
    =>
    (assert (dizzy (yes-or-no-p "Feeling dizzy?:"))))

(defrule MAIN::f-19
        (have-anxiety yes)
    (heart_palpitation yes)
        =>
        (assert (concentrate (yes-or-no-p "Are you hard to concentrate? "))))

(defrule MAIN::f-20
        (have-anxiety yes)
    (heart_palpitation yes)
        =>
        (assert (uneasy_unrealistically (yes-or-no-p "Always feeling uneasy and thinking unrealistically? "))))

(defrule MAIN::f-21
        (have-anxiety yes)
    (heart_palpitation yes)
    =>
        (assert (muscle_feel_tight (yes-or-no-p "Exposure to triggers causes the muscles to feel tight? "))))

(defrule MAIN::f-8
    (have-anxiety yes)
    (heart_palpitation yes)
    (control_worry no)
    =>
    (assert (afraid_crowd (yes-or-no-p "Afraid of crowded place?:"))))

(defrule MAIN::f-7
    (have-anxiety yes)
    (heart_palpitation yes)
    (control_worry no)
    =>
    (assert (difficult_breath (yes-or-no-p "Difficult at breathing?:"))))

(defrule MAIN::f-9
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (afraid_crowd yes)
    (difficult_breath yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    =>
    (assert (panic_attack (yes-or-no-p "Panic attacks repeat unexpectedly?:"))))

(defrule MAIN::f-10
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    (afraid_crowd yes)
    (difficult_breath yes)
    =>
    (assert (short_breath (yes-or-no-p "Sensation of shortness of breath?:"))))

(defrule MAIN::f-11
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    (afraid_crowd yes)
    (difficult_breath yes)
    =>
    (assert (panic_arises (yes-or-no-p "Panic arises even through the object that triggers panic is not life threatening?:"))))

(defrule MAIN::f-12
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    (afraid_crowd yes)
    (difficult_breath yes)
    =>
    (printout t "How long did this happen:")
    (printout t crlf crlf)
    (printout t "1. less than 1 month")
    (printout t crlf)
    (printout t "2. more than 1 month")
    (printout t crlf crlf crlf)
;   (printout t "Type number(1/2):")
;   (assert (how_long (read))))
    (assert (how_long (number-valid-2 "Type number(1/2):"))))

(defrule MAIN::f-13
    (have-anxiety yes)
    (heart_palpitation no)
    =>
    (assert (major_attachment_figures (yes-or-no-p "Have major attachment figures?:"))))

(defrule MAIN::f-14
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (printout t crlf)
    (printout t "List of symptom:")
    (printout t crlf crlf)
    (printout t "1. Refuse to leave home, go to school, go to work.")
    (printout t crlf crlf)
    (printout t "2. Worry about losing major attachment figures due to illness, disasters, or death.")
    (printout t crlf crlf)
    (printout t "3. Worry about experiencing untoward events (getting lost, being kidnapped, having an accident, becoming ill).")
    (printout t crlf crlf)
    (printout t "4. Reluctance to sleep away from home or sleep away from home.")
    (printout t crlf crlf)
    (printout t "5. Repeated nightmares with separation theme.")
    (printout t crlf crlf)
    (assert (list_symptom (yes-or-no-p "Do you have at least 1 of the symptom?:"))))

(defrule MAIN::f-15
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (worry_separation (yes-or-no-p "Worry about separation?:"))))

(defrule MAIN::f-16
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (nausea (yes-or-no-p "Nausea or vomitting?:"))))

(defrule MAIN::f-17
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (stomach_aches (yes-or-no-p "Stomach aches?:"))))

(defrule MAIN::f-18
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (headache (yes-or-no-p "Headaches?:"))))

(defrule MAIN::s-2-f-12
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (printout t "How long did this happen:")
    (printout t crlf crlf)
    (printout t "1. less than 1 month")
    (printout t crlf)
    (printout t "2. more than 1 month")
    (printout t crlf)
    (printout t "3. more than 6 month")
    (printout t crlf crlf crlf)
;   (printout t "Type number(1/2/3):")
;   (assert (how_long (read))))
    (assert (how_long (number-valid "Type number(1/2/3)?:"))))

(defrule MAIN::f-27
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures no)
    =>
    (assert (avoid_social (yes-or-no-p "Avoid social situation?:"))))

(defrule MAIN::f-28
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures no)
    =>
    (assert (fear_social (yes-or-no-p "Fear about social situation?:"))))

(defrule MAIN::f-29
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures no)
    =>
    (assert (fear_humiliation (yes-or-no-p "Fear of humiliating or embarrassing themselves?:"))))

(defrule MAIN::f-22
    (have-anxiety yes)
    (dizzy no)
    (difficult_breath no)
    (heart_palpitation yes)
    =>
    (assert (fear_not_realistic (yes-or-no-p "Do not realize that your fear is not realistic? "))))

(defrule MAIN::f-23
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy no)
    =>
    (assert (trigger_headache (yes-or-no-p "Exposure to triggers causes of frequent headaches/migraines? "))))

(defrule MAIN::f-24
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy no)
    =>
    (assert (trigger_intense_anxiety (yes-or-no-p "Exposure to triggers cause intense anxiety? "))))



(defrule MAIN::f-25
    (heart_palpitation yes)
    =>
    (assert (control_worry (yes-or-no-p "Difficult control worry? "))))

(defrule MAIN::f-26-adult-adoles
    (control_worry yes)
    (or (age 1)
        (age 2))
    =>
    (printout t "Do you experience three or more of the following:-")
        (printout t crlf crlf)
        (printout t "1. Restlessness")
        (printout t crlf)
        (printout t "2. Easily fatigue")
        (printout t crlf)
        (printout t "3. Muscle tension")
    (printout t crlf)
    (printout t "4. Hard to concentrate")
        (printout t crlf)
        (printout t "5. Sleep disturbance")
        (printout t crlf crlf)
    (assert (experience (yes-or-no-p "Type (yes/no) : "))))

(defrule MAIN::f-26-kid
    (control_worry yes)
    (age 3)
    =>
    (printout t "Do you experience atleast 1 of the following:-")
        (printout t crlf crlf)
        (printout t "1. Restlessness")
        (printout t crlf)
        (printout t "2. Easily fatigue")
        (printout t crlf)
        (printout t "3. Muscle tension")
    (printout t crlf)
    (printout t "4. Hard to concentrate")
        (printout t crlf)
        (printout t "5. Sleep disturbance")
        (printout t crlf crlf)
    (assert (experience-kid (yes-or-no-p "Type (yes/no) : "))))

(defrule MAIN::s-4-f-12
    (or (experience yes)
        (experience-kid yes))
        =>
        (printout t "How long did this happen:")
        (printout t crlf crlf)
        (printout t "1. less than 6 months")
        (printout t crlf)
        (printout t "2. more than 6 months")
        (printout t crlf crlf crlf)
    (assert (how_long (number-valid-2 "Type number(1/2):"))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;RESULT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defrule MAIN::s-1
    (have-anxiety yes)
    (or (age 2)
        (age 3))
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy yes)
    (difficult_breath yes)
    (afraid_crowd yes)
    (panic_attack yes)
    (short_breath yes)
    (panic_arises yes)
    (how_long 2)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have panic disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder panic)))

(defrule MAIN::s-2-1
    (have-anxiety yes)
    (age 2)
    (heart_palpitation no)
    (major_attachment_figures yes)
    (list_symptom yes)
    (worry_separation yes)
    (nausea yes)
    (stomach_aches yes)
    (headache yes)
    (how_long 3)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have separation anxiety disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder separation-anxiety)))
;   (halt))

(defrule MAIN::s-2-2
    (have-anxiety yes)
    (or (age 1)
        (age 3))
    (heart_palpitation no)
    (major_attachment_figures yes)
    (major_attachment_figures yes)
    (list_symptom yes)
    (worry_separation yes)
    (nausea yes)
    (stomach_aches yes)
    (headache yes)
    (how_long 2)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have separation anxiety disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder separation-anxiety)))
;   (halt))

(defrule MAIN::s-3
    (have-anxiety yes)
    (or (age 2)
        (age 3))
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy no)
    (concentrate yes)
    (uneasy_unrealistically yes)
    (muscle_feel_tight yes)
    (afraid_crowd yes)
    (fear_not_realistic yes)
    (trigger_headache yes)
    (trigger_intense_anxiety yes)
    =>
    (printout t crlf)
        (printout t "Solution:")
        (printout t crlf)
        (printout t "You have phobia disorder! Please refer specialist now!!!")
        (printout t crlf crlf)
        (assert (disorder phobia)))
;   (halt))

(defrule MAIN::s-4-adult-adoles
    (have-anxiety yes)
    (experience yes)
    (or (age 1)
        (age 2))
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy yes)
    (concentrate yes)
    (uneasy_unrealistically yes)
    (muscle_feel_tight yes)
    (control_worry yes)
    (how_long 2)
    =>
    (printout t crlf)
        (printout t "Solution:")
        (printout t crlf)
        (printout t "You have generalized anxiety disorder! Please refer specialist now!!!")
        (printout t crlf crlf)
        (assert (disorder generalized-anxiety)))
;   (halt))


(defrule MAIN::s-4-kid
    (have-anxiety yes)
    (experience-kid yes)
    (age 3)
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy yes)
    (concentrate yes)
    (uneasy_unrealistically yes)
    (muscle_feel_tight yes)
    (control_worry yes)
    (how_long 2)
    =>
    (printout t crlf)
        (printout t "Solution:")
        (printout t crlf)
        (printout t "You have generalized anxiety disorder! Please refer specialist now!!!")
        (printout t crlf crlf)
        (assert (disorder generalized-anxiety)))
;   (halt))

(defrule MAIN::s-5
    (have-anxiety yes)
    (or (age 2)
        (age 3))
    (heart_palpitation no)
    (major_attachment_figures no)
    (avoid_social yes)
    (fear_social yes)
    (fear_humiliation yes)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have social anxiety disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder social-anxiety)))
;   (halt))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;FEEDBACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defrule MAIN::feedback-have-disorder
    (or (disorder panic)
        (disorder separation-anxiety)
        (disorder phobia)
        (disorder generalized-anxiety)
        (disorder social-anxiety))
    =>
    (printout t crlf)
    (printout t "Do you satisfied with the system ?" crlf)
    (printout t "Rate: (1)-Disatisfied")
    (printout t "      (2)-Normal")
    (printout t "      (3)-Satisfied" crlf crlf)
    (assert (feedback (number-valid "Feedback answer : ")))
    (printout t crlf crlf "Thank you, have a nice day!" crlf))

(defrule feedback-no-disorder
    (declare (salience -10000))
    (or (and    (not    (disorder panic|separation-anxiety|phobia|generalized-anxiety|social-anxiety))
        (have-anxiety no))
        (and    (not    (disorder panic|separation-anxiety|phobia|generalized-anxiety|social-anxiety))
        (have-anxiety yes)))
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)       
    (printout t "You have no disorder")
    (printout t crlf crlf)
    (assert (no-disorder yes))

    (printout t crlf)
    (printout t "Do you satisfied with the system ?" crlf)
    (printout t "Rate: (1)-Disatisfied")
    (printout t "      (2)-Normal")
    (printout t "      (3)-Satisfied" crlf crlf)
    (assert (feedback (number-valid "Feedback answer : ")))
    (printout t crlf crlf "Thank you, have a nice day!" crlf))

更新

假设我创建了一个名为 generalized-anxiety-list 的新定义模板,我只想在其中存储广泛性焦虑症状。然后我创建一个新的 defrule 来检查是否只有广泛性焦虑的症状:

    (defrule check-s-5
;all these symptoms MUST be a condition
    (symptom (name have-anxiety) (value yes))
    (symptom (name heart-palpitation) (value no))
    (symptom (name major-attachment-figures) (value no))
    (symptom (name avoid-social) (value yes))
    (symptom (name fear-social) (value yes))
    (symptom (name fear-humiliation) (value yes))
    =>
    (assert (generalized-anxiety-list (generalized-anxiety-names

我被困在这里。我如何在广义焦虑列表中断言这些症状?

更新

我创建了一个名为 count-all 的新 deftemplate 来计算所有带有 yes 和 no 值的症状。只要用户输入问题的新答案,它就会将症状的名称存储在count-all中。

(deftemplate count-all
    (multislot names))

(defrule new-count-all
        (symptom (name ?name))
        =>
        (assert (count-all (names ?name))))
    
    (defrule add-to-count-all
        (symptom (name ?name))
        ?sl <- (count-all (names $?names&~:(member$ ?name ?names)))
        =>
        (modify ?sl (names ?names ?name)))

标签: clips

解决方案


创建一个 deftemplate 用于一般地表示症状(或响应或任何您想称呼它们的名称):

         CLIPS (6.4 2/9/21)
CLIPS> 
(deftemplate symptom
   (slot name)
   (slot value))   
CLIPS>  

添加一个 deftemplate 和规则来收集所有共享一个共同值的症状:

CLIPS>    
(deftemplate symptom-list
   (multislot names)
   (slot value))
CLIPS>    
(defrule new-symptom-list
   (symptom (name ?name)
            (value ?value))
   (not (symptom-list (value ?value)))
   =>
   (assert (symptom-list (names ?name) (value ?value))))
CLIPS>    
(defrule add-to-symptom-list
   (symptom (name ?name)
            (value ?value))
   ?sl <- (symptom-list (names $?names&~:(member$ ?name ?names)) 
                        (value ?value))
   =>
   (modify ?sl (names ?names ?name)))
CLIPS> 

修改现有规则以使用新的症状 deftemplate:

CLIPS>    
(deffunction ask-question (?question $?allowed-values)
   (printout t ?question)
   (bind ?answer (read))
   (if (lexemep ?answer) 
       then (bind ?answer (lowcase ?answer)))
   (while (not (member$ ?answer ?allowed-values)) do
      (printout t ?question)
      (bind ?answer (read))
      (if (lexemep ?answer) 
          then (bind ?answer (lowcase ?answer))))
   ?answer)
CLIPS> 
(deffunction yes-or-no-p (?question)
   (bind ?response (ask-question ?question yes no y n))
   (if (or (eq ?response yes) (eq ?response y))
       then yes 
       else no))
CLIPS> 
(defrule start
    (declare (salience 10))
    =>
    (printout t crlf crlf)
    (printout t "Anxiety Diagnosis Expert System")
    (printout t crlf crlf)
    (assert (symptom (name have-anxiety)
                     (value (yes-or-no-p "Do you have an excessive anxiety and worry?: ")))))
CLIPS> 
(defrule f-3
    (symptom (name have-anxiety) (value yes))
    =>
    (assert (symptom (name heart_palpitation) (value (yes-or-no-p "Heart palpitation?: ")))))
CLIPS> 
(defrule f-4
    (symptom (name have-anxiety) (value yes))
    (symptom (name heart_palpitation) (value yes))
    =>
    (assert (symptom (name excess_sweating) (value (yes-or-no-p "Excessive sweating?: ")))))
CLIPS> 
(defrule f-5
    (symptom (name have-anxiety) (value yes))
    (symptom (name heart_palpitation) (value yes))
    =>
    (assert (symptom (name body_trembling) (value (yes-or-no-p "Trembling on some parts of body?: ")))))
CLIPS>

现在,当您运行程序时,症状列表事实将具有具有相同值的症状集合:

CLIPS> (reset)
CLIPS> (run)


Anxiety Diagnosis Expert System

Do you have an excessive anxiety and worry?: yes
Heart palpitation?: yes
Excessive sweating?: no
Trembling on some parts of body?: yes
CLIPS> (facts)
f-1     (symptom (name have-anxiety) (value yes))
f-2     (symptom-list (names have-anxiety heart_palpitation body_trembling) (value yes))
f-3     (symptom (name heart_palpitation) (value yes))
f-4     (symptom (name excess_sweating) (value no))
f-5     (symptom-list (names excess_sweating) (value no))
f-6     (symptom (name body_trembling) (value yes))
For a total of 6 facts.
CLIPS>

您现在可以编写规则,其中操作或条件检索具有相似值的症状计数:

CLIPS> 
(defrule count-yes-symptoms
   (symptom-list (names $?names) (value yes))
   =>
   (println "Number of symptoms with value yes = " (length$ ?names)))
CLIPS> (run)
Number of symptoms with value yes = 3
CLIPS>

推荐阅读