4.
WAP in turbo prolog for medical diagnosis and show the advantages and
disadvantages of green and red cuts.
SWI Prolog Code:
% --- Facts ---
symptom('Flu').
symptom('Yellowish eyes and skin').
symptom('Dark color urine').
symptom('Pale bowel movement').
symptom('Fatigue').
symptom('Vomitting').
symptom('Fever').
symptom('Pain in joints').
symptom('Weakness').
symptom('Stomach Pain').
treatment('Flu', 'Drink hot water, avoid cold eatables.').
treatment('Yellowish eyes and skin', 'Put eye drops, have healthy sleep, do not
strain your eyes.').
treatment('Dark color urine', 'Drink lots of water, juices and eat fruits. Avoid
alcohol consumption.').
treatment('Pale bowel movement', 'Drink lots of water and exercise regularly.').
treatment('Fatigue', 'Drink lots of water, juices and eat fruits.').
treatment('Vomitting', 'Drink salt and water.').
treatment('Fever', 'Put hot water cloth on head and take crocin.').
treatment('Pain in joints', 'Apply pain killer and take crocin.').
treatment('Weakness', 'Drink salt and water, eat fruits.').
treatment('Stomach Pain', 'Avoid outside food and eat fruits.').
:- dynamic(patient/2).
% --- Input loop ---
input :-
retractall(patient(_,_)),
ask_all_symptoms,
output.
ask_all_symptoms :-
symptom(X),
write('Does the patient have '), write(X), write(' (yes/no)? '),
read(Y),
assertz(patient(X,Y)),
X \= 'Stomach Pain',
fail.
ask_all_symptoms. % when fail finishes, this succeeds once
% --- Disease rules (using \+ instead of not/1) ---
disease(hemochromatosis) :-
patient('Stomach Pain',yes),
patient('Pain in joints',yes),
patient('Weakness',yes),
patient('Dark color urine',yes),
patient('Yellowish eyes and skin',yes).
disease(hepatitis_c) :-
\+ disease(hemochromatosis),
patient('Pain in joints',yes),
patient('Fever',yes),
patient('Fatigue',yes),
patient('Vomitting',yes),
patient('Pale bowel movement',yes).
disease(hepatitis_b) :-
\+ disease(hemochromatosis),
\+ disease(hepatitis_c),
patient('Pale bowel movement',yes),
patient('Dark color urine',yes),
patient('Yellowish eyes and skin',yes).
disease(hepatitis_a) :-
\+ disease(hemochromatosis),
\+ disease(hepatitis_c),
\+ disease(hepatitis_b),
patient('Flu',yes),
patient('Yellowish eyes and skin',yes).
disease(jaundice) :-
\+ disease(hemochromatosis),
\+ disease(hepatitis_c),
\+ disease(hepatitis_b),
\+ disease(hepatitis_a),
patient('Yellowish eyes and skin',yes).
disease(flu) :-
\+ disease(hemochromatosis),
\+ disease(hepatitis_c),
\+ disease(hepatitis_b),
\+ disease(hepatitis_a),
patient('Flu',yes).
% --- Output ---
output :-
nl,
possible_diseases,
nl,
advice.
possible_diseases :-
( disease(X),
write('The patient may suffer from '), write(X), nl,
fail
; true
).
advice :-
symptom(X),
patient(X,yes),
treatment(X,Y),
write(Y), nl,
X \= 'Stomach Pain',
fail.
advice.
OUTPUT:
?- input.
Does the patient have Flu (yes/no)? yes.
Does the patient have Yellowish eyes and skin (yes/no)? |: yes.
Does the patient have Dark color urine (yes/no)? |: yes.
Does the patient have Pale bowel movement (yes/no)? |: yes.
Does the patient have Fatigue (yes/no)? |: yes.
Does the patient have Vomitting (yes/no)? |: no.
Does the patient have Fever (yes/no)? |: no.
Does the patient have Pain in joints (yes/no)? |: no.
Does the patient have Weakness (yes/no)? |: no.
Does the patient have Stomach Pain (yes/no)? |: no.
The patient may suffer from hepatitis_b
Drink hot water, avoid cold eatables.
Put eye drops, have healthy sleep, do not strain your eyes.
Drink lots of water, juices and eat fruits. Avoid alcohol consumption.
Drink lots of water and exercise regularly.
Drink lots of water, juices and eat fruits.
true.