简体   繁体   English

Prolog连接到Java

[英]Prolog connect to Java

I have an expert system similar to animal identification mold. 我有一个类似于动物识别模具的专家系统。 This program can be run independently in prolog, now I want to build a GUI for it based on java using netbeans. 该程序可以在prolog中独立运行,现在我想使用netbeans基于Java为它构建一个GUI。 I know how to do the first query to consult the file: 我知道如何做第一个查询来查询文件:

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

But how can I do the second query: "-? go." 但是我该怎么做第二个查询:“-?go”。 ( By typing in "go." in prolog the program can be run with asking user questions, and user answer should be (Y/N.)to continue the following questions) (通过在序言中键入“ go。”,程序可以在询问用户问题的情况下运行,并且用户答案应该为(是/否)以继续以下问题)

The source code of Expert System: 专家系统的源代码:

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

You can execute second query in the same way you executed the first one. 您可以按照执行第一个查询的相同方式执行第二个查询。

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