next up previous contents
Next: A Simple Expert System: Up: Example: Forward- and Backward-Chaining Previous: Facts

Queries

Here we ask some questions to get new inferences done. Since both questions are in one path, and since there is only one answer to each question, we get one set of bindings back.

  (ask '((grandfather William ?gf)
         (grandmother William ?gm))
       :comment "Who are William's grandfathers and grandmothers?")

QUERYING:  Who are William's grandfathers and grandmothers?

 Result:
   Bindings:            ?gm    --- elizabeth "[elizabeth]"
                        ?gf    --- philip "[philip]"
                       
  => T

Here's a similar inference.

  (ask '((uncle William ?u)
         (aunt William ?v))
       :comment "Who are William's aunts and uncles?")

QUERYING:  Who are William's aunts and uncles?

 Result:
   Bindings:            ?v     --- sarah "[sarah]"
                        ?u     --- andrew "[andrew]"
                       
  => T

Here the question has two answers, so we get two bindings back.

  (ask '((parent William ?u))
       :comment "Who are William's parents?")

QUERYING:  Who are William's parents?

 Result (1 of 2):
   Binding:             ?u     --- diana "[diana]"
                       
 Result (2 of 2):
   Binding:             ?u     --- charles "[charles]"
                       
  => T

In the following, we use a special form, :all-paths, which succeeds if all sets of bindings that result from the first path, also satisfy the second access path.

  (ask '((:all-paths ((child Charles ?b)) ((gender ?b male))))
       :comment "Are all Charles' children male?")

QUERYING:  Are all Charles' children male?

  => T

  (ask '((:all-paths ((child Charles ?b)) ((gender ?b female))))
       :comment "Are all Charles' children female?")
  
QUERYING:  Are all Charles' children female?

 *Query failed.*

  => NIL



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