2012-09-01 2 views
2

나는 모든 환자의 증상을 계산하여 그 질병의 확실성을 계산하려고하는데, 나는 각 질병의 증상 하나를 얻고 있습니다.
결과도 일부 중복됩니다.
프롤로그 - 모든 환자의 증상을 조사하십시오.

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('%'). 

사람이 제발 도와 드릴까요 :
확실성 요인은 환자의 증상의 수/질병의 증상의 총인가?

답변

1

이 쓸모없는 것 같다

findall(Sint , member(Sint, Symptoms), L1) 

단순히 L1 등의 증상을 재 작성. 왜? 이 조각에서

것은

( 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) 
) 

다른 대안이 있어야한다.

이 사실 disease(Disease, Symptoms, Num).은 쓸모가 없어야하지만 더 이상 처리하기가 더 어려워지는 언 바운드 변수를 도입합니다.

당신은

countSint(Diseases, Symptoms, Patient) :- 
    aggregate(count, diagnose(Symptoms, Diseases, _), Count), 
    format('diagnosed:~d for:~w~n', [Count, Patient]). 

편집

그것은 프레 젠 테이션에서 별도의 논리에 더처럼 당신이 계산 솔루션을 잘 조작 된 술어를 찾을 라이브러리 (aggregate), 뭔가 살펴보고 고려할 수 , 그리고 여기에 좋은 피드백을 얻으려면 코드에서 쓰기/읽기를 제거하고 대신 당신이 신경 쓰는 몇 가지 예제를 보여줘야한다고 생각합니다. 지금은 내가 당신의 코멘트에서 추측 할 수, 당신이 필요로하는 필수 공식을 보여

disease(meningitis, [fever, stiff_neck]). 
disease(dengue, [fever, vomiting, red_spots]). 

% find diseases from symptoms, sort by certainty factor 
diagnose(Symptoms, Diseases) :- 
    setof(CF-Disease, common_symptoms(Symptoms, Disease, CF), Diseases). 

common_symptoms(Symptoms_Patient, Disease, CF) :- 
    disease(Disease, Symptoms_Disease), 
    intersection(Symptoms_Patient, Symptoms_Disease, Common_Symptoms), 
    length(Common_Symptoms, NCS), 
    length(Symptoms_Disease, NSD), 
    CF is NCS/NSD * 100. 

시험 : CHAC 응답에 대한

?- diagnose([fever, stiff_neck],L). 
L = [33.33333333333333-dengue, 100-meningitis]. 
+0

감사합니다! 집계를 사용했지만 여전히 필요한 결과를 얻지 못하고 있습니다. 환자가 가지고있는 모든 증상의 수를 각 질병에 대한 데이터베이스의 증상과 함께 알아야합니다. 나는 내가 뭘 잘못하고 있는지 모르겠다. –

+1

@ Ítala : 좋은 조언을 원한다면 새로운 시도로 질문을 편집하십시오! : d – m09

+0

@chac 감사합니다! 그게 내가 정확히 필요한거야 :) –