Главная страница Случайная страница КАТЕГОРИИ: АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника |
Пример 9.9. Правила determine-low-output и determine-point-surface-state
(defrule determine-low-output " " (working-state engine unsatisfactory) (not (symptom engine low-output | not-low-output)) (not (repair?)) => (if (yes-or-no-p " Is the output of the engine low (yes/no)? ") then (assert (symptom engine low-output)) else (assert (symptom engine not-low-output))) ) (defrule determine-point-surface-state " " (or (and (working-state engine does-not-start) (spark-state engine irregular-spark)) (symptom engine low-output)) (not (repair?)) => (bind? response (ask-question " What is the surface state of the points (normal /burned /contaminated)? " normal burned contaminated)) (if (eq? response burned) then (assert (repair " Replace the points.")) else (if (eq? response contaminated) then (assert (repair " Clean the points.")))) )
Правило determine-low-output определяет, имеет ли место низкая мощность двигателя или нет. Правило determine-point-surface-state адекватно реагирует на условия, заданные в правилах 7 и 12. Обратите внимание на использование условных элементов or и and, которые обеспечивают одинаковое поведение правила в двух абсолютно разных ситуациях. Кроме того, правило determine-point-surface-state отличается от приведенных ранее тем, что непосредственно использует функцию ask-question, вместо yes-or-no-p, т. к. в данный момент пользователю задается вопрос, подразумевающий три варианта ответа. Реализация оставшихся диагностических правил (8—11) также не должна вызвать у вас затруднений. Пример 9.10. Оставшиеся диагностические правила (defrule determine-conductivity-test " " (working-state engine does-not-start) (spark-state engine does-not-spark) (charge-state battery charged) (not (repair?)) => (if (yes-or-no-p " Is the conductivity test for the ignition coil positive(yes/no)? ") then (assert (repair " Repair the distributor lead wire.")) else (assert (repair " Replace the ignition coil."))) ) (defrule determine-sluggishness " " (working-state engine unsatisfactory) (not (repair?)) => (if (yes-or-no-p " Is the engine sluggish (yes/no)? ") then (assert (repair " Clean the fuel line.")))) (defrule determine-misfiring " " (working-state engine unsatisfactory) (not (repair?)) (if (yes-or-no-p " Does the engine misfire (yes/no)? ") then (assert (repair " Point gap adjustment.")) (assert (spark-state engine irregular-spark))) ) (defrule determine-knocking " " (working-state engine unsatisfactory) (not (repair?)) => (if (yes-or-no-p " Does the engine knock (yes/no)? ") then (assert (repair " Timing adjustment."))) )
|