病気の確実性係数を計算するためにすべての患者の症状を数えようとしていますが、各病気の症状は 1 つだけです。
また、結果にはいくつかの重複が表示されます。
確実性係数は、患者の症状の数/病気の症状の合計です。
start:-
write('Enter the name of the patient: '), read(Patient),
write('Enter the symptoms: '), read(Symptoms), write('\n'),
countSint(Diseases, Symptoms , Patient).
countSint(Diseases, Symptoms , Patient) :-
findall(Sint , member(Sint, Symptoms), L1), length(L1 , Size),
( Size < 2
-> writeln('Enter with at least 3 symptoms...\n'), start
; Size > 1
-> write('\n Enter semicolon...:\n\n'), write('Patient: '), write(Patient),
diagnose(Symptoms,Diseases, L)
).
diagnose(Symptoms,Diseases,L) :- search(Symptoms, Diseases, L).
% disease(Disease, Symptoms, Num).
disease(meningitis,[fever, stiff_neck],2).
disease(dengue,[fever, vomiting, red_spots], 3).
% search(Symptoms, Diseases, L).
search([H|T] , Diseases, L) :-
disease(Disease, Symptoms, Num),
Disease0 = [Disease,Diseases],
member(H, Symptoms),
search(T , Diseases0, L),
write('has '), write(Disease), writeln(': '),
setof(H, (disease(Disease, Symptoms, Num),
member(H, Symptoms)), L),
length(L, Size),
calc_cf(Num, Size, R).
calc_cf(Num, Size, R):- % Calculate the certainty factor
R is Size / Num * 100,
write('The certainty factor is '),
write(R),
writeln('%').
誰か助けてくれませんか?