我对prolog还很陌生,我遇到了一个使用prolog的简单医疗诊断程序的问题,我试图找到关于这个医疗诊断系统的代码来使它工作,但是我不能,我不知道我需要改变什么,我使用SWI prolog软件。
在这里,我尝试使用的prolog代码在域中显示错误,显示“语法error=操作符期望”。
domains
disease,indication = symbol
Patient,name = string
predicates
hypothesis(string,disease)
symptom(name,indication)
response(char)
go
clauses
go :-
write("What is the patient's name? "),
readln(Patient),
hypothesis(Patient,Disease),
write(Patient,"probably has ",Disease,"."),nl.
go :-
write("Sorry, I don't seem to be able to"),nl,
write("diagnose the disease."),nl.
symptom(Patient,fever) :-
write("Does ",Patient," have a fever (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,rash) :-
write("Does ",Patient," have a rash (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,headache) :-
write("Does ",Patient," have a headache (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,runny_nose) :-
write("Does ",Patient," have a runny_nose (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,conjunctivitis) :-
write("Does ",Patient," have a conjunctivitis (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,cough) :-
write("Does ",Patient," have a cough (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,body_ache) :-
write("Does ",Patient," have a body_ache (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,chills) :-
write("Does ",Patient," have a chills (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,sore_throat) :-
write("Does ",Patient," have a sore_throat (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,sneezing) :-
write("Does ",Patient," have a sneezing (y/n) ?"),
response(Reply),
Reply='y'.
symptom(Patient,swollen_glands) :-
write("Does ",Patient," have a 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.我能做些什么让它发挥作用?
发布于 2014-12-16 15:50:44
正如注释中所解释的那样,代码很可能是为与Prolog共享特性的逻辑编程语言编写的,但它并不被认为是Prolog系统(无论是官方的还是事实上的Prolog标准都不是w.r.t)。
要使代码在上运行,快速重写代码如下:
go :-
write('What is the patient''s name? '),
read(Patient),
hypothesis(Patient,Disease),
write_list([Patient,'probably has ',Disease,'.']),nl.
go :-
write('Sorry, I don''t seem to be able to'),nl,
write('diagnose the disease.'),nl.
symptom(Patient,fever) :-
write_list(['Does ',Patient,' have a fever (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,rash) :-
write_list(['Does ',Patient,' have a rash (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,headache) :-
write_list(['Does ',Patient,' have a headache (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,runny_nose) :-
write_list(['Does ',Patient,' have a runny_nose (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,conjunctivitis) :-
write_list(['Does ',Patient,' have a conjunctivitis (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,cough) :-
write_list(['Does ',Patient,' have a cough (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,body_ache) :-
write_list(['Does ',Patient,' have a body_ache (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,chills) :-
write_list(['Does ',Patient,' have a chills (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,sore_throat) :-
write_list(['Does ',Patient,' have a sore_throat (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,sneezing) :-
write_list(['Does ',Patient,' have a sneezing (y/n) ?']),
response(Reply),
Reply='y'.
symptom(Patient,swollen_glands) :-
write_list(['Does ',Patient,' have a 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).为了方便起见,此重写使用了SWI特定的内置谓词get_single_char/1。如果要使代码适合在其他Prolog系统上运行,则需要替换它的调用。
https://stackoverflow.com/questions/27505960
复制相似问题