what mistake in this medical diagnosis prolog? -


i still new prolog, have problem simple medical diagnosis program using prolog, try find code medical diagnosis system make work, cant, dont know need change, use swi prolog software.

here prolog code try use show error in domains, show "syntax error= operator expected"

domains disease,indication = symbol patient,name = string  predicates hypothesis(string,disease) symptom(name,indication) response(char) go clauses  go :-     write("what patient's name? "),     readln(patient),     hypothesis(patient,disease),     write(patient,"probably has ",disease,"."),nl. go :-     write("sorry, don't seem able to"),nl,     write("diagnose disease."),nl.  symptom(patient,fever) :-     write("does ",patient," have fever (y/n) ?"),     response(reply),     reply='y'. symptom(patient,rash) :-     write("does ",patient," have rash (y/n) ?"),     response(reply),     reply='y'. symptom(patient,headache) :-     write("does ",patient," have headache (y/n) ?"),     response(reply),     reply='y'. symptom(patient,runny_nose) :-     write("does ",patient," have runny_nose (y/n) ?"),     response(reply),     reply='y'. symptom(patient,conjunctivitis) :-     write("does ",patient," have conjunctivitis (y/n) ?"),     response(reply),     reply='y'. symptom(patient,cough) :-     write("does ",patient," have cough (y/n) ?"),     response(reply),     reply='y'. symptom(patient,body_ache) :-     write("does ",patient," have body_ache (y/n) ?"),     response(reply),     reply='y'. symptom(patient,chills) :-     write("does ",patient," have chills (y/n) ?"),     response(reply),     reply='y'. symptom(patient,sore_throat) :-     write("does ",patient," have sore_throat (y/n) ?"),     response(reply),     reply='y'. symptom(patient,sneezing) :-     write("does ",patient," have sneezing (y/n) ?"),     response(reply),     reply='y'. symptom(patient,swollen_glands) :-     write("does ",patient," have swollen_glands (y/n) ?"),     response(reply),     reply='y'.  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).  response(reply) :-     readchar(reply),     write(reply),nl. 

what can make working?

as explained in comments, code written logic programming language shares features prolog that's not considered prolog system (w.r.t both official , de facto prolog standards).

a quick rewrite of code running on swi-prolog is:

go :-     write('what patient''s name? '),     read(patient),     hypothesis(patient,disease),     write_list([patient,'probably has ',disease,'.']),nl.  go :-     write('sorry, don''t seem able to'),nl,     write('diagnose disease.'),nl.  symptom(patient,fever) :-     write_list(['does ',patient,' have fever (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,rash) :-     write_list(['does ',patient,' have rash (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,headache) :-     write_list(['does ',patient,' have headache (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,runny_nose) :-     write_list(['does ',patient,' have runny_nose (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,conjunctivitis) :-     write_list(['does ',patient,' have conjunctivitis (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,cough) :-     write_list(['does ',patient,' have cough (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,body_ache) :-     write_list(['does ',patient,' have body_ache (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,chills) :-     write_list(['does ',patient,' have chills (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,sore_throat) :-     write_list(['does ',patient,' have sore_throat (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,sneezing) :-     write_list(['does ',patient,' have sneezing (y/n) ?']),     response(reply),     reply='y'.  symptom(patient,swollen_glands) :-     write_list(['does ',patient,' have swollen_glands (y/n) ?']),     response(reply),     reply='y'.  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).  write_list([]). write_list([term| terms]) :-     write(term),     write_list(terms).  response(reply) :-     get_single_char(code),     put_code(code), nl,     char_code(reply, code). 

for convenience, rewrite makes use of swi-prolog specific built-in predicate, get_single_char/1. need replace call if want adapt code run on other prolog systems.


Comments

  1. Ok now this is a kind of article any reader would love and share. The way it is written, the way each example is given makes this content super informative.

    ReplyDelete

Post a Comment

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -