簡體   English   中英

Prolog連接到Java

[英]Prolog connect to Java

我有一個類似於動物識別模具的專家系統。 該程序可以在prolog中獨立運行,現在我想使用netbeans基於Java為它構建一個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”。 (通過在序言中鍵入“ 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.

您可以按照執行第一個查詢的相同方式執行第二個查詢。

Query second_query = new Query("go");

consulted = second_query.query();

if ( !consulted ){
  System.err.println( "Consult failed" );
  System.exit( 1 );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM