내 연구를 위해 프롤로그 프로그래밍을하고 있습니다.프롤로그 프로그래밍에서 특정 규칙 만들기 (if-then-else like)
hypothesis(Patient,cold,Score) :-
symptom(Patient,fever) -> Score is 10; Score is 0.
hypothesis(Patient,severe_cold,Score) :-
symptom(Patient,fever) -> Score1 is 10; Score1 is 0,
symptom(Patient, runny_nose) -> Score2 is 20; Score2 is 0, Score is Score1 + Score2
.
모든 가설에 대한 점수를 얻고 싶습니다. 즉 증상 (Patient, fever)이 ok로 확인되면 sever_cold (점수 10) 및 cold (점수 10)에 대한 점수를 모두 얻고 싶습니다. 또 다른 예를 들어 증상 (Patient, runny_nose)이 ok로 체크 된 경우 severe_cold (Score 20) 점수를 얻고 싶습니다. 하지만 프롤로그가 작동하지 않습니다 ...
처음으로 프롤로그를 사용합니다. 처리하기가 너무 어렵습니다.
는 **편집* ** * ** 는 사실, 내 모든 코드는 다음과 같습니다. 그것은 .. 증상 만 "열"이 표시되지만 모든 점수가 100이기 때문에 나는 내 프로그램 ...
1 ?- start.
What is the patient's name? GJ
|: a man has a fever
|: wow
|: great
|: good
|: nice
|: nothing
|: wow
|: wow
|: wow
|: wow
100until...100until...[GJ] probably has cold.
true
을 테스트 할 때 여기에
%% Lines are without period(.)
diagnosis :-
readln(Line1),
readln(Line2),
readln(Line3),
readln(Line4),
readln(Line5),
readln(Line6),
readln(Line7),
readln(Line8),
readln(Line9),
readln(Line10),
write(Line1),nl,
write(Line2),nl,
write(Line3),nl,
write(Line4),nl,
write(Line5),nl,
write(Line6),nl,
write(Line7),nl,
write(Line8),nl,
write(Line9),nl,
write(Line10),nl.
%% (get_symptom(Line1,[man]) -> write('man!!!!!!!!!')),
%% (get_symptom(Line2,[woman]) -> write('woman!!!!!!!!!')).
%% if A then B else C, (A->B; C)
%% grammar
s --> np, vp.
np --> det, n.
vp --> v, np.
det --> [a].
n --> [man].
v --> [has].
n --> [woman].
n --> [fever].
n --> [runny_nose].
get_symptom(Line,[N]) :- s(Line,[]), n([N],[]).
%% FindSymptom(Line, [Symptom]) : - s(Line,[]), np(_, _, object,[a,
%% Symptom]), n(singular, [Symptom], []).
start :-
write('What is the patient''s name? '),
readln(Patient), %% Here, this can be used for input of all symtoms
diagnosis,
hypothesis1(Patient,cold,S1),
append([cold/S1/red],[],N1), write(S1),
write('until...'),
hypothesis2(Patient,severe_cold,S2), write(S2),
append([severe_cold/S2/red],N1,BarList),
write('until...'),
%% write(Patient,"probably has ",Disease,"."),nl.
hypothesis(Disease),
write(Patient),
write(' probably has '),
write(Disease),
write('.'),
test_barchart(BarList).
start :-
write('Sorry, I don''t seem to be able to'),nl,
write('diagnose the disease.'),nl.
symptom(Patient,fever) :-
get_symptom(Line1, [fever]);
get_symptom(Line2, [fever]);
get_symptom(Line3, [fever]);
get_symptom(Line4, [fever]);
get_symptom(Line5, [fever]);
get_symptom(Line6, [fever]);
get_symptom(Line7, [fever]);
get_symptom(Line8, [fever]);
get_symptom(Line9, [fever]);
get_symptom(Line10, [fever]).
symptom(Patient,runny_nose) :-
get_symptom(Line1, [runny_nose]);
get_symptom(Line2, [runny_nose]);
get_symptom(Line3, [runny_nose]);
get_symptom(Line4, [runny_nose]);
get_symptom(Line5, [runny_nose]);
get_symptom(Line6, [runny_nose]);
get_symptom(Line7, [runny_nose]);
get_symptom(Line8, [runny_nose]);
get_symptom(Line9, [runny_nose]);
get_symptom(Line10, [runny_nose]).
hypothesis1(Patient,cold,Score_Cold) :-
symptom(Patient,fever) -> Score_Cold is 100; Score_Cold is 0.
hypothesis2(Patient,severe_cold,Score_Severe) :-
(symptom(Patient,fever) -> Score1 is 50; Score1 is 0),
(symptom(Patient, runny_nose) -> Score2 is 50; Score2 is 0),
Score_Severe is Score1 + Score2.
hypothesis(Disease) :-
(hypothesis1(Patient,cold,Score1),
Score1 =:= 100 -> Disease = cold);
(hypothesis2(Patient,severe_cold,Score2),
Score2 =:= 100 -> Disease = severe_cold).
%% make graph for the result
:- use_module(library(pce)).
:- use_module(library(plot/barchart)).
:- use_module(library(autowin)).
test_barchart(BarList):-
new(W, picture),
send(W, display, new(BC, bar_chart(vertical,0,100))),
forall(member(Name/Height/Color,
BarList),
( new(B, bar(Name, Height)),
send(B, colour(Color)),
send(BC, append, B)
)),
send(W, open).
%% [X/100/red, y/150/green, z/80/blue, v/50/yellow]
%% append List
append([], L, L).
append([H|T], L2, [H|L3]):-
append(T, L2, L3).
... 무슨 일이야?
나는 정말로 이해하지 못한다. 전체 프로그램을 게시하고, 아마도 누군가가 세부 사항을 도울 수 있습니다 ... – CapelliC
감사합니다. 나는 더 자세히 다른 질문을했습니다 .. 조언 주셔서 감사합니다 :) – GoodGJ