Note that there are some explanatory texts on larger screens.

plurals
  1. POMake some specific rules (if-then-else like) in Prolog Programming
    primarykey
    data
    text
    <p>I'am doing Prolog programming for my research. </p> <pre><code>hypothesis(Patient,cold,Score) :- symptom(Patient,fever) -&gt; Score is 10; Score is 0. hypothesis(Patient,severe_cold,Score) :- symptom(Patient,fever) -&gt; Score1 is 10; Score1 is 0, symptom(Patient, runny_nose) -&gt; Score2 is 20; Score2 is 0, Score is Score1 + Score2 . </code></pre> <p>I want to get score for all hypothesis. That is, if symptom(Patient,fever) is checked as ok, then I want to get score for sever_cold (Score 10) and cold (Score 10)both. For another example, if symptom(Patient, runny_nose) is checked as ok, then I want to get score for severe_cold (Score 20). But the Prolog doesn't work... </p> <p>It's first time I use Prolog.. It's too confusing to handle.</p> <p><em><strong></em>**</strong><em>Edited</em><strong><em>*</em>**<em>*</em>**</strong> Actually, all of the my code is as below.</p> <pre><code>%% 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]) -&gt; write('man!!!!!!!!!')), %% (get_symptom(Line2,[woman]) -&gt; write('woman!!!!!!!!!')). %% if A then B else C, (A-&gt;B; C) %% grammar s --&gt; np, vp. np --&gt; det, n. vp --&gt; v, np. det --&gt; [a]. n --&gt; [man]. v --&gt; [has]. n --&gt; [woman]. n --&gt; [fever]. n --&gt; [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) -&gt; Score_Cold is 100; Score_Cold is 0. hypothesis2(Patient,severe_cold,Score_Severe) :- (symptom(Patient,fever) -&gt; Score1 is 50; Score1 is 0), (symptom(Patient, runny_nose) -&gt; Score2 is 50; Score2 is 0), Score_Severe is Score1 + Score2. hypothesis(Disease) :- (hypothesis1(Patient,cold,Score1), Score1 =:= 100 -&gt; Disease = cold); (hypothesis2(Patient,severe_cold,Score2), Score2 =:= 100 -&gt; 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). </code></pre> <p>Here, when I tested my program...</p> <pre><code>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 </code></pre> <p>As It shows, there is only "fever" for symptom.. but all the score is 100... What happened?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload