code cleanup; minor fixes
This commit is contained in:
parent
99765573ef
commit
0e48d88f07
@ -2,28 +2,57 @@
|
|||||||
% | == disease data base == |
|
% | == disease data base == |
|
||||||
% | ======================= |
|
% | ======================= |
|
||||||
|
|
||||||
disease("flu",[("pain",["throat"]),("runny nose"),("fever",-1),("general weakness"),("cough")],[("pain",["muscles"])]).
|
disease("flu",[("pain",["throat"]),("runny nose"),("fever",-1),("general weakness"),("coughs")],[("pain",["muscles"])]).
|
||||||
disease("malaria",[("fever",2),("general weakness")],[("pain",["head"]),("chills"),("erythrocyte",-1)]).
|
disease("malaria",[("fever",2),("general weakness")],[("pain",["head"]),("chills"),("erythrocyte",-1)]).
|
||||||
disease("angina",[("fever",2),("cough"),("general weakness"),("magnifying lymph nodes"),("pain",["throat"])],[("cannot swallow"),("pain",["head"]),("chills")]).
|
disease("angina",[("fever",2),("coughs"),("general weakness"),("magnifying lymph nodes"),("pain",["throat"])],[("cannot swallow"),("pain",["head"]),("chills")]).
|
||||||
disease("diphtheria",[("fever",1),("general weakness"),("dyspnea")],[("Unclear Speech"),("cannot swallow")]).
|
disease("diphtheria",[("fever",1),("general weakness"),("dyspnea")],[("Unclear Speech"),("cannot swallow")]).
|
||||||
disease("typhoid",[("fever",-1),("pain",["stomach"]),("spleen enlargement")],["tire symptoms"]).
|
disease("typhoid",[("fever",0),("pain",["stomach"]),("spleen enlargement")],["tire symptoms"]).
|
||||||
disease("plague",[("fever",2),("general weakness"),("magnifying lymph nodes"),("liver enlargement"),("spleen enlargement")],[("cloded rash")]).
|
disease("plague",[("fever",2),("general weakness"),("magnifying lymph nodes"),("liver enlargement"),("spleen enlargement")],[("cloded rash")]).
|
||||||
disease("haemophilia",[("epistaxis"),("impaired blood clotting"),("spleen enlargement")],[]).
|
disease("haemophilia",[("epistaxis"),("impaired blood clotting"),("spleen enlargement")],[("fever",0),("fever",1),("fever",2)]).
|
||||||
disease("whooping cough",[("fever",1),("pain",["throat"]),("paroxysmal cough")],[("conjunctivitis"),("vomiting")]).
|
disease("whooping cough",[("fever",1),("pain",["throat"]),("paroxysmal cough")],[("conjunctivitis"),("vomits")]).
|
||||||
disease("myasthenia",[("excessive fatigue")],[("muscle weakness"),("double vision")]).
|
disease("myasthenia",[("excessive fatigue")],[("muscle weakness"),("double vision"),("fever",0),("fever",1),("fever",2)]).
|
||||||
disease("atrial fibrillation",[("dizziness"),("fainting"),("excessive fatigue")],[("cough")]).
|
disease("atrial fibrillation",[("dizziness"),("faints"),("excessive fatigue")],[("coughs"),("fever",1),("fever",2),("fever",3)]).
|
||||||
|
|
||||||
|
|
||||||
% | ===================== |
|
% | ===================== |
|
||||||
% | == main procedures == |
|
% | == main procedures == |
|
||||||
% | ===================== |
|
% | ===================== |
|
||||||
|
|
||||||
% temporarily returning true
|
|
||||||
diagnose(Sentence, Answer) :-
|
diagnose(Sentence, Answer) :-
|
||||||
interpret(Sentence, Symptoms),
|
interpret(Sentence, Symptoms),
|
||||||
suggest(Symptoms, Answer).
|
suggest(Symptoms, Answer).
|
||||||
|
|
||||||
|
|
||||||
|
% | ============================= |
|
||||||
|
% | == data parsing procedures == |
|
||||||
|
% | ============================= |
|
||||||
|
|
||||||
|
% | = interprete input = |
|
||||||
|
|
||||||
|
interpret(Input, Symptoms) :-
|
||||||
|
split_string(Input, ".", " ", Splited),
|
||||||
|
iterate(Splited,A),
|
||||||
|
flatten(A, Symptoms).
|
||||||
|
|
||||||
|
% | = auxiliary procedures = |
|
||||||
|
|
||||||
|
envelop([X], [Z]):-
|
||||||
|
Z=(X).
|
||||||
|
|
||||||
|
envelop([X|Xs], [Z|Zs]) :-
|
||||||
|
Z=(X),
|
||||||
|
envelop(Xs,Zs).
|
||||||
|
|
||||||
|
iterate([_], []).
|
||||||
|
iterate([X|Xs], [Z|WithoutLast]) :-
|
||||||
|
(sub_string(X,_,_,_,"Patient has ")->string_length(X,AA),L is AA-12, sub_string(X,12,L,_,AAA), split_string(AAA, ",", " ", AAAA),envelop(AAAA,Z);
|
||||||
|
(sub_string(X,_,_,_,"Patient ")->string_length(X,AA),L is AA-8, sub_string(X,8,L,_,AAA), split_string(AAA, ",", " ", AAAA),envelop(AAAA,Z);
|
||||||
|
(sub_string(X,_,_,_,"Patients erythrocyte level is ")->string_length(X,AA),L is AA-30, sub_string(X,30,L,_,AAA), re_replace(",",".",AAA,AAAA), number_string(VAL,AAAA), (VAL>4.2->(VAL>5.4->Z=("erythrocyte",1);Z=("erythrocyte",0));Z=[("erythrocyte",-1)]);
|
||||||
|
(sub_string(X,_,_,_,"Patients temperature is ")->string_length(X,AA), sub_string(X,24,4,_,AAA), re_replace(",",".",AAA,AAAA), number_string(VAL,AAAA), (VAL>37.0->(VAL>38.0->Z=("fever",2);Z=("fever",1));Z=[("fever",0)]);
|
||||||
|
(sub_string(X,_,_,_,"Patients ")->string_length(X,AA),L is AA-15, sub_string(X,9,L,_,AAA), split_string(AAA, ",", " ", AAAA), Z=[("pain",AAAA)];Z="cannot interprete"))))),
|
||||||
|
iterate(Xs, WithoutLast).
|
||||||
|
|
||||||
|
|
||||||
% | ==================================== |
|
% | ==================================== |
|
||||||
% | == disease recognizing procedures == |
|
% | == disease recognizing procedures == |
|
||||||
% | ==================================== |
|
% | ==================================== |
|
||||||
@ -143,30 +172,3 @@ suggest(Symptoms, Answer) :-
|
|||||||
suggest(Symptoms, Answer) :-
|
suggest(Symptoms, Answer) :-
|
||||||
checkForDiseaseWeak(Symptoms, "atrial fibrillation"),
|
checkForDiseaseWeak(Symptoms, "atrial fibrillation"),
|
||||||
Answer = "The patients disease might be atrial fibrillation.".
|
Answer = "The patients disease might be atrial fibrillation.".
|
||||||
|
|
||||||
% interprete input
|
|
||||||
|
|
||||||
interpret(Input, Symptoms) :-
|
|
||||||
split_string(Input, ".", " ", Splited),
|
|
||||||
iterate(Splited,A),
|
|
||||||
flatten(A, Symptoms).
|
|
||||||
|
|
||||||
envelop([X], [Z]):-
|
|
||||||
Z=(X).
|
|
||||||
|
|
||||||
envelop([X|Xs], [Z|Zs]) :-
|
|
||||||
Z=(X),
|
|
||||||
envelop(Xs,Zs).
|
|
||||||
|
|
||||||
iterate([_], []).
|
|
||||||
|
|
||||||
|
|
||||||
iterate([X|Xs], [Z|WithoutLast]) :-
|
|
||||||
(sub_string(X,_,_,_,"Patient has ")->string_length(X,AA),L is AA-12, sub_string(X,12,L,_,AAA), split_string(AAA, ",", " ", AAAA),envelop(AAAA,Z);
|
|
||||||
(sub_string(X,_,_,_,"Patient ")->string_length(X,AA),L is AA-8, sub_string(X,8,L,_,AAA), split_string(AAA, ",", " ", AAAA),envelop(AAAA,Z);
|
|
||||||
(sub_string(X,_,_,_,"Patients erythrocyte level is ")->string_length(X,AA),L is AA-30, sub_string(X,30,L,_,AAA), re_replace(",",".",AAA,AAAA), number_string(VAL,AAAA), (VAL>4.2->(VAL>5.4->Z=("erythrocyte",1);Z=("erythrocyte",0));Z=[("erythrocyte",-1)]);
|
|
||||||
(sub_string(X,_,_,_,"Patients temperature is ")->string_length(X,AA), sub_string(X,24,4,_,AAA), re_replace(",",".",AAA,AAAA), number_string(VAL,AAAA), (VAL>37.0->(VAL>38.0->Z=("fever",2);Z=("fever",1));Z=[("fever",0)]);
|
|
||||||
(sub_string(X,_,_,_,"Patients ")->string_length(X,AA),L is AA-15, sub_string(X,9,L,_,AAA), split_string(AAA, ",", " ", AAAA), Z=[("pain",AAAA)];Z="cannot interprete"))))),
|
|
||||||
iterate(Xs, WithoutLast).
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user