2014-02-18 4 views
1

У меня есть экспертная система, подобная форме идентификации животных. Эта программа может запускаться независимо в прологе, теперь я хочу создать для нее графический интерфейс на основе java, используя netbeans. Я знаю, как сделать первый запрос проконсультироваться файл:Пролог подключиться к Java

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); 
     } 

Но как я могу сделать второй запрос: «- идти.» (Введя в «идти». В Прологе программу можно запускать с задавать вопросы пользователя, и пользователь ответ должен быть (Y/N), чтобы продолжить следующие вопросы.)

Исходный код экспертной системы:

/* 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

Вы можете выполнить второй запрос так же, как вы выполнили первый.

Query second_query = new Query("go"); 

consulted = second_query.query(); 

if (!consulted){ 
    System.err.println("Consult failed"); 
    System.exit(1); 
} 
Смежные вопросы