:- use_module(library(jpl)). start :-sleep(0.4), write('---------------------------------------'),nl, sleep(0.4), write('***************************************'),nl, sleep(0.2), write('#########||| Expert System |||################'),nl, sleep(0.4), write('***************************************'),nl, sleep(0.4), write('---------------------------------------'),nl,nl,nl, /*write("Hi, How are you? May I know your name please?: "), read(patient),*/ interface2. /*hypothesis(patient,disease), write(patient),write(', you'),write(' probably have '),write(disease),write('.'),undo, nl,nl,nl, sleep(0.7), write('***************************************'),nl, sleep(0.4), write('#########||| Thanks for visiting. Have a good day!. |||################'),nl, sleep(0.4), write('***************************************'),nl.*/ symptom(patient,fever) :- verify(patient," have a fever (y/n) ?"). symptom(patient,rash) :- verify(patient," have a rash (y/n) ?"). symptom(patient,headache) :- verify(patient," have a headache (y/n) ?"). symptom(patient,runny_nose) :- verify(patient," have a runny_nose (y/n) ?"). symptom(patient,conjunctivitis) :- verify(patient," have a conjunctivitis (y/n) ?"). symptom(patient,cough) :- verify(patient," have a cough (y/n) ?"). symptom(patient,body_ache) :- verify(patient," have a body_ache (y/n) ?"). symptom(patient,chills) :- verify(patient," have a chills (y/n) ?"). symptom(patient,sore_throat) :- verify(patient," have a sore_throat (y/n) ?"). symptom(patient,sneezing) :- verify(patient," have a sneezing (y/n) ?"). symptom(patient,swollen_glands) :- verify(patient," have a swollen_glands (y/n) ?"). /*symptom(_,"Sorry, I couldn't diagnose the disease.").*/ hypothesis(patient,measles) :- symptom(patient,fever), symptom(patient,cough), symptom(patient,conjunctivitis), symptom(patient,runny_nose), symptom(patient,rash). hypothesis(patient,german_measles) :- symptom(patient,fever), symptom(patient,headache), symptom(patient,runny_nose), symptom(patient,rash). hypothesis(patient,flu) :- symptom(patient,fever), symptom(patient,headache), symptom(patient,conjunctivitis), symptom(patient,runny_nose), symptom(patient,body_ache), symptom(patient,chills), symptom(patient,cough), symptom(patient,sore_throat). hypothesis(patient,common_cold) :- symptom(patient,headache), symptom(patient,sneezing), symptom(patient,sore_throat), symptom(patient,runny_nose), symptom(patient,chills). hypothesis(patient,mumps) :- symptom(patient,fever), symptom(patient,swollen_glands). hypothesis(patient,chicken_pox) :- symptom(patient,fever), symptom(patient,chills), symptom(patient,body_ache), symptom(patient,rash). hypothesis(patient,measles) :- symptom(patient,cough), symptom(patient,sneezing), symptom(patient,runny_nose). hypothesis(_,"disease. But I'm sorry. I couldn't diagnose the disease"). response(reply) :- read(reply), write(reply),nl. ask(patient,question) :- write(patient),write(', do you'),write(question), /*read(N), ( (N==yes; N==y) -> assert(yes(question)); assert(no(question)), fail),*/ interface(', do you',patient,question), write('Loading.'),nl, sleep(1), write('Loading..'),nl, sleep(1), write('Loading...'),nl, sleep(1),nl. :- dynamic yes/1,no/1. verify(P,S) :- (yes(S) -> true ; (no(S) -> fail; ask(P,S))). undo :- retract(yes(_)),fail. undo :- retract(no(_)),fail, undo. pt(patient):- hypothesis(patient,disease), interface3(patient,', you probably have ',disease,'.'), write(patient),write(', you probably haave '),write(disease),write('.'),undo,end. end :- nl,nl,nl, sleep(0.7), write('***************************************'),nl, sleep(0.4), write('#########||| Thanks for visiting. Have a good day!. |||################'),nl, sleep(0.4), write('***************************************'),nl. interface(X,Y,Z) :- atom_concat(Y,X, FAtom), atom_concat(FAtom,Z,FinalAtom), jpl_new('javax.swing.JFrame',['Expert System'], F), jpl_new('javax.swing.JLabel',['--- MEDICAL EXPERT SYSTEM ---'],LBL), jpl_new('javax.swing.JPanel',[],Pan), jpl_call(Pan,add,[LBL],_), jpl_call(F,add,[Pan],_), jpl_call(F, setLocation, [400,300], _), jpl_call(F, setSize, [400,300], _), jpl_call(F, setVisible, [@(true)], _), jpl_call(F, toFront, [], _), jpl_call('javax.swing.JOptionPane', showInputDialog, [F,FinalAtom], N), jpl_call(F, dispose, [], _), write(N),nl, ( (N == yes ; N == y) -> assert(yes(Z)); assert(no(Z)), fail). interface2 :- jpl_new('javax.swing.JFrame',['Expert System'], F), jpl_new('javax.swing.JLabel',['--- MEDICAL EXPERT SYSTEM ---'],LBL), jpl_new('javax.swing.JPanel',[],Pan), jpl_call(Pan,add,[LBL],_), jpl_call(F,add,[Pan],_), jpl_call(F, setLocation, [400,300], _), jpl_call(F, setSize, [400,300], _), jpl_call(F, setVisible, [@(true)], _), jpl_call(F, toFront, [], _), jpl_call('javax.swing.JOptionPane', showInputDialog, [F,'Hi, How are you? May I know your name please?'], N), jpl_call(F, dispose, [], _), /*write(N),nl,*/ ( (N == @(null) -> write('you cancelled'), interface3('you cancelled. ','Thank you ','for visiting.','Have a good day.'),end,fail ; write("Hi, How are you? May I know your name please?: "),write(N),nl,pt(N) ). interface3(P,W1,D,W2) :- atom_concat(P,W1,A), atom_concat(A,D,B), atom_concat(B,W2,W3), jpl_new('javax.swing.JFrame',['Expert System'], F), jpl_new('javax.swing.JLabel',['--- MEDICAL EXPERT SYSTEM ---'],LBL), jpl_new('javax.swing.JPanel',[],Pan), jpl_call(Pan,add,[LBL],_), jpl_call(F,add,[Pan],_), jpl_call(F, setLocation, [400,300], _), jpl_call(F, setSize, [400,300], _), jpl_call(F, setVisible, [@(true)], _), jpl_call(F, toFront, [], _), jpl_call('javax.swing.JOptionPane', showMessageDialog, [F,W3], N), jpl_call(F, dispose, [], _), /*write(N),nl*/ ( N == @(void) -> write('') ; write("") ). help :- write("To start the expert system please type 'start.' and press the enter key").