我有一个类似于动物识别模具的专家系统。这个程序可以在prolog中独立运行,现在我想基于java使用netbeans为它构建一个GUI。我知道如何查询第一个查询文件:
private void startDiagnose(){
Term consult_arg[] = {
new Atom( "C:/Users/Adrian/Desktop/WOU/wou.pl" )
};
Query consult_query =
new Query(
"consult",
consult_arg );
boolean consulted = consult_query.query();
if ( !consulted ){
System.err.println( "Consult failed" );
System.exit( 1 );
}
但是如何进行第二次查询:“ - ?go。” (通过在prolog中键入“go。”,可以在询问用户问题的情况下运行程序,并且用户答案应该是(是/否。)以继续以下问题)
专家系统的源代码:
/* wou.pro
wou intelligent ambassador.
start with ?- go. */
go:- hypothesize(Major),
write('The major I suggest you to choose is: ['),
write(Major),
write(']'),
nl,
undo.
/* hypotheses to be tested */
/* education*/
hypothesize(community_health_education) :- community_health_education, !.
hypothesize(school_health_education) :- school_health_education, !.
hypothesize(physical_education) :- physical_education, !.
hypothesize(special_education) :- special_education, !.
/*social science*/
hypothesize(history) :- history, !.
hypothesize(psychological_science) :- psychological_science, !.
hypothesize(anthropology) :- anthropology, !.
hypothesize(criminal_justice) :- criminal_justice, !.
hypothesize(environmental_studies) :- environmental_studies, !.
hypothesize(geography) :- geography, !.
hypothesize(political_science) :- political_science, !.
hypothesize(english) :- english, !.
/*engineering*/
hypothesize(cs) :- cs, !.
hypothesize(information_system) :-information_system, !.
/*science*/
hypothesize(mathematics) :- mathematics, !.
hypothesize(biology) :- biology, !.
hypothesize(chemistry) :- chemistry,!.
hypothesize(physics) :- physics, !.
hypothesize(nursing) :- nursing, !.
/*business*/
hypothesize(accounting) :- accounting, !.
hypothesize(economics) :- economics, !.
/*Art*/
hypothesize(painting) :- painting, !.
hypothesize(music) :- music, !.
hypothesize(dance) :- dance, !.
/*no major*/
hypothesize(no_major).
/* major identification rules */
community_health_education :- social,
education,
verify(working_for_a_community).
school_health_education :- social,
education,
verify(working_in_a_school).
physical_education :- social,
education,
verify(physical_training).
special_education :- social,
education,
verify(helping_special_population).
history :- social,
verify(antique),
verify(ancient_story).
psychological_science :- social,
verify(tv_show_lie_to_me).
anthropology :- social,
verify(studying_human_kind).
criminal_justice :- social,
verify(go_to_law_school).
environmental_studies :- social,
verify(environment_protection).
geography :- social,
verify(studying_the_earth).
political_science :- social,
verify(working_for_the_government).
english :- social,
verify(being_a_writer).
cs :- engineeringscience,
engineering,
verify(diy_desktop),
verify(coding).
information_system :- engineeringscience,
engineering,
verify(configuring_a_system).
mathematics :- engineeringscience,
verify(successione_di_fibonacci),
verify(solving_equations).
biology :- engineeringscience,
verify(origin_of_life),
verify(being_a_biologist).
chemistry :- engineeringscience,
verify(being_a_chemist).
physics :- engineeringscience,
verify(being_a_physicist).
nursing:- engineeringscience,
verify(being_a_nurse).
accounting :- business,
verify(using_excel),
verify(being_an_accountant),
verify(auditing).
economics :- business,
verify(monetary),
verify(being_an_ecomomist).
painting :- art,
verify(drawing).
music :- art,
verify(playing_instrucment).
dance :- art,
verify(opera),
verify(want_to_be_a_dancer).
/* classification rules */
social :- verify(reading_and_writing_editorial), !.
social :- verify(writing_more_than_mathematical_logic).
education :- verify(teaching_children),!.
education :- verify(being_a_high_school_teacher).
engineeringscience :- verify(quantitative_analysis), !.
engineeringscience :- verify(natural_phenomenon),
verify(discovery).
engineering :- engineeringscience,
verify(reparing_machine), !.
engineering :- engineeringscience,
verify(fixing_electronic_components),
verify(computer_games).
business :- verify(making_a_lot_of_money), !.
business :- verify(trading).
art :- verify(creative), !.
art :- verify(emotional).
/* how to ask questions */
ask(Question) :-
write('Do you like(or good at): '),
write(Question),
write('? (y/n)'),
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)
->
fail ;
ask(S))).
/* undo all yes/no assertions */
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.
答案 0 :(得分:0)
您可以按照执行第一个查询的方式执行第二个查询。
Query second_query = new Query("go");
consulted = second_query.query();
if ( !consulted ){
System.err.println( "Consult failed" );
System.exit( 1 );
}