Discussions related to Visual Prolog
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

In my system I have a problem with common dialog

Unread post by fred malack »

If commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have a fever(y/n) ?"))= "y" then
Assert(symptom(Patient, "fever"))


In the above code it popup and whenevr I click cancel it doesnt respond I need some help.
fr@dlu
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Unread post by Ferenc Nagy »

Code: Select all

if commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have a fever(y/n) ?"))= "y" then assert(symptom(Patient, "fever")) endif, askNextQuestion(Patient),
If you cancel this dialog then commondialogs::tryGet_string fails and the procedure won't be continued by askNextQuestion().

If you respond with anything else than "y" and confirm the dialog then the program
1. executes if,
2. jumps to askNextQuestion().

I think the solution is

Code: Select all

predicates diagnose(string Patient) -> string determ.   askFirstQuestion(string Patient) -> boolean Answer1 procedure. askNextQuestion(string Patient) -> boolean Answer2 procedure. clauses askFirstQuestion(Patient)=true :- Answer1=commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have a fever(y/n) ?")), Answer1="y", asserta(symptom(Patient, "fever")), !. askFirstQuestion(Patient)=false.   askNextQuestion(Patient)=true :- Answer2=commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have rashes(y/n) ?")), Answer2="y", asserta(symptom(Patient, "meningitis")), !. askNextQuestion(Patient)=false. % Calling sequence diagnose(Patient) = Disease :-      true=askFirstQuestion(Patient),            Answer2=askNextQuestion(Patient),      fail. diagnose(Patient) = Disease :-      symptom(Patient,Disease).  
Lesson
Forget if ...endif structures. These are not PROLOG but imported alien elements.


Other remarks:
"Y", "yes", "yeah", "39 centigrade" answers mean 'false' with your tools.
I do not want to complicate the program with retaining only the lowercased first character and repeating the question if the result is neither "y" nor "n".
The assertA() causes that "meningitis" precedes "fever" in the database of symptoms.
The assertZ() causes that "meningitis" follows "fever" in the database of symptoms.
TIA, Regards,
Frank Nagy
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Thanx alot for the help

Unread post by fred malack »

i real need your help because i am trying to replace if and else with my code but i still a novice and gives me a hard time the below is my code i realy need your help plz because i have to present it.

Code: Select all

implement taskWindow     inherits applicationWindow     open core, vpiDomains constants     mdiProperty : boolean = true. clauses     new():-         applicationWindow::new(),         generatedInitialize().   constants     txt_input = "Eingabe".   domains     name = string.     disease = symbol.     indication = symbol.   predicates     onShow : window::showListener. clauses     onShow(_, _CreationData):-         _MessageForm = messageForm::display(This).   predicates     onFileNew : window::menuItemListener. clauses     onFileNew(_Source, _MenuTag):-   if Patient = commonDialogs::tryGet_string(This, txt_input, "", "What is the Patient's name ?") then         else            Patient = "unknown"         end if,         go(Patient).   predicates     go : (name Patient). clauses     go(Patient) :-         checkPupil(Patient),         fail.     go(Patient) :-         gradePupil(Patient),         fail.     go(_Patient):-         stdIo::write("=====\n").   facts     symptom : (name,indication) nondeterm.   predicates     checkPatient : (name Patient)               multi.   clauses     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a fever (y/n) ?")) = "y" then             assert(symptom(Patient, "fever"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a rash (y/n) ?")) = "y" then             assert(symptom(Patient, "rash"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a headache (y/n) ?")) = "y" then             assert(symptom(Patient, "headache"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a fever (y/n) ?")) = "y" then             assert(symptom(Patient, "fever"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a runny_nose (y/n) ?")) = "y" then             assert(symptom(Patient, "runny_nose"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a conjunctivitis (y/n) ?")) = "y" then             assert(symptom(Patient, "conjunctivitis"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a cough (y/n) ?")) = "y" then             assert(symptom(Patient, "cough"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a body_ache (y/n) ?")) = "y" then             assert(symptom(Patient, "body_ache"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a chills (y/n) ?")) = "y" then             assert(symptom(Patient, "chills"))         end if.       checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a sore_throat (y/n) ?")) = "y" then             assert(symptom(Patient, "sore_throat"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a sneezing (y/n) ?")) = "y" then             assert(symptom(Patient, "sneezing"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a swollen_glands (y/n) ?")) = "y" then             assert(symptom(Patient, "swollen_glands"))         end if.       predicates     gradeDisease : (name Patient) nondeterm.         clauses     gradeDisease(Patient) :-         hypothesis(Patient, Disease),         stdIo::write(Patient, " ", Disease, "\n").         predicates     hypothesis : (name Patient, disease indication [out])         nondeterm.        clauses     hypothesis(Patient, "measles") :-         symptom(Patient,fever),         symptom(Patient,cough),         symptom(Patient,conjunctivitis),         symptom(Patient,runny_nose),         symptom(Patient,rash).      hypothesis(Patient,german_measles) :-         symptom(Patient,fever),         symptom(Patient,headache),         symptom(Patient,runny_nose),         symptom(Patient,rash).   hypothesis(Patient,flu) :-         symptom(Patient,fever),         symptom(Patient,headache),         symptom(Patient,body_ache),         symptom(Patient,conjunctivitis),         symptom(Patient,chills),         symptom(Patient,sore_throat),         symptom(Patient,runny_nose),         symptom(Patient,cough).         hypothesis(Patient,common_cold) :-         symptom(Patient,headache),         symptom(Patient,sneezing),         symptom(Patient,sore_throat),         symptom(Patient,runny_nose),         symptom(Patient,chills).         hypothesis(Patient,mumps) :-         symptom(Patient,fever),         symptom(Patient,swollen_glands).         hypothesis(Patient,chicken_pox) :-         symptom(Patient,fever),         symptom(Patient,chills),         symptom(Patient,body_ache),         symptom(Patient,rash).   hypothesis(Patient,measles) :-         symptom(Patient,cough),         symptom(Patient,sneezing),         symptom(Patient,runny_nose).
fr@dlu
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

This is an untested approach you might consider:

Code: Select all

class facts     finding : ( string ClinicalSignOrSymptom ).   class predicates     ask_put_finding : ( window, string, string ) determ (i,i,i).     ask_signs_and_symptoms : ( window, string Patient ) . clauses ask_put_finding( ParentWin, Pt, SignSymptom ) :-     Prompt = string::format( "Does % have a % (y/n) ?", Pt, SignSymptom ),     Response = commonDialogs::tryGet_string( ParentWin, Pt, Prompt ),     FC = string::frontChar( Response ),     if _Pos = string::search( "TY", YesOther, string::caseInsensitive ) then         assert( symptom( Pt, SignSymptom ))     else         % do nothing, but you could add more logic here later     end if.     finding( "fever" ). finding( "rash" ). finding( "headache" ). /*     Add other conditions to findings here.     Can you guess how you might be able to "consult" your findings from a file     into your expert system when you use a fact database? */   ask_signs_and_symptoms( ParentWin, Pt ):-     finding( SignSymptom ),  % for each clinical finding in facts         ask_put_finding( ParentWin, Pt, SignSymptom ),         fail. ask_signs_and_symptoms(_,_):-     vpiCommonDialogs::note("Patient Signs & Symptoms","Data entry is complete.").
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Unread post by fred malack »

....Thanks for this approach but i am trying to implement it in the code i had before and i cant please i need your help.....

Ferenc Nagy wrote:

Code: Select all

if commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have a fever(y/n) ?"))= "y" then assert(symptom(Patient, "fever")) endif, askNextQuestion(Patient),
If you cancel this dialog then commondialogs::tryGet_string fails and the procedure won't be continued by askNextQuestion().

If you respond with anything else than "y" and confirm the dialog then the program
1. executes if,
2. jumps to askNextQuestion().

I think the solution is

Code: Select all

predicates diagnose(string Patient) -> string determ.   askFirstQuestion(string Patient) -> boolean Answer1 procedure. askNextQuestion(string Patient) -> boolean Answer2 procedure. clauses askFirstQuestion(Patient)=true :- Answer1=commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have a fever(y/n) ?")), Answer1="y", asserta(symptom(Patient, "fever")), !. askFirstQuestion(Patient)=false.   askNextQuestion(Patient)=true :- Answer2=commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have rashes(y/n) ?")), Answer2="y", asserta(symptom(Patient, "meningitis")), !. askNextQuestion(Patient)=false. % Calling sequence diagnose(Patient) = Disease :-      true=askFirstQuestion(Patient),            Answer2=askNextQuestion(Patient),      fail. diagnose(Patient) = Disease :-      symptom(Patient,Disease).  
Lesson
Forget if ...endif structures. These are not PROLOG but imported alien elements.


Other remarks:
"Y", "yes", "yeah", "39 centigrade" answers mean 'false' with your tools.
I do not want to complicate the program with retaining only the lowercased first character and repeating the question if the result is neither "y" nor "n".
The assertA() causes that "meningitis" precedes "fever" in the database of symptoms.
The assertZ() causes that "meningitis" follows "fever" in the database of symptoms.
fr@dlu
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Unread post by Ferenc Nagy »

Code: Select all

ask_put_finding( ParentWin, Pt, SignSymptom ) :-     Prompt = string::format( "Does % have a % (y/n) ?", Pt, SignSymptom ),     Response = commonDialogs::tryGet_string( ParentWin, Pt, Prompt ),     FC = string::frontChar( Response ),     if _Pos = string::search( "TY", YesOther, string::caseInsensitive ) then         assert( symptom( Pt, SignSymptom ))     else         % do nothing, but you could add more logic here later     end if.
Hi,

Good News:
1: Harrison Pratt's above code makes a case-insensitive comparison.
2: It solves the problem of "Y", "yes", ... and accepts words beginning with "T" as "y" answer.

Bad News:
1: If the user cancels the common dialog then the program does not execute the

Code: Select all

else         % do nothing, but you could add more logic here later
branch.
2: If the user presses the [Enter] immediately without a "y" character the the
Response will be an empty string and

Code: Select all

FC =string::frontChar( Response )
causes a runtime error.
TIA, Regards,
Frank Nagy
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Re:

Unread post by Harrison Pratt »

Frank,
Thanks for pointing out that vulnerability!
Harrison

[quote]Bad News:
1: If the user cancels the common dialog then the program does not execute the
2: If the user presses the [Enter] immediately without a "y" character the the
Response will be an empty string and

Code: Select all

FC =string::frontChar( Response ) causes a runtime error.[/quote]
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Hello Ferenc Nagy

Unread post by fred malack »

Thanx alot but i am trying to implement it without the use of if...then
With the code u introduce to me.
I did post the code that i am using above and i am trying to change it with this
Method but its not workn please i need help.

Code: Select all

predicates diagnose(string Patient) -> string determ.   askFirstQuestion(string Patient) -> boolean Answer1 procedure. askNextQuestion(string Patient) -> boolean Answer2 procedure. clauses askFirstQuestion(Patient)=true :- Answer1=commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have a fever(y/n) ?")), Answer1="y", asserta(symptom(Patient, "fever")), !. askFirstQuestion(Patient)=false.   askNextQuestion(Patient)=true :- Answer2=commondialogs::tryGet_string(This, txt_input, "" , string::concat("does" , Patient, "have rashes(y/n) ?")), Answer2="y", asserta(symptom(Patient, "meningitis")), !. askNextQuestion(Patient)=false. % Calling sequence diagnose(Patient) = Disease :-      true=askFirstQuestion(Patient),            Answer2=askNextQuestion(Patient),      fail. diagnose(Patient) = Disease :-      symptom(Patient,Disease).
fr@dlu
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

I need help on how to clear the data in editcontrol

Unread post by fred malack »

I want to clear the textfield after i save so that i can enter new data.

Code: Select all

Predicates    OnPushButtonClick : button :clickResponder.   Clauses     OnPushButtonClick(_sources) = button :defaultAction() :-            Fname = fname_ctl:gettext(),            Mname = mname_ctl:gettext(),   Person::addPerson( Fname , Mname),   Person :: saveDatabase.
fr@dlu
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

I think this is what you need (if I understand the question correctly):

Code: Select all

predicates    onPushButtonClick : button :clickResponder.   clauses     onPushButtonClick(_sources) = button :defaultAction() :-         Fname = fname_ctl:getText(),         Mname = mname_ctl:getText(),         person::addPerson(Fname , Mname),         person::saveDatabase,         fname_ctl:setText(""),         mname_ctl:setText("").
Regards Thomas Linder Puls
PDC
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Thanx alot mr.thomas please help me i have another prolem.

Unread post by fred malack »

In the above code i posted of my project i want
To be able to alert a message when the patient is not
Diagnose

Code: Select all

implement taskWindow     inherits applicationWindow     open core, vpiDomains constants     mdiProperty : boolean = true. clauses     new():-         applicationWindow::new(),         generatedInitialize().   constants     txt_input = "Eingabe".   domains     name = string.     disease = symbol.     indication = symbol.   predicates     onShow : window::showListener. clauses     onShow(_, _CreationData):-         _MessageForm = messageForm::display(This).   predicates     onFileNew : window::menuItemListener. clauses     onFileNew(_Source, _MenuTag):-   if Patient = commonDialogs::tryGet_string(This, txt_input, "", "What is the Patient's name ?") then         else            Patient = "unknown"         end if,         go(Patient).   predicates     go : (name Patient). clauses     go(Patient) :-         checkPupil(Patient),         fail.     go(Patient) :-         gradePupil(Patient),         fail.     go(_Patient):-         stdIo::write("=====\n").   facts     symptom : (name,indication) nondeterm.   predicates     checkPatient : (name Patient)               multi.   clauses     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a fever (y/n) ?")) = "y" then             assert(symptom(Patient, "fever"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a rash (y/n) ?")) = "y" then             assert(symptom(Patient, "rash"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a headache (y/n) ?")) = "y" then             assert(symptom(Patient, "headache"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a fever (y/n) ?")) = "y" then             assert(symptom(Patient, "fever"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a runny_nose (y/n) ?")) = "y" then             assert(symptom(Patient, "runny_nose"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a conjunctivitis (y/n) ?")) = "y" then             assert(symptom(Patient, "conjunctivitis"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a cough (y/n) ?")) = "y" then             assert(symptom(Patient, "cough"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a body_ache (y/n) ?")) = "y" then             assert(symptom(Patient, "body_ache"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a chills (y/n) ?")) = "y" then             assert(symptom(Patient, "chills"))         end if.       checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a sore_throat (y/n) ?")) = "y" then             assert(symptom(Patient, "sore_throat"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a sneezing (y/n) ?")) = "y" then             assert(symptom(Patient, "sneezing"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("Does ", Patient, " have a swollen_glands (y/n) ?")) = "y" then             assert(symptom(Patient, "swollen_glands"))         end if.       predicates     gradeDisease : (name Patient) nondeterm.         clauses     gradeDisease(Patient) :-         hypothesis(Patient, Disease),         stdIo::write(Patient, " ", Disease, "\n").         predicates     hypothesis : (name Patient, disease indication [out])         nondeterm.        clauses     hypothesis(Patient, "measles") :-         symptom(Patient,fever),         symptom(Patient,cough),         symptom(Patient,conjunctivitis),         symptom(Patient,runny_nose),         symptom(Patient,rash).      hypothesis(Patient,german_measles) :-         symptom(Patient,fever),         symptom(Patient,headache),         symptom(Patient,runny_nose),         symptom(Patient,rash).   hypothesis(Patient,flu) :-         symptom(Patient,fever),         symptom(Patient,headache),         symptom(Patient,body_ache),         symptom(Patient,conjunctivitis),         symptom(Patient,chills),         symptom(Patient,sore_throat),         symptom(Patient,runny_nose),         symptom(Patient,cough).         hypothesis(Patient,common_cold) :-         symptom(Patient,headache),         symptom(Patient,sneezing),         symptom(Patient,sore_throat),         symptom(Patient,runny_nose),         symptom(Patient,chills).         hypothesis(Patient,mumps) :-         symptom(Patient,fever),         symptom(Patient,swollen_glands).         hypothesis(Patient,chicken_pox) :-         symptom(Patient,fever),         symptom(Patient,chills),         symptom(Patient,body_ache),         symptom(Patient,rash).   hypothesis(Patient,measles) :-         symptom(Patient,cough),         symptom(Patient,sneezing),         symptom(Patient,runny_nose).
I want it when it when i doesnt diagnose
To give a note that the patient couldnt be diagnose

Code: Select all

Hypothesis(Patient,Disease) Stdio::write(Patient,Disease).      
I put if but its not working
fr@dlu
Post Reply