Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

Both sides previous revision Poprzednia wersja
Nowa wersja
Poprzednia wersja
pl:miw:miw08_ruleruntimeg_2 [2008/03/17 19:33]
miw
pl:miw:miw08_ruleruntimeg_2 [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 ====== Opis ====== ​ ====== Opis ====== ​
 +__**Projekt zakończony**__
 +
 Damian Janicki <​janicki.damian@gmail.com>​ Damian Janicki <​janicki.damian@gmail.com>​
  
 Investigate runtime integration aspects, mainly semi-automatical building of a GUI for Prolog programs possibilities XPCE, Static QT/Gtk, Gtk-Server, Java (Swing), Eclipse (SWT) Investigate runtime integration aspects, mainly semi-automatical building of a GUI for Prolog programs possibilities XPCE, Static QT/Gtk, Gtk-Server, Java (Swing), Eclipse (SWT)
  
-    * input +    * inputXPCE, QT, GTK, GtkServer, Java etc., SWI Prolog documentation
- +
-XPCE, QT, GTK, GtkServer, Java etc., SWI Prolog documentation +
- +
-    * output+
  
-Feasibility study, a prototype.+    * output: Java/​JPL, ​Feasibility study, a prototype.
  
     * integration options for Java: JPL (SWI),​Logtalk (OO Prolog), architecture:​ MVC     * integration options for Java: JPL (SWI),​Logtalk (OO Prolog), architecture:​ MVC
     * approach: 2 -3 app. cases, M prolog, V in Java, C -> JPL/​Logtalk,​ e.g. ready M in Prolog, build V in Java: Car ES, opposite: ready MV i Java, build M in Prolog, make it work with the V     * approach: 2 -3 app. cases, M prolog, V in Java, C -> JPL/​Logtalk,​ e.g. ready M in Prolog, build V in Java: Car ES, opposite: ready MV i Java, build M in Prolog, make it work with the V
  
-====== ​Spotkania ​======  +[[pl:​miw:​miw08_ruleruntimeg_2_spotkania|Spotkania]]
-===== 08.03.04 ===== +
-  * **MISSED** prototyp dla car, tj. ask_question +
- +
-===== 080311 ===== +
-  * problems, problems +
- +
-===== 080318 ===== +
-  * przerobienie car na wywołanie V w Javie+
  
 ====== Projekt ====== ====== Projekt ======
 Oryginalny system ([[pl:​prolog:​prolog_lab:​prolog_lab_2#​tematprosty_system_ekspertowy]]) Oryginalny system ([[pl:​prolog:​prolog_lab:​prolog_lab_2#​tematprosty_system_ekspertowy]])
  
 +=== Wersja 1 ===
 +
 +== Predykat tworzący dialog, za pomocą, którego pobieramy informacje od użytkownika ==
 <code prolog> <code prolog>
-% From the book +show_yes_no_dialog(Tekst,​Response) :- 
-% PROLOG PROGRAMMING IN DEPTH + jpl_new(array(class([java,​lang],​['​String'​])),​['​yes','​no'​],​ ArrayRef), 
-% by Michael ACovingtonDonald Nuteand Andre Vellino + jpl_get(ArrayRef,​0,​ArrayPosRef),​ 
-(Prentice Hall1997). + jpl_get('​javax.swing.JOptionPane'​'​YES_NO_OPTION',​ YesNoRef)
-% Copyright 1997 Prentice-HallInc. + jpl_get('​javax.swing.JOptionPane'​'​QUESTION_MESSAGE',​ QuestionRef)
-% For educational use only+ jpl_call('​javax.swing.JOptionPane',​ '​showOptionDialog',​ [@(null), 
 +        Tekst,  
 +        '​Question',​ 
 +        ​YesNoRef,​ 
 +        ​QuestionRef,​ 
 +        ​@(null),​  
 +        ​ArrayRef,​  
 +        ​ArrayPosRef],​  
 +        ​RetVal),​ 
 + interpret(RetVal,​Response).
  
-% File CAR.PL +interpret(1,​no).  
-% Simple automotive expert system+interpret(0,​yes).  
 +</​code>​
  
-:- consult('getyesno.pl'​). ​ % Use ensure_loaded if available.+== Predykat tworzący dialog, który wyświetla informacje o uszkodzeniach == 
 +<code prolog>​ 
 +show_explain_dialog(Tekst) ​:- 
 + jpl_call('javax.swing.JOptionPane',​ '​showMessageDialog',​ [@('​null'),Tekst],_). 
 +</​code>​
  
-% 
-% Main control procedures 
-% 
  
-start :- +== Predykat ask_question == 
-   ​write('​This program diagnoses why a car won''​t start.'​),​nl,​ +Przed zmianami: 
-   ​write('​Answer all questions with Y for yes or N for no.'),nl, +<code prolog>​ 
-   clear_stored_answers,​ +ask_question(starter_was_ok) ​:- 
-   ​try_all_possibilities.+   ​write('​When you first started trying to start the car,'​),​nl,​ 
 +   ​write('​did the starter crank the engine normally? ​'),nl. 
 +</​code>​
  
-try_all_possibilities ​:-     % Backtrack through all possibilities... +Po zmianach (korzysta z Java)
-   defect_may_be(D)+<code prolog>​ 
-   explain(D), +ask_question(starter_was_ok,Res) :- 
-   fail.+ show_yes_no_dialog('When you first started trying to start the car did the starter crank the engine normally?'​,Res). 
 +</​code>​
  
-try_all_possibilities      % ...then succeed with no further action.+== Predykat explain ​ == 
 +Przed zmianami: 
 +<code prolog>​ 
 +explain(wrong_gear) :- 
 +   nl, 
 +   ​write('​Check that the gearshift is set to Park or Neutral.'​),​nl,​ 
 +   ​write('​Try jiggling the gearshift lever.'),nl. 
 +</​code>​
  
 +Po zmianach:
 +<code prolog>
 +explain(wrong_gear) :-
 + show_explain_dialog('​Check that the gearshift is set to Park or Neutral.Try jiggling the gearshift lever.'​).
 +</​code>​
  
-% +== Predykat user_says: == 
-% Diagnostic knowledge base +Przed: 
-%   (conditions under which to give each diagnosis+<code prolog>​ 
-%+user_says(Q,A:- \+ stored_answer(Q,​_),​ 
 +                  ask_question(Q),​ 
 +                  get_yes_or_no(Response),​ 
 +                  asserta(stored_answer(Q,​Response)),​ 
 +                  Response = A. 
 +</​code>​ 
 +Po: 
 +<code prolog>​ 
 +user_says(Q,​A) :- \+ stored_answer(Q,​_),​ 
 +                  ask_question(Q,​Response),​ 
 +   asserta(stored_answer(Q,​Response)),​ 
 +                  Response = A. 
 +</​code>​
  
-defect_may_be(drained_battery:- +V: Interfejs w Javie 
-   user_says(starter_was_ok,yes), +== Funkcja wywolujaca prologa == 
-   user_says(starter_is_ok,​no).+<code java> 
 +private void startDiagnose(){ 
 + Query queryConsult = new Query("​consult"​new Atom("​pl/​carJPL.pl"​)); 
 + queryConsult.query()
 +  
 + Query start = new Query("​start"​);​ 
 + start.query(); 
 +
 +</​code>​
  
-defect_may_be(wrong_gear) :- +=== Wersja 2 === 
-   user_says(starter_was_ok,​no).+W stosunku do wersji pierwszej deklaracje dialogów z pytaniem do użytkownika znajduja się w klasie MessageDialogsDzieki temu poziomu prologu wołana jest tylko jedna funkcja:
  
-defect_may_be(starting_system) :- +Klasa MessageDialogs 
-   user_says(starter_was_ok,​no).+<code java> 
 +import javax.swing.JOptionPane;​
  
-defect_may_be(fuel_system:- +public class MessageDialogs { 
-   user_says(starter_was_ok,​yes), +  
-   user_says(fuel_is_ok,no).+ public static String showYesNoDialog(String A_strMessage
 +
 + String strRetVal = new String(""​)
 + Object[] options = {"​Yes"​"​No"​};​ 
 + int nRetVal = JOptionPane.showOptionDialog( null, 
 + A_strMessage,​ 
 + "​Question",​ 
 + JOptionPane.YES_NO_OPTION,​ 
 + JOptionPane.QUESTION_MESSAGE,​ 
 + null, 
 + options,​ 
 + options[0]);​ 
 +  
 + if(nRetVal == 1) 
 + strRetVal = "​yes";​ 
 + else if (nRetVal == 0) 
 + strRetVal = "no"; 
 +  
 + return strRetVal;​ 
 +
 +  
 + public static void showInformation(String A_strMessage)
 + JOptionPane.showMessageDialog(null,​ A_strMessage);​ 
 +
 +
 +</​code>​
  
-defect_may_be(ignition_system) :- +Predykat show_yes_no_dialog : 
-   user_says(starter_was_ok,yes), +<code prolog>​ 
-   ​user_says(fuel_is_ok,yes).+show_yes_no_dialog(Tekst,​Response) :-  
 + jpl_call('​dialog.MessageDialogs'​'​showYesNoDialog'​[Tekst]Response). 
 +</​code>​
  
  
-+[[pl:​miw:​miw08_ruleruntimeg_2:​pliki|Źródła projektu]]
-% Case knowledge base +
-%   ​(information supplied by the user during the consultation) +
-%+
  
-:- dynamic(stored_answer/​2). 
  
-   % (Clauses get added as user answers questions.) 
  
 +====== Sprawozdanie ======
 +[[pl:​miw:​miw08_ruleruntimeg_2:​pliki|Źródła projektu]]
  
-% +===== Cel projektu ===== 
-% Procedure to get rid of the stored answers +Celem projektu było stworzenie aplikacji, której modelem jest jest program Varda napisany w języku prolog, natomiast interfejs miał być stworzony w języku java. Komunikacja pomiędzy java, a prologiem miała odbywać się za pomocą biblioteki JPL. 
-% without abolishing the dynamic declaration +
-%+
  
-clear_stored_answers :- retract(stored_answer(_,_)),fail. +===== Wykonanie ===== 
-clear_stored_answers.+W ramach projektu udało się zrealizować interfejs graficzny napisany w języku Java do programu Varda. Program składa się z klas javaktóre tworzą GUIoraz klas, które są odpowiedzialne za komunikacje z prologiemW projekcie znajduje się także plik prologa, gdzie zdefiniowane są odpowiednie zapytania pobierające informacje z programu varda.
  
  
-% 
-% Procedure to retrieve the user's answer to each question when needed, 
-% or ask the question if it has not already been asked 
-% 
  
-user_says(Q,​A) :- stored_answer(Q,​A).+==== Najważniejsze pliki ==== 
 +  * MainFrame.java - klasa tworząca interfejs użytkownika
  
-user_says(Q,​A) :\+ stored_answer(Q,_), +  * SplitData.java ​klasa przetrzymująca informacje o elementachna których należy wykonać operacje split
-                  nl,nl, +
-                  ask_question(Q),​ +
-                  get_yes_or_no(Response),​ +
-                  asserta(stored_answer(Q,​Response)),​ +
-                  Response = A.+
  
 +  * VardaControl.javc - klasa, która za pomocą odpowiednich predykatów pobiera informacje z programu Varda, które następnie przekazywane są do MainFrame lub do SplitData (dla operacji split). Klasa odpowiada również za wysyłanie danych do prologa gdy wykonujemy operacje takie jak split, finalize.
  
-+  * gui_query.pl - plik prologa, w którym znajdują się predykaty potrzebne do pobierania informacji z programu varda, np. pobieranie atrybutów które możemy zesplitowac,​ lub zfinalizować w danym momencie. ​
-% Texts of the questions +
-%+
  
-ask_question(starter_was_ok) :- 
-   ​write('​When you first started trying to start the car,'​),​nl,​ 
-   ​write('​did the starter crank the engine normally? '),nl. 
  
-ask_question(starter_is_ok) :- +==== Funkcje programu ==== 
-   write('​Does the starter crank the engine normally now? '),nl.+Program posiada wszystkie możliwości programu Varda. Za pomocą interfejsu graficznego możemy dodawać atrybutytworzyć nowe property, a także wykonywac operacje finalize i split. Program jest tak skonstruowany aby użytkownik w danym momencie mógł wykonać tylko dozwolone operacje.  
 +Dodatkowo z poziomu programu możemy wyświetlić diagramy ARD, TPH, wygenerować i wyświetlić XTT
  
-ask_question(fuel_is_ok) :- 
-   ​write('​Look in the carburetor. ​ Can you see or smell gasoline?'​),​nl. 
  
  
-% 
-%  Explanations for the various diagnoses 
-% 
  
-explain(wrong_gear) :- +=====  Uruchomianie projektu ===== 
-   nl, +Aby uruchomić program należy posiadać bibliotekę JPLSposób instalacji oraz źródła projektu znajdują się [[pl:​miw:​miw08_ruleruntimeg_2:​pliki|tutaj]] 
-   ​write('​Check that the gearshift is set to Park or Neutral.'),nl, +$PROLOG_HOME/​lib/​i386-linux/​ - jest scieżka do katalogu w którym znajduje się plik libjpl.so  
-   write('​Try jiggling the gearshift lever.'),nl.+$PROLOG_HOME jest scieżką do katalogu w którym zainstalowany jest Swi-prolog.
  
-explain(starting_system) :- 
-   nl, 
-   ​write('​Check for a defective battery, voltage'​),​nl,​ 
-   ​write('​regulator,​ or alternator; if any of these is'​),​nl,​ 
-   ​write('​the problem, charging the battery or jump-'​),​nl,​ 
-   ​write('​starting may get the car going temporarily.'​),​nl,​ 
-   ​write('​Or the starter itself may be defective.'​),​nl. 
  
-explain(drained_battery) ​:- +Istnieją trzy możliwości uruchomienia projektu: 
-   nl, + 
-   write('​Your attempts to start the car have run down the battery.'),nl+  * Należy sciągnąć {{:​pl:​miw:​miw08_ruleruntimeg_2:​Varda_source.tar.gz|źródła }} projektu i następnie skompilować je za pomocą polecenia javac: 
-   write('​Recharging or jump-starting will be necessary.'),nl, + 
-   write('​But there is probably nothing wrong with the battery itself.'),nl.+javac -classpath $PROLOG_HOME/​lib/​jpl.jar . 
 +gdzie zmienna $PROLOG_HOME jest scieżką do katalogu w którym zainstalowany jest Swi-prolog. 
 + 
 +Następnie uruchamiamy projekt za pomocą polecenia:  
 + 
 +java -classpath $PROLOG_HOME/​lib/​jpl.jar -Djava.library.path=$LD_LIBRARY_PATH:​$PROLOG_HOME/​lib/​i386-linux/​ .:​$PROLOG_HOME/​lib/​jpl.jar MainFrame 
 + 
 +  * Drugim sposobem jest ściągniecie już skompilowanego {{:​pl:​miw:​miw08_ruleruntimeg_2:​varda_jar.tar.gz|projektu}}który należy uruchomić poleceniem: 
 + 
 +java -jar -Djava.library.path=$LD_LIBRARY_PATH:​$PROLOG_HOME/​lib/​i386-linux/​ -classpath $PROLOG_HOME/​lib/​jpl.jar ​ VardaFrame_fat.jar 
 + 
 +  * Trzecim sposobem jest ściągniecie projektu eclipse {{:​pl:​miw:​miw08_ruleruntimeg_2:​varda_projektEclipsee.tar.gz|z archiwum tar.gz}} lub z repozytorium SVN: 
 + 
 +http://​svn2.assembla.com/​svn/​MIVprojekt/​VardaFrame
  
-explain(fuel_system) :- 
-   nl, 
-   ​write('​Check whether there is fuel in the tank.'​),​nl,​ 
-   ​write('​If so, check for a clogged fuel line or filter'​),​nl,​ 
-   ​write('​or a defective fuel pump.'​),​nl. 
  
-explain(ignition_system) :- 
-   nl, 
-   ​write('​Check the spark plugs, cables, distributor,'​),​nl,​ 
-   ​write('​coil,​ and other parts of the ignition system.'​),​nl,​ 
-   ​write('​If any of these are visibly defective or long'​),​nl,​ 
-   ​write('​overdue for replacement,​ replace them; if this'​),​nl,​ 
-   ​write('​does not solve the problem, consult a mechanic.'​),​nl. 
-</​code>​ 
  
-V: Interfejs w Javie 
  
-<code java> 
-</​code>​ 
  
-====== Sprawozdanie ====== 
  
 ====== Materiały ====== ====== Materiały ======
-[[pl:​miw:​miw08_umlandardxtt:​notatki|wszystkie pliki]]+
  
 [[http://​www.swi-prolog.org/​packages/​jpl/​|JPL - Prolog/Java interface]] [[http://​www.swi-prolog.org/​packages/​jpl/​|JPL - Prolog/Java interface]]
pl/miw/miw08_ruleruntimeg_2.1205778832.txt.gz · ostatnio zmienione: 2019/06/27 15:58 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0