From 99765573ef1288534f165ef463110bff946baadd Mon Sep 17 00:00:00 2001 From: Jakub R Date: Sun, 13 Jun 2021 17:19:24 +0200 Subject: [PATCH] implemented diagnose procedure - combined interprate and suggest procedures --- asd.pl | 80 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/asd.pl b/asd.pl index d038f41..a74384a 100644 --- a/asd.pl +++ b/asd.pl @@ -2,16 +2,16 @@ % | == disease data base == | % | ======================= | -disease('flu',[('pain',['throat']),('runny nose'),('fever',-1),('general weakness'),('cough')],[('pain',['muscles'])]). -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('diphtheria',[('fever',1),('general weakness'),('dyspnea')],[('Unclear Speech'),('cannot swallow')]). -disease('typhoid',[('fever',-1),('pain',['stomach']),('spleen enlargement')],['tire symptoms']). -disease('plague',[('fever',2),('general weakness'),('magnifying lymph nodes'),('liver enlargement'),('spleen enlargement')],[('cloded rash')]). -disease('haemophilia',[('epistaxis'),('impaired blood clotting'),('spleen enlargement')],[]). -disease('whooping cough',[('fever',1),('pain',['throat']),('paroxysmal cough')],[('conjunctivitis'),('vomiting')]). -disease('myasthenia',[('excessive fatigue')],[('muscle weakness'),('double vision')]). -disease('atrial fibrillation',[('dizziness'),('fainting'),('excessive fatigue')],[('cough')]). +disease("flu",[("pain",["throat"]),("runny nose"),("fever",-1),("general weakness"),("cough")],[("pain",["muscles"])]). +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("diphtheria",[("fever",1),("general weakness"),("dyspnea")],[("Unclear Speech"),("cannot swallow")]). +disease("typhoid",[("fever",-1),("pain",["stomach"]),("spleen enlargement")],["tire symptoms"]). +disease("plague",[("fever",2),("general weakness"),("magnifying lymph nodes"),("liver enlargement"),("spleen enlargement")],[("cloded rash")]). +disease("haemophilia",[("epistaxis"),("impaired blood clotting"),("spleen enlargement")],[]). +disease("whooping cough",[("fever",1),("pain",["throat"]),("paroxysmal cough")],[("conjunctivitis"),("vomiting")]). +disease("myasthenia",[("excessive fatigue")],[("muscle weakness"),("double vision")]). +disease("atrial fibrillation",[("dizziness"),("fainting"),("excessive fatigue")],[("cough")]). % | ===================== | @@ -19,12 +19,9 @@ disease('atrial fibrillation',[('dizziness'),('fainting'),('excessive fatigue')] % | ===================== | % temporarily returning true -diagnose(Sentence, Answer) :- true. - - - - - +diagnose(Sentence, Answer) :- + interpret(Sentence, Symptoms), + suggest(Symptoms, Answer). % | ==================================== | @@ -49,6 +46,7 @@ checkForDiseaseStrong(Symptoms, Disease) :- checkForDiseaseWeak(Symptoms, Disease) :- disease(Disease, ObligatorySymptoms, AdditionalSymptoms), append(ObligatorySymptoms, AdditionalSymptoms, ExpectedSymptoms), + not(checkForDiseaseStrong(Symptoms, Disease)), includesAny(Symptoms, ExpectedSymptoms), includesAll(ExpectedSymptoms, Symptoms), !. @@ -58,92 +56,92 @@ checkForDiseaseWeak(Symptoms, Disease) :- % flu suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'flu'), + checkForDiseaseStrong(Symptoms, "flu"), Answer = "The patients disease is almost certainly flu.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'flu'), + checkForDiseaseWeak(Symptoms, "flu"), Answer = "The patients disease might be flu.". % malaria suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'malaria'), + checkForDiseaseStrong(Symptoms, "malaria"), Answer = "The patients disease is almost certainly malaria.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'malaria'), + checkForDiseaseWeak(Symptoms, "malaria"), Answer = "The patients disease might be malaria.". % angina suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'angina'), + checkForDiseaseStrong(Symptoms, "angina"), Answer = "The patients disease is almost certainly angina.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'angina'), + checkForDiseaseWeak(Symptoms, "angina"), Answer = "The patients disease might be angina.". % diphtheria suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'diphtheria'), + checkForDiseaseStrong(Symptoms, "diphtheria"), Answer = "The patients disease is almost certainly diphtheria.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'diphtheria'), + checkForDiseaseWeak(Symptoms, "diphtheria"), Answer = "The patients disease might be diphtheria.". % typhoid suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'typhoid'), + checkForDiseaseStrong(Symptoms, "typhoid"), Answer = "The patients disease is almost certainly typhoid.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'typhoid'), + checkForDiseaseWeak(Symptoms, "typhoid"), Answer = "The patients disease might be typhoid.". % plague suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'plague'), + checkForDiseaseStrong(Symptoms, "plague"), Answer = "The patients disease is almost certainly plague.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'plague'), + checkForDiseaseWeak(Symptoms, "plague"), Answer = "The patients disease might be plague.". % haemophilia suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'haemophilia'), + checkForDiseaseStrong(Symptoms, "haemophilia"), Answer = "The patients disease is almost certainly haemophilia.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'haemophilia'), + checkForDiseaseWeak(Symptoms, "haemophilia"), Answer = "The patients disease might be haemophilia.". % whooping cough suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'whooping cough'), + checkForDiseaseStrong(Symptoms, "whooping cough"), Answer = "The patients disease is almost certainly whooping cough.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'whooping cough'), + checkForDiseaseWeak(Symptoms, "whooping cough"), Answer = "The patients disease might be whooping cough.". % myasthenia suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'myasthenia'), + checkForDiseaseStrong(Symptoms, "myasthenia"), Answer = "The patients disease is almost certainly myasthenia.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'myasthenia'), + checkForDiseaseWeak(Symptoms, "myasthenia"), Answer = "The patients disease might be myasthenia.". % atrial fibrillation suggest(Symptoms, Answer) :- - checkForDiseaseStrong(Symptoms, 'atrial fibrillation'), + checkForDiseaseStrong(Symptoms, "atrial fibrillation"), Answer = "The patients disease is almost certainly atrial fibrillation.". suggest(Symptoms, Answer) :- - checkForDiseaseWeak(Symptoms, 'atrial fibrillation'), + checkForDiseaseWeak(Symptoms, "atrial fibrillation"), Answer = "The patients disease might be atrial fibrillation.". % interprete input @@ -164,11 +162,11 @@ 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'))))), + (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).