main.clp

; Diagnoser | Expert System task 4cs

;
; run:
; CLIPS> (load C:\PATH_DIR\main.clp)
; CLIPS> (run)


(deffunction print-parts()
	(printout t crlf "--= Diagnoser =--" crlf crlf)
	(printout t "> eye (available)" crlf)
	(printout t "> nose (available)" crlf)
	(printout t "> ear" crlf)
	(printout t "> mouth" crlf)
	(printout t "> shoulder" crlf)
	(printout t "> neck" crlf)
	(printout t "> hand" crlf)
	(printout t "> arm" crlf)
	(printout t "> elbow" crlf)
	(printout t "> waist" crlf)
	(printout t "> stomack" crlf)
	(printout t "> leg" crlf)
	(printout t "> foot" crlf)
	(printout t "Choose part: ")
)

(defglobal  ?*sum* = 0)

; vvvvvvvvvvvvvvvvvv
(defrule START_POINT
	?f <- (initial-fact)
=>
	(load-facts "kb.clp")
	(retract ?f)
	(print-parts)
	(assert (ask-part (read)))
)

(defrule ask-part
	?f <- (ask-part ?part)
	(ask-part ?)
=>
	(printout t "-->> " ?part ":" crlf)
	(assert (ask-questions ?part))
)

(defrule ask-questions
	?f <- (ask-questions ?part)
	?f2 <- (question ?part ?perc $?text)
	(ask-questions ?)
=>
	(printout t $?text " [yes, no] ")
	(bind ?ans (read))
	(if (member$ ?ans (create$ yes) )
		then (bind ?*sum* (+ ?*sum* ?perc))
	)
	(assert (result ?part))
)

(defrule result
	?f <- (result ?part)
	(advice ?part $?text)
	(result ?)
=>
	(retract ?f)
	(if (> ?*sum* 0)
		then 
			(printout t crlf "danger percentage: " ?*sum* "%" crlf)
			(printout t $?text crlf crlf)
		else 
			(printout t crlf "you are ok!" crlf crlf)
	)
)

kb.clp

; Diagnoser | Knowledge base
;
; Expert person(ex. doctor) will add symptoms here


(question nose 50 Is there nose runny?)
(question nose 20 Is there sneezing?)
(question nose 30 is there sore throat?)
; برد - دكتور انف واذن
(advice nose Maybe it's cold go to otolaryngologist doctor)


(question eye 40 Is there friction in the eye?)
(question eye 40 Is eyes are red?)
(question eye 20 Are there tears?)
; التهاب فى العين- دكتور عيون
(advice eye Maybe it's Inflammation go to ophthalmologist doctor)

 
Facebook Comments
Last modified: August 9, 2019