next up previous contents
Next: Calling Lisp and the Up: A Simple Expert System: Previous: Rules - Slightly Less

Queries - Slightly Less Simple Rules

Diagnosing the same three patients, we get the same diagnoses, but the order of questions is somewhat different, determined by the way the symptoms are stored in the symptom slot of the disease frames.

> (dx-patient 'frank)
 Is it true that (has-symptom frank nodules)?  (Yes or No) no
 Is it true that (has-symptom frank nausea)?  (Yes or No) yes
 Give me a value for ?t in (temperature frank ?t): 100
  ((FRANK HAS FLU))

> (dx-patient 'george)
 Is it true that (has-symptom george nodules)?  (Yes or No) yes
 Give me a value for ?t in (temperature george ?t): 103
 Is it true that (has-symptom george nausea)?  (Yes or No) no
  ((GEORGE HAS PLAGUE))

> (dx-patient 'harry)
 Is it true that (has-symptom harry nodules)?  (Yes or No) yes
 Give me a value for ?t in (temperature harry ?t): 104
 Is it true that (has-symptom harry nausea)?  (Yes or No) yes
  ((HARRY HAS PLAGUE) (HARRY HAS FLU))

The rules contained explicit sequencing information that guaranteed that Frank was not asked about nodules after his relatively low fever made that question irrelevant. A different ordering of the disease descriptions gives a better order of questions, and eliminates the irrelevant question, but storage order within a slot is not a semantic property of the knowledge base, and cannot be relied on. Methods for ensuring a desired sequence will be discussed in section 6.

For comparison with the previous trace, here is a trace of Harry's diagnosis, using the slightly less verbose ``Trace Interesting'' mode.

algy> ti
  Trace level = :BASIC.

algy> (dx-patient 'harry)

  ** Beginning basic Trace **
 Creating new frame: harry.
 Inserting new value (isa harry things). 
 Inserting new value (name harry "harry"). 
 Inserting new value (isa harry people). 
   Applying: ((isa harry people) -> (isa harry objects)).
     Inserting new value (isa harry objects). 
       Applying: ((isa harry objects) -> (isa harry things)).
       Rule applied.
   Rule applied.
   Applying: ((isa harry people) -> (isa harry physical-objects)).
     Inserting new value (isa harry physical-objects). 
       Applying: ((isa harry physical-objects) -> (isa harry objects)).
       Rule applied.
   Rule applied.
 Creating new frame: ri-13.
 Applying: ((has-disease harry ?d) <- (member diseases ?d) 
                                     (:all-paths ((symptom ?d ?s)) 
                                                 ((has-symptom harry ?s)))).
   Inserting new value (query-queue set-partition (member diseases ?d)). 
   Creating new frame: ri-14.
   Applying: ((has-symptom harry nodules) <- (:ask (has-symptom harry nodules))). 
 Is it true that (has-symptom harry nodules)?  (Yes or No) yes
     Inserting new value (has-symptom harry nodules). 
   Rule applied.
   Creating new frame: ri-15.
   Applying: ((has-symptom harry high-fever) <- (temperature harry ?t) 
                                               (:test (> ?t 102))).
     Creating new frame: ri-16.
     Applying: ((temperature harry ?t) <- (:ask (temperature harry ?t))).
 Give me a value for ?t in (temperature harry ?t): 104
       Inserting new value (temperature harry 104). 
     Rule applied.
     Inserting new value (has-symptom harry high-fever). 
   Rule applied.
   Creating new frame: ri-17.
   Applying: ((has-symptom harry nausea) <- (:ask (has-symptom harry nausea))).
 Is it true that (has-symptom harry nausea)?  (Yes or No) yes
     Inserting new value (has-symptom harry nausea). 
   Rule applied.
   Creating new frame: ri-18.
   Applying: ((has-symptom harry fever) <- (temperature harry ?t) 
                                          (:test (> ?t 99))).
     Inserting new value (has-symptom harry fever). 
   Rule applied.
   Inserting new value (has-disease harry plague). 
   Inserting new value (has-disease harry flu). 
 Rule applied.
  ** End basic Trace **
  ((HARRY HAS PLAGUE) (HARRY HAS FLU))



Micheal S. Hewett
Tue Oct 29 10:54:13 CST 1996