next up previous
Next: 後ろ向き推論 Up: 2 プロダクションシステム Previous: 2.10 実行例(2)

2.11 実行例(3)

ゴールがない例で,発火ルールがなくなって終了する例を示す.
(defun rule-demo3 (&optional *verbose*)
  (set-up-rules
   'animal
   '((rule1      (?x has feathers)
                ==> (?x is a bird))
     (rule2     (?x flies) (?x lays eggs)
                ==> (?x is a bird))
     (rule3     (?x has hair)
                ==> (?x is a mammal))
     (rule4     (?x gives milk)
                ==> (?x is a mammal))
     (rule5     (?x eats meat)
                ==> (?x is a carnivore))
     (rule6     (?x has pointed teeth)
                (?x has claws)
                (?x has forward eyes)
                ==> (?x is a carnivore))
     (rule7     (?x is a mammal)
                (?x has foofs)
                ==> (?x is an ungulate))
     (rule8     (?x is a mammal)
                (?x chews cud)
                ==> (?x is an ungulate))
     (rule9     (?x is a mammal)
                (?x is a carnivore)
                (?x has tawny color)
                (?x has dark spots)
                ==> (?x is a cheetah))
     (rule10    (?x is a mamal)
                (?x is a carnivore)
                (?x has tawny color)
                (?x has black stripes)
                ==> (?x is a tiger))
     (rule11    (?x is an ungulate)
                (?x has long neck)
                (?x has long legs)
                (?x has dark spots)
                ==> (?x is a giraffe))
     (rule12    (?x is an ungulate)
                (?x has black stripes)
                ==> (?x is a zebra))
     (rule13    (?x is a bird)
                (?x does not fly)
                (?x has long neck)
                (?x has long legs)
                (?x is black and white)
                ==> (?x is an ostrich))
     (rule14    (?x is a bird)
                (?x does not fly)
                (?x swims)
                (?x is black and white)
                ==> (?x is a penguin))
     (rule15    (?x is a bird)
                (?x flies well)
                ==> (?x is an albatross))
     (rule16    (?x is a ?y)
                (?x is a parent of ?z)
                ==> (?z is a ?y))
     ))
  (setf *wmcq*
        '((robbie has dark spots)
          (robbie has tawny color)
          (robbie eats meat)
          (robbie has hair)
          (suzie has feathers)
          (suzie flies well)))
  (ps 'animal *wmcq* nil)
  )
このような場合は,現在わかっている事実の知識(作業記憶として与えられる) から,知識として知っているルールをもとに推論できる事実をできるかぎり拾 い出すという処理になる.
> (rule-demo3 t)

0: rule RULE1 adds (SUZIE IS A BIRD). 
  FIND-FIRST effects.
    (RULE1 RULE3 RULE5) -> RULE1.
1: rule RULE3 adds (ROBBIE IS A MAMMAL). 
  FIREABLE-RULES effects.
   (RULE1 RULE3 RULE5 RULE15)
              -> (RULE3 RULE5 RULE15).
  FIND-FIRST effects.
   (RULE3 RULE5 RULE15) -> RULE3.
2: rule RULE5 adds (ROBBIE IS A CARNIVORE). 
  FIREABLE-RULES effects.
   (RULE1 RULE3 RULE5 RULE15)
              -> (RULE5 RULE15).
  FIND-FIRST effects.
    (RULE5 RULE15) -> RULE5.
3: rule RULE9 adds (ROBBIE IS A CHEETAH). 
  FIREABLE-RULES effects.
    (RULE1 RULE3 RULE5 RULE9 RULE15)
              -> (RULE9 RULE15).
  FIND-FIRST effects.
    (RULE9 RULE15) -> RULE9.
4: rule RULE15 adds (SUZIE IS AN ALBATROSS). 
  FIREABLE-RULES effects.
    (RULE1 RULE3 RULE5 RULE9 RULE15)
              -> (RULE15).
  FIND-FIRST effects.
    (RULE15) -> RULE15.
Rule Interpreter Halted
No Rules Fired
Here are contents of working memory: 
((SUZIE IS AN ALBATROSS)
 (ROBBIE IS A CHEETAH)
 (ROBBIE IS A CARNIVORE)
 (ROBBIE IS A MAMMAL)
 (SUZIE IS A BIRD)
 (ROBBIE HAS DARK SPOTS)
 (ROBBIE HAS TAWNY COLOR)
 (ROBBIE EATS MEAT)
 (ROBBIE HAS HAIR)
 (SUZIE HAS FEATHERS)
 (SUZIE FLIES WELL))
NIL
推論により判明した事実すべてが作業記憶のなかに保存されている.

generated through LaTeX2HTML. M.Inaba 平成18年5月7日