JIP - Java Internet Prolog - By Ugosoft

How to...

BLUE_THIN_LINE.gif (1434 bytes)

| Home | Presentation | JIP Console | Built-In | API | Intelligent Applets | Contacts |

BLUE_THIN_LINE.gif (1434 bytes)

How to run JIPConsole as an application:

Fisrt of alla you must have installed on your machine the Java™ Development Kit JDK 1.1.x or later or the Java™ Runtime Environment JRE 1.1.x or later. You can download them from:

http://www.javasoft.com/products/jdk/1.1/ http://www.javasoft.com/products/jdk/1.1/jre/index.html

To run JIPConsole:

- if you add JIPackage.zip package to the classpath environment variable you can use

 java JIP.JIPConsole

- otherwise you would use

 java -classpath %CLASSPATH%;<JIPDir>/JIPPackage.zip JIP.JIPConsole

prev.gif (8311 bytes)


How to run your prolog code as a "stand alone" application using JIProlog interpreter

Fisrt of alla you must have installed on your machine the Java™ Development Kit JDK1.1.x or later or the Java™ Runtime Environment JRE1.1.x or later. You can download them from:

http://www.javasoft.com/products/jdk/1.1/ http://www.javasoft.com/products/jdk/1.1/jre/index.html

Then, you must define in your prolog code the entry-point predicate main/0 (it will be called when the interpreter will start) as the example belows:

main:-
    winputbox("Insert something", X),
    write(X), nl,
    wmsgbox(X).

Finally you can run you prolog code by JIProlog interpreter:

- if you add JIPackage.zip package to the classpath environment variable you can use

 java JIP.JIProlog <MyPrologFile>

- otherwise you have to use

 java -classpath %CLASSPATH%;<JIPDir>/JIPPackage.zip JIP.JIProlog <MyPrologFile>

prev.gif (8311 bytes)


How to trace your program by JIPConsole:

1) Check the box "Trace" between the buttons below.
2) Type your query and press <enter>. A trace window will appear with three buttons: "Step", "Skip", "Abort"

Press "Step" button to go to next step, press "Skip" to skip trace or "Abort" to stop the execution.

prev.gif (8311 bytes)


How to write a custom Dialog:

Suppose you have a dialog class MyDialog derived from java.awt.Dialog that you would use in JIP. You must create a new class following the skeleton shown below:

public class MyDialog4JIP extends MyDialog implements JIPDialog
{
   
public MyDialog4JIP(Frame parent, JIPTerm input)
    {
        super
(parent, "Caption", "Title"); // or another constructor
       
  ...
        // (manage the input term as you need)

   
}
     
    public
JIPTerm getOutput()
    {

         return
outputTerm;
    }


    public
boolean
succeeds()
    {

         return
// true if the user operations succeed or false otherwise
    }
}

An example is the message box shown by wmsgbox/1 predicate (wmsgbox(Message)):

class JIPMessageDialog extends MessageDialog implements JIPDialog
{
   
public JIPMessageDialog(Frame parent, JIPTerm input)
       {
                super(parent, "JIP - Message", input.toString());
       }

       public JIPTerm getOutput()
       {
 
              return null;
       }

       public boolean
succeeds()
      {
               return true;
      }
}

prev.gif (8311 bytes)


How to write a custom extension class:

Suppose you have a Java™ class MyClass derived from any Java™ classes that you would use in JIP. You have to create a new class following the skeleton shown below:

public class MyClass4JIP extends AnyClass implements JIPXCall
{
   
public My
Class4JIP()
    {
        super
(); // or another constructor
       
  ...
    }

    public
void invoke()
    {
        ... // your implementation calling the methods of your class
         

    }

     
    public
JIPTerm getOutput()
    {

         return
outputTerm;
    }


    public
boolean
succeeds()
    {

         return
//
true if "invoke" succeeds or false otherwise
    }
}

An example is the implementation of a class that generate random numbers in the range [min, max]:

public class RandomNumberGen extends Random implements JIPXCall
{
       int m_nMin, m_nMax;

       public void invoke(JIPTerm input)
       {
             if(input.isList())
             {
                     JIPList list = input.getList();
                     JIPNumber min = list.getHead().getNumber();
                     JIPNumber max = list.getTail().getHead().getNumber();
                     m_nMin = (int)min.getValue();
                     m_nMax = (int)max.getValue();
             }
             else
             {
                     throw new RuntimeException("The second parameter is bad");
             }
   }

   public JIPTerm getOutput()
   {
     
int n = (int)(nextDouble() * (double)(m_nMax - m_nMin + 1)) + m_nMin;
            return JIPNumber.getNewNumber(n);
      }

      public boolean succeeds()
      {
             return true;
      }
}

prev.gif (8311 bytes)


How to write an external database of clauses:

An external database of clauses is a database not stored in the prolog memory but in an external device such as JDBC database, text database and so on. 
Sometimes when you have a lot of facts related to a single predicate that are modified outside the prolog (such as a data-entry process or similar) you wish to have them in an external database so you don't have to import them in the prolog database. JIProlog allow you to use an external database of facts as it was in the prolog memory.

The predicate extern/3 allow you to declare a predicate as an external predicate.

To implement a database of clauses you must derive a class from the abstract class JIPClausesDatabase and implement a JIPClausesEnumeration to enumerate the facts in sequence.

You must implement:

/** Set attributes to pass to the database (i.e. login info, filename, etc.) 
public abstract void setAttributes(String strAttribs);

/** Add a clause to the database at the position specified 
public
abstract synchronized boolean addClauseAt(int nPos, JIPClause clause);

/** Append a clause to the database
public
abstract synchronized boolean addClause(JIPClause clause);

/** Remove a clause to the database
public
abstract synchronized boolean removeClause(JIPClause clause);

/** Return an enumeration of clauses contained in the database
public
abstract synchronized Enumeration clauses();

Then you must implement the method:

/** Get next clause in the enumeration of clauses 
public abstract JIPClause nextClause();

As an example, the files TextClausesDatabase.java and TextClausesEnumeration.java implement a detabase of clauses stored in a text file.

You can try it in JIP by typing:

JIP:-extern(foo/3, "JIP.TextClausesDatabase", "database.txt").
yes

JIP:-foo(X,Y,Z).

prev.gif (8311 bytes)

 

BLUE_THIN_LINE.gif (1434 bytes)

| Home | Presentation | JIP Console | Built-In | API | Intelligent Applets | Contacts |

BLUE_THIN_LINE.gif (1434 bytes)

Copyright © Ugo Chirico

This page hosted by Get your own Free Home Page