Итак, у нас есть проект, в котором нам нужно создать экспертную систему, которая, предоставляя сведения о некоторых автомобилях, выбирает наиболее подходящую для пользователя.
Прежде всего, в классе мы узнали мелочи о клипах, таких как deftemplate, deffacts и defrule. Ничего лишнего (!!!) Так что мой проект, я думаю, не может содержать код вроде модулей или функций.
Во-вторых, согласно приведенным данным, код должен быть таким, который я пишу далее.
Дело в том, что: 1. Другого пути, кроме (отзыва), мы не научились. 2. Если я прав: 2а. Есть ли способ найти в моем коде то, что нужно отозвать, и чтобы эксперт не записывал не относящиеся к делу факты? 2b. что я должен написать, чтобы каждый раз приносил результат? (например, если мы укажем семейство типов и высокую цену, у нас не будет руссельта). 2c. есть ли способ, чтобы после этого "метода вычитания" я, хотя, программа печатала, после вопросов, оставшиеся факты, но не с способом "(факты)" ??
спасибо за преимущество.
код:
(deftemplate car_template
(slot brand_name (type STRING))
(slot type (type STRING)(allowed-symbols family city super))
(slot price (type SYMBOL) (allowed-symbols low mid high))
;;; low = 0-10000 mid = 10001-20000 high = 20001-10000
(slot performance (type SYMBOL) (allowed-symbols low mid high))
(slot equipment (type SUMBOL) (allowed-symbols low mid high))
)
(deffacts car_facts
(car (brand_name "Opel Astra")(type family)(price mid)(performance low)
(car (brand_name "Peugeot 106a")(type city)(price low)(performance high)
(car (brand_name "Mercedes E200")(type super)(price high)(performance mid)
(car (brand_name "Rover 25")(type family)(price mid)(performance mid)
(car (brand_name "Ferrari F40")(type super)(price high)(performance high)
)
(defrule type_rule
(initial-fact)
=>
(printout t "Give the Type you want (possible options: family city super): "
(bind ?response (read))
(if (eq ?response family) then
;;;retracting city
(retract 2)
;;;rectarting super
(retract 3 5)
else (if (eq ?response city) then
;;;retracting family
(retract 1 4)
;;;rectarting super
(retract 3 5)
else
;;;retracting city
(retract 2)
;;;retracting family
(retract 1 4)
))))
(defrule price_rule
(initial-fact)
=>
(printout t "Give the price you want (possible options: low mid high): "
(bind ?response (read))
(if (eq ?response low) then
;;;retracting mid
(retract 1 4)
;;;rectarting high
(retract 3 5)
else (if (eq ?response mid) then
;;;retracting low
(retract 2)
;;;rectarting high
(retract 3 5)
else
;;;retracting mid
(retract 1 4)
;;;retracting low
(retract 2)
))))
(defrule performance_rule
(initial-fact)
=>
(printout t "Give the performance you want (possible options: low mid high): "
(bind ?response (read))
(if (eq ?response low) then
;;;retracting mid
(retract 3 4)
;;;rectarting high
(retract 2 5)
else (if (eq ?response mid) then
;;;retracting low
(retract 1)
;;;rectarting high
(retract 2 5)
else
;;;retracting mid
(retract 3 4)
;;;retracting low
(retract 1)
))))
(defrule print_facts
(initial-fact)
=>
(printout t "The car that fits you is: "
(facts)
))