Я смотрю на этот cold_flu.pl
пример пролога.
%Flu or cold identification example
%Start with ?- go.
go:- hypothesis(Disease),
write('I believe you have: '),
write(Disease),
nl,
undo.
%Hypothesis that should be tested
hypothesis(cold):- cold, !.
hypothesis(flu):- flu, !.
%Hypothesis Identification Rules
cold :-
verify(headache),
verify(runny_nose),
verify(sneezing),
verify(sore_throat).
flu :-
verify(fever),
verify(headache),
verify(chills),
verify(body_ache).
/* how to ask questions */
ask(Question) :-
write('Does the patient have the following symptom: '),
write(Question),
write('? '),
read(Response),
nl,
( (Response == yes ; Response == y)
->
assert(yes(Question)) ;
assert(no(Question)), fail).
:- dynamic yes/1,no/1.
/* How to verify something */
verify(S) :- (yes(S) -> true ;
(no(S) -> write('failed') ;
ask(S))).
/* undo all yes/no assertions */
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.
Я замечаю, что если спросить:
Does the patient have the following symptom: headache?
и ответ no.
, то программапотерпит неудачу, потому что только два возможных исхода говорят о том, что у пациента болит голова.
Как бы вы отредактировали его так, чтобы он чисто заканчивался сообщением о том, что вряд ли это простуда от гриппа?
Я не знаю Пролога, но несколько раз пытался, например, добавить правило гипотезы для nothing
.