next up previous
Next: 2.4 作業記憶 Up: 2 プロダクションシステム Previous: 2.2 プロダクションルールの表現

2.3 ルールの保存

  (set-up-rules
   'c+q
   '((rule1     (?x is a woman)
                ==> (?x is human))
     (rule2     (?x is a man)
                ==> (?x is human))
     (rule3     (?x is human)
                ==> (?x is a carnivore))
     (rule4     (?x is human)
                (?x eats meat)
                ==> (?x is a carnivore))
     (rule5     (?x is human)
                (?x eats vegetables)
                ==> (?x is a vegetarian))
     (rule6     (?x is a carnivore)
                ==> (?x is a living-thing))
     (rule7     (?x is a vegetarian)
                ==> (?x is a living-thing))))
set-up-rulesは以下のように*rules*のruleset-name属性に各ルール名のリス トが入ります. 個々のルールの条件部,行動部はルール名のシンボルのantecedent 属性,および,concequent属性に保存されます(store-rule).

(defvar *rules* nil
  "Holds the ruleset to the interpreted.")
(defun set-up-rules (ruleset-name rules)
  (setf (get '*rules* ruleset-name)
        (mapcar #'store-rule rules)))

(defun store-rule (rule)
  (let ((pos
         (position '==> rule :test #'eq)))
    (setf (get (car rule) 'consequent)
          (subseq rule (+ 1 pos)))
    (setf (get (car rule) 'antecedent)
          (subseq rule 1 pos))
    (car rule)))
ルールからデータをとってくる関数をつくっておきます.

(defun antecedent (rule) (get rule 'antecedent))
(defun consequent (rule) (get rule 'consequent))

next up previous
Next: 2.4 作業記憶 Up: 2 プロダクションシステム Previous: 2.2 プロダクションルールの表現
generated through LaTeX2HTML. M.Inaba 平成18年5月21日