Prolog工作机制

时间:2015-05-20 08:05:16

标签: prolog

我对Prolog很新。我已经阅读了很多文档和检查过的例子。

我有一个代码,简化版本可以在下面看到;

go :-
    write('Patient Name? '),
    read(Patient),
    case(Patient,Disorder),
    write_list([Patient,' has', ' ', Disorder,'.']),nl.

go :-
    write('No diagnosis'),nl.

statement(Patient,fever) :-
    write_list([Patient,has fever (y/n) ?']),
    response(Reply),
    Reply='y'.

statement(Patient,itch) :-
    write_list([Patient,has itch (y/n) ?']),
    response(Reply),
    Reply='y'.

statement(Patient,headache) :-
    write_list([Patient,'has headache(y/n) ?']),
    response(Reply),
    Reply='y'.

statement(Patient,cough) :-
    write_list([Patient,' has cough (y/n) ?']),
    response(Reply),
    Reply='y'.

case(Patient,pt_measles) :-
    statement(Patient,fever),
    statement(Patient,itch).

case(Patient,pt_german_measles) :-
    statement(Patient,fever),
    statement(Patient,itch),
    statement(Patient,headache).

write_list([]).
write_list([A| Z]) :-
    write(A),
    write_list(Z).

response(Reply) :-
    get_single_char(Code),
    put_code(Code), nl,
    char_code(Reply, Code).

代码询问患者姓名和陈述。我正在努力的是,它以fever? -> itch? -> headache? ->cough?的顺序问我问题。如果我选择No for itch,它会跳过头痛和咳嗽问题并跳到新病例。如果不向新病例提出问题,或者在没有问这些问题的情况下是什么让它跳到新病例,它如何跳过头痛和咳嗽?

提前致谢!

0 个答案:

没有答案