更改 Prolog 中的输出 - 用于检测 covid 症状
Posted
技术标签:
【中文标题】更改 Prolog 中的输出 - 用于检测 covid 症状【英文标题】:change the output in Prolog - for detecting covid symptoms 【发布时间】:2021-08-06 23:25:18 【问题描述】:我想请问您能否建议我如何创建条件或重做代码。我需要程序的输出来检测 covid19 的症状。如果我在程序中的十个症状中至少有 3 次标记为“是”,则输出将是“您有 covid19 症状”。如果“是”少于 3 次,则输出将是“您没有 covid19 症状”。 谢谢
start :- x(Disease), write('the verdict is : '), write(Disease),nl, undo.
x(symptoms) :- symptoms,!.
x(withoutsymptoms). /* without symptoms */
symptoms :- verify(conjunctivitis),
verify(sore_throat),
verify(fatigure),
verify(shake),
verify(diarrhea),
verify(runny_nose),
verify(cold),
verify(muscle_pain),
verify(chest_pressure),
verify(loss_of_taste),
verify(fever).
ask(Question) :-
write('How are you? '),
write(Question),
write('? '),
read(Response),
nl,
( (Response == yes ; Response == yes)
->
assert(yes(Question)) ;
assert(no(Question)), fail).
:- dynamic yes/1,no/1.
verify(S) :-
(yes(S)
->
true ;
(no(S)
->
fail ;
ask(S))).
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.
【问题讨论】:
【参考方案1】:这种尝试看起来令人困惑。下面的呢,它也不使用assertz/1
来戳Prolog 数据库,而是将响应收集在一个列表中以供以后分析。
此外,我们不使用“术语反序列化器”read/1
,而是使用read_line_to_string/2
% ---
% Symptoms are listed naturally in a list.
% There are 11 symptoms
symptoms( [conjunctivitis,
sore_throat,
fatigue,
shake,
diarrhea,
runny_nose,
cold,
muscle_pain,
chest_pressure,
loss_of_taste,
fever] ).
% ---
% Go through the symptoms list, collecting answers
ask_about_symptoms([],[]).
ask_about_symptoms([Symptom|MoreSymptoms],[Answer-Symptom|MorePairs]) :-
repeat,
format("Do you have: ~s?\n",[Symptom]),
read_line_to_string(user_input,S1),
string_lower(S1,S2),
(
member(S2,["yes","y","ja","oui"])
->
Answer = yes
;
member(S2,["no","n","nein","non"])
->
Answer = no
;
format("Please try again\n",[]),fail % Back to "repeat"
),
ask_about_symptoms(MoreSymptoms,MorePairs).
is_yes_pair(yes-_).
ask_candidate :-
symptoms(Symptoms),
ask_about_symptoms(Symptoms,AnswerPairs),
!, % don't go back to asking
include(is_yes_pair,AnswerPairs,Included),
format("So you say you have the following symptoms: ~q~n",[Included]),
length(Included,Hits),
((Hits>=3) -> format("Looks bad.~n",[]) ; format("You probably don't have it.~n",[])).
示例运行:
?- [rona].
true.
?- ask_candidate.
Do you have: conjunctivitis?
|: y
Do you have: sore_throat?
|: y
Do you have: fatigue?
|: n
Do you have: shake?
|: n
Do you have: diarrhea?
|: n
Do you have: runny_nose?
|: y
Do you have: cold?
|: foo
Please try again
Do you have: cold?
|: bar
Please try again
Do you have: cold?
|: n
Do you have: muscle_pain?
|: n
Do you have: chest_pressure?
|: y
Do you have: loss_of_taste?
|: y
Do you have: fever?
|: y
So you say you have the following symptoms: [yes-conjunctivitis,yes-sore_throat,yes-runny_nose,yes-chest_pressure,yes-loss_of_taste,yes-fever]
Looks bad.
true.
【讨论】:
另外,请阅读The Bulletin of the Atomic Scientists,首页。谁让狗出去的?该死。以上是关于更改 Prolog 中的输出 - 用于检测 covid 症状的主要内容,如果未能解决你的问题,请参考以下文章
史密斯探测证实,BioFlash可检出空气中的SARS-CoV-2变异株,包括德尔塔和德尔塔+