Лични средства
Вие сте тук: Начало Members marian's Home Експертни системи Примери и упражнения Пример за евристична класификация

Пример за евристична класификация

— Plain Text, 2Kb

Съдържание на файла

;; A CLIPS ruleset which attempts to mirror 
;; the definition of an assault weapon. 

;; DECLARATIONS

(deftemplate gun
 (slot name (type SYMBOL))
 (slot class (type SYMBOL))
 (slot action (type SYMBOL))
 (slot caliber (type FLOAT))
 (slot capacity (type INTEGER))
 (slot feature (type SYMBOL))
)

(deftemplate assault-weapon
 (slot name (type SYMBOL))
)

;; FACTS

 (deffacts guns
 (gun (name Browning22) (class rifle) (action semi) (caliber .22)   	
		(capacity 11))
 (gun (name CobrayM11) (class pistol) (action semi) (caliber 9.0) 	
		(capacity 30))
 (gun (name HK91) (class rifle) (action semi) (caliber .308)
		(capacity 20))
 (gun (name Glock17) (class pistol) (action semi) (caliber 9.0) 		
		(capacity 17))
 (gun (name Mossberg500) (class shotgun) (action slide)
		(caliber .410) (capacity 5) (feature pistol-grip))
 (gun (name BenelliSuper90) (class shotgun) (action semi)
		(caliber 12.0) (capacity 5) (feature barrel-shroud))
)

;; RULES

;; The general case

;; Any semi-automatic rifle or shotgun with a capacity of
;; more than 5 rounds

(defrule Part1
 (gun (name ?N) (class ?C&rifle|shotgun) (action semi)
  (capacity ?X&:(> ?X 5)))
 =>
 (assert (assault-weapon (name ?N)))
)

;; Any semi-automatic rifle or shotgun with an offending feature

(defrule Part2
 (gun (name ?N) (class ?C&rifle|shotgun) (action semi)
  (feature ?F&flash-suppressor|barrel-shroud|night-scope))
 =>
 (assert (assault-weapon (name ?N)))
)

;; Any pistol-grip shotgun

(defrule Part3
 (gun (name ?N) (class shotgun) (feature pistol-grip))
 =>
 (assert (assault-weapon (name ?N)))
)

;; Specific cases

;; A Cobray M11 is an assault weapon

(defrule cobray
 =>
 (assert (assault-weapon (name CobrayM11)))
)

;; Exceptions

;; No rimfire rifle is an assault weapon

(defrule rimfire
 ?except <- (gun (name ?N) (class rifle) (caliber .22))
 ?mistake <- (assault-weapon (name ?N))
 =>
 (retract ?mistake)
 (retract ?except)
)

;; No slide-action shotgun is an assault weapon
;; Insert a rule called slide here

(defrule slide
 ?except <- (gun (name ?N) (class shotgun) (action slide))
 ?mistake <- (assault-weapon (name ?N))
 =>
 (retract ?mistake)
 (retract ?except)
)

Действия към документ