Je suis d'exécution d'un logiciel fourni par le JPL de swi-prolog pour appeler prologue de Java. J'utilise comme Eclipse IDE. Je ne sais pas comment commencer cet exemple très utile pour mes fins que je trouve en ligne.

Voici le code java:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package prolog;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
 
import jpl.Atom;
import jpl.Compound;
import jpl.Variable;
import jpl.Term;
import jpl.Query;
import jpl.JPL;
 
 
@SuppressWarnings({ "unchecked", "deprecation", "serial" })
public class JavaProlog extends JFrame {
 
	JButton 	startButton = new JButton("Start");
	JTextArea 	textArea	= new JTextArea("A Diagnostic Expert System \n" +
											"for respiratory diseases and lung.");
 
	/**
         */
	JavaProlog(){
		Container cp=getContentPane();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
		setLocation	(200,200);
		setSize		(300,200);
		setLayout	(new FlowLayout());
 
 
		startButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				startDiagnose();
			}
		});
 
		cp.add(textArea);
		cp.add(startButton);
 
		setVisible(true);	
	}
 
	private void startDiagnose(){
		Term consult_arg[] = { 
		        new Atom( "C://Users//je_vista//workspace//mdc.pl" ) 
		    };
		    Query consult_query = 
		        new Query( 
		            "consult", 
		            consult_arg );
 
		    boolean consulted = consult_query.query();
 
		    if ( !consulted ){
		        System.err.println( "Consult failed" );
		        System.exit( 1 );
		    }
	}
 
	public static void main( String argv[] ){
		JPL.init();
		JavaProlog jpTest = new JavaProlog();
 
}
et ce sont les fichiers prolog sur ce programme

Code Prolog : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
:- (clause(conman,_) ; consult('conman.pl')).
 
:- abolish(kb_intro/1).
:- abolish(kb_threshold/1).    % Should use retractall   
:- abolish(kb_hypothesis/1).   % instead of abolish      
:- abolish(c_rule/4).          % in some implementations 
:- abolish(kb_can_ask/1).      % of Prolog               
 
kb_intro(['',
          'MDC: A Demonstration Medical Diagnostic System',
          '           Using Confidence Rules',
          '']).
 
kb_threshold(65).
 
kb_hypothesis('The patient has allergic rhinitis.').
kb_hypothesis('The patient has strep throat.').
kb_hypothesis('The patient has pneumonia.').
kb_hypothesis('Give the patient an antihistamine.').
kb_hypothesis('Give the patient a decongestant.').
kb_hypothesis('Give the patient penicillin.').
kb_hypothesis('Give the patient tetracycline.').
kb_hypothesis('Give the patient erythromycin.').
 
 
 
c_rule('The patient has nasal congestion.',
       95,
       [],
       ['The patient is breathing through the mouth.',yes]).
 
c_rule('The patient has a sore throat.',
       95,
       [],
       [and,['The patient is coughing.',yes],['The inside of the patient''s throat is red.',yes]]).
 
c_rule('The patient has a sore throat.',
       90,
       [],
       ['The inside of the patient''s throat is red.',yes]).
 
c_rule('The patient has a sore throat.',
       75,
       [],
       ['The patient is coughing.',yes]).
 
c_rule('The patient has chest congestion.',
       100,
       [],
       ['There are rumbling sounds in the chest.',yes]).
 
c_rule('The patient has allergic rhinitis.',
       85,
       [],
       [and,['The patient has nasal congestion.',yes],[and,['The patient has a sore throat.',no],['The patient has chest congestion.',no]]]).
 
c_rule('The patient has strep throat.',
       80,
       [],
       [and,['The patient has nasal congestion.',yes],
            ['The patient has a sore throat.',yes]]).
 
c_rule('The patient has pneumonia.',
       90,
       [],
       [and,['The patient has chest congestion.',yes],
            [and,['The patient has nasal congestion.',yes],
                 ['The patient has a sore throat.',no]]]).
 
c_rule('The patient has pneumonia.',
       75,
       [],
       [and,['The patient has chest congestion.',yes],
         ['The patient has nasal congestion.',yes]]).
 
c_rule('Give the patient an antihistamine.',
       100,
       ['The patient has allergic rhinitis.'],
       []).
 
c_rule('Give the patient a decongestant.',
       100,
       ['The patient has nasal congestion.'],
       ['The patient has high blood pressure.',no]).
 
c_rule('Give the patient penicillin.',
       100,
       ['The patient has pneumonia.'],
       ['The patient is allergic to penicillin.',no]).
 
c_rule('Give the patient penicillin.',
       100,
       ['The patient has pneumonia.',
        'The patient is allergic to penicillin.'],
       [and,['The patient is in critical condition.',yes],
            ['The patient is allergic to tetracycline.',yes]]).
 
c_rule('Give the patient tetracycline.',
       100,
       ['The patient has pneumonia.',
        -,'Give the patient penicillin.'],
       ['The patient is allergic to tetracycline.',no]).
 
c_rule('Give the patient erythromycin.',
       100,
       ['The patient has strep throat.'],
       ['The patient is allergic to erythromycin.',no]).
 
kb_can_ask('The patient has nasal congestion.').
kb_can_ask('The patient has chest congestion.').
kb_can_ask('The patient has a sore throat.').
kb_can_ask('The patient has high blood pressure.').
kb_can_ask('The patient is allergic to penicillin.').
kb_can_ask('The patient is allergic to erythromycin.').
kb_can_ask('The patient is allergic to tetracycline.').
kb_can_ask('The patient is breathing through the mouth.').
kb_can_ask('The patient is coughing.').
kb_can_ask('The inside of the patient''s throat is red.').
kb_can_ask('There are rumbling sounds in the chest.').
kb_can_ask('The patient is in critical condition.').
 
:- conman.

puis le prologue autre fichier

Code Prolog : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
:- ensure_loaded('getyesno.pl').
 
:- dynamic known/3.
 
 
conman :- kb_intro(Statement),
          writeln(Statement),nl,
          kb_threshold(T),
          kb_hypothesis(Hypothesis),
          confidence_in([Hypothesis,yes],CF),
          CF >= T,
          write('Conclusion: '),
          writeln(Hypothesis),
          write('Confidence in hypothesis: '),
          write(CF),
          writeln('%.'),
          explain_conclusion(Hypothesis), fail.
 
conman :- kb_hypothesis(Hypothesis),
          confirm([Hypothesis]),!,
          writeln('No further conclusions.'),
          nl, finish_conman.
 
conman :- writeln('Can draw no conclusions.'),
          nl, finish_conman.
 
finish_conman :-
     retractall(known(_,_,_)),
     write('Do you want to conduct another consultation?'),
     yes, nl, nl, !, conman.
 
finish_conman.
 
 
ask_confidence(Hypothesis,CF) :-
     kb_can_ask(Hypothesis),
     writeln('Is the following conjecture true? --'),
     write('  '), writeln(Hypothesis),
     writeln(['Possible responses: ',
              '  (y) yes            (n) no',
              '  (l) very likely    (v) very unlikely',
              '  (p) probably       (u) unlikely',
              '  (m) maybe          (d) don''t know.',
              '         (?) why?']),
     write('  Your response --> '),
     get_only([y,l,p,m,n,v,u,d,?],Reply), nl, nl,
     convert_reply_to_confidence(Reply,CF),
     !, Reply \== d,
     ask_confidence_aux(Reply,Hypothesis,CF).
 
ask_confidence_aux(Char,_,_) :- Char \== ?, !.
 
ask_confidence_aux(_,Hypothesis,CF) :-
     explain_question,
     !, ask_confidence(Hypothesis,CF).
 
get_only(List,Reply) :-
     get(Char),name(Value,[Char]),
     member(Value,List),Reply = Value, !.
 
get_only(List,Reply) :-
     write(' [Invalid response.  Try again.] '),
     !,
     get_only(List,Reply).
 
 
convert_reply_to_confidence(?,_).
convert_reply_to_confidence(d,_).
convert_reply_to_confidence(n,0).
convert_reply_to_confidence(v,5).
convert_reply_to_confidence(u,25).
convert_reply_to_confidence(m,60).
convert_reply_to_confidence(p,80).
convert_reply_to_confidence(l,90).
convert_reply_to_confidence(y,100).
 
 
explain_question :-
     current_hypothesis(Hypothesis),
     writeln(
'This information is needed to test the following hypothesis:'),
     writeln(Hypothesis), nl,
     writeln('Do you want further explanation?'),
     explain_question_aux,!.
 
explain_question :-
     writeln('This is a basic hypothesis.'),
     nl, wait.
 
 
explain_question_aux :- \+ yes, nl, nl, !.
 
explain_question_aux :- nl, nl, fail.
 
 
explain_conclusion(Hypothesis) :-
     writeln('Do you want an explanation?'),
     yes, nl, nl,
     explain_conclusion_aux(Hypothesis), wait, !.
 
explain_conclusion(_) :- nl, nl.
 
 
explain_conclusion_aux([]) :- !.
 
explain_conclusion_aux([Hypothesis,_]) :-
     !, explain_conclusion_aux(Hypothesis).
 
explain_conclusion_aux([and,[Hypothesis,_],Rest]) :-
     !, explain_conclusion_aux(Hypothesis),
     explain_conclusion_aux(Rest).
 
explain_conclusion_aux([or,[Hypothesis,_],Rest]) :-
     !, explain_conclusion_aux(Hypothesis),
     explain_conclusion_aux(Rest).
 
explain_conclusion_aux(Hypothesis) :-
     known(Hypothesis,CF,user),
     kb_threshold(T),CF >= T,
     !, write(Hypothesis),writeln(' -'),
     write('From what you told me, I accepted this with '),
     write(CF),writeln('% confidence.'), nl.
 
explain_conclusion_aux(Hypothesis) :-
     known(Hypothesis,CF,user),
     !, DisCF is 100 - CF,
     write(Hypothesis),writeln(' -'),
     write('From what you told me, I rejected this with '),
     write(DisCF),writeln('% confidence.'), nl.
 
explain_conclusion_aux(Hypothesis) :-
     known(Hypothesis,50,no_evidence),
     !, write(Hypothesis),writeln(' -'),
     writeln(
          'Having no evidence, I assumed this was 50-50.'),
      nl.
 
explain_conclusion_aux(Hypothesis) :-
     !, known(Hypothesis,CF1,[CF,Prerequisites,Conditions]),
     writeln(Hypothesis),write('Accepted with '),
     write(CF1),
     writeln('% confidence on the basis of the following'),
     write('Rule: '),writeln(Hypothesis),
     write('  with confidence of '),
     write(CF),
     writeln('% if'),
     list_prerequisites(Prerequisites),
     list_conditions(Conditions), nl,
     explain_conclusion_aux(Conditions).
 
list_prerequisites([]) :- !.
 
list_prerequisites([-,Hypothesis|Rest]) :-
     !, write('  is disconfirmed: '),
     writeln(Hypothesis),
     list_prerequisites(Rest).
 
list_prerequisites([Hypothesis|Rest]) :-
     write('  is confirmed: '),
     writeln(Hypothesis),
     list_prerequisites(Rest).
 
 
list_conditions([]) :- !.
 
list_conditions([and,Hypothesis,Rest]) :-
     list_conditions(Hypothesis),
     list_conditions(Rest).
 
list_conditions([or,Hypothesis,Rest]) :-
     writeln(' ['),
     list_conditions(Hypothesis),
     writeln('     or'),
     list_conditions(Rest), writeln(' ]').
 
list_conditions([Hypothesis,yes]) :-
     write('    to confirm: '),
     writeln(Hypothesis).
 
list_conditions([Hypothesis,no]) :-
     write('    to disconfirm: '),
     writeln(Hypothesis).
 
wait :- write('Press Return when ready to continue. '),
        get0(_), nl, nl.
 
 
confidence_in([],100) :- !.
 
confidence_in([Hypothesis,yes],CF) :-
     known(Hypothesis,CF,_), !.
 
confidence_in([Hypothesis,yes],CF) :-
     ask_confidence(Hypothesis,CF), !,
     assert(known(Hypothesis,CF,user)).
 
confidence_in([Hypothesis,yes],CF) :-
     asserta(current_hypothesis(Hypothesis)),
     findall(X,evidence_that(Hypothesis,X),List),
     findall(C,member([C,_],List),CFList),
     retract(current_hypothesis(_)),
     CFList \== [],
     !, maximum(CFList,CF),
     member([CF,Explanation],List),
     assert(known(Hypothesis,CF,Explanation)).
 
confidence_in([Hypothesis,yes],50) :-
     assert(known(Hypothesis,50,no_evidence)), !.
 
confidence_in([Hypothesis,no],CF) :-
     !, confidence_in([Hypothesis,yes],CF0),
     CF is 100 - CF0.
 
confidence_in([and,Conjunct1,Conjunct2],CF) :-
     !, confidence_in(Conjunct1,CF1),
     confidence_in(Conjunct2,CF2),
     minimum([CF1,CF2],CF).
 
confidence_in([or,Disjunct1,Disjunct2],CF) :-
     !, confidence_in(Disjunct1,CF1),
     confidence_in(Disjunct2,CF2),
     maximum([CF1,CF2],CF).
 
 
evidence_that(Hypothesis,[CF,[CF1,Prerequisite,Condition]]):-
     c_rule(Hypothesis,CF1,Prerequisite,Condition),
     confirm(Prerequisite),
     confidence_in(Condition,CF2),
     CF is (CF1 * CF2)//100.
 
 
confirm([]).
 
confirm([-,Hypothesis|Rest]) :-
     !, known(Hypothesis,CF,_),
     kb_threshold(T),
     M is 100 - CF, M >= T,
     confirm(Rest).
 
confirm([Hypothesis|Rest]) :-
     known(Hypothesis,CF,_),
     kb_threshold(T),CF >= T,
     !, confirm(Rest).
 
 
minimum([M,K],M) :- M < K, ! .
minimum([_,M],M).
 
yes :-  write('--> '),
        get_yes_or_no(Response),
        !,
        Response == yes.
 
 
maximum([],0) :- !.
maximum([M],M) :- !.
maximum([M,K],M) :- M >= K, !.
maximum([M|R],N) :- maximum(R,K), maximum([K,M],N).
 
member(X,[X|_]).
member(X,[_|Z]) :- member(X,Z).

et la dernière est:

Code Prolog : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
% Menu that obtains 'yes' or 'no' answer
 
get_yes_or_no(Result) :- get(Char),              % read a character
                         get0(_),                % consume the Return after it
                         interpret(Char,Result),
                         !.                      % cut -- see text
 
get_yes_or_no(Result) :- nl,
                         write('Type Y or N:'),
                         get_yes_or_no(Result).
 
interpret(89,yes).  % ASCII 89  = 'Y'
interpret(121,yes). % ASCII 121 = 'y'
interpret(78,no).   % ASCII 78  = 'N'
interpret(110,no).  % ASCII 110 = 'n'

Ces fichiers si je les exécuter à partir Prolog (consulter mdc.pl en Prolog swi et le programme commence par des questions), ils fonctionnent très bien. La même chose quand je les appelle dans la java programme. Je peux voir le résultat dans la console d'Eclipse. Mais je voudrais construire quelque java gui pour l'interaction entre l'utilisateur et le système, mais je ne sais pas comment prendre le code de prologue en Java et le mettre dans l'interface graphique. Par exemple, comment puis-je répondre à la première question à partir d'une interface graphique Java et de communiquer la réponse au programme prolog?

Avez-vous des suggestions pour moi, s'il vous plaît?

S'il vous plaît excuser mon français, mais j'ai utilisé un traducteur automatique parce que malheureusement je ne parle pas le français.

J'espère que vous pourrez m'aider avec le code

merci