2
我試圖計算所有患者的症狀來計算疾病的確定性因素,但我只是得到每種疾病的一種症狀。
此外,結果顯示了一些重複。
的可信度/患者的症狀的人數佔總數的疾病的症狀:
Prolog - 計算所有患者的症狀
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('%').
誰能幫助我,好嗎?
謝謝回答,CHAC! 我用聚合,但我仍然沒有得到我需要的結果。我需要獲取患者與我的數據庫中每種疾病症狀相同的所有症狀的數量。我不知道我做錯了什麼。 –
@Ítala:編輯你的問題與你的新嘗試,如果你想好的建議! :d – m09
@chac謝謝!這正是我需要:) –