Implementing Diagnosis Problem in Prolog

 predicates

	hypothesis(string,string)
	symptom(string,string)
	response(char)
	go

 clauses
	go:-
		write("What is the patient's name?"),
		readln(Patient),
		hypothesis(Patient,Disease),
		write(Patient," probably has ",Disease,"."),nl.
		
	go:-
		write("Sorry,diagnosis not possible."),nl.
		
	symptom(Patient,headache):-
		write("Does ",Patient," have headache?(y/n)"),
		response(Reply),
		Reply='y'.
		
	symptom(Patient,sneezing):-
		write("Is ",Patient," sneezing?(y/n)"),
		response(Reply),
		Reply='y'.
	
	hypothesis(Patient,commoncold):-
		symptom(Patient,headache),
		symptom(Patient,sneezing).

	response(Reply):-
		readchar(Reply),
		write(Reply),nl.
		
/* Output  

	Goal: go
		What is the patient's name? abc
		Does abc have headache?(y/n)y
		Is abc sneezing?(y/n)y
		abc probably has commoncold.
	
	Goal: go
		What is the patient's name? pqr
		Does abc have headache?(y/n)n
		Sorry,diagnosis not possible
 */

Leave a Reply

Your email address will not be published. Required fields are marked *