Java Prolog Interface API is distributed with implementation adapter and concrete prolog driver library until it is possible according to related libraries licenses. The distributions are named normally such that prolobjectlink-jpi-jpl7-swi7-x.y.z-dist.zip meaning that this distribution is a JPI implementation over JPL version 7 or above and SWI-Prolog version 7 or above. The x.y.z is the distribution version. The distribution can be downloaded in zip or tar.gz compresses format. To install you need perform the following steps:
For the JPI beginners we recommended start with a Pure Java-Prolog Engine because have less configuration aspects and native engine are more difficult to link.
After download and unzip JPI distribution in the final JPI folder you will see the following structure:
Folder/File | Description |
bin | Binaries scripts |
docs | Documentation |
prt | Prolog programs files |
lib | Library jars files |
obj | Programs to link native engine procedures |
src | Adapter source folder |
CONTRIBUTING | Binaries scripts |
LICENSE | Binaries scripts |
NOTICE | Binaries scripts |
README | Binaries scripts |
In general way and in bottom-up order the JPI architecture is composed by the guest Operating System at low level. Over this level we find compatible with guest Operating System and Native Prolog Engines implementations. Over this level we find Pure Java Prolog Engine implementations and Java Driver libraries to Native Prolog Engine. Over this layer is the JPI interface adapter implementation for your correspondent Java Prolog Driver. In the top level we find a User Application that use the JPI interface.
User Application | ||||||
JPI | ||||||
JPI-JPL | JPI-JLOG | JPI-TUPROLOG | JPI-INTERPROLOG | |||
JPL | jLog | tuProlog | Interprolog | |||
SWI | YAP | JVM | XSB | |||
OS |
After installation and architecture compression you can use the hello world sample for test the system integration. This hello world sample show how interacts with JPI from Java programming language with Abstracted Prolog Engine. For the first experience we suggesting use a Java-based Prolog engine like tuProlog because have less configuration aspects.
Create in your preferred development environment an empty project. Set in the project build path the JPI downloaded libraries located at lib folder. Create a Main Java class that look like below code:
public class Main { public static void main(String[] args) { PrologProvider provider = Prolog.getProvider(Swi7Prolog.class); PrologEngine engine = provider.newEngine(); engine.asserta("sample('hello wolrd')"); PrologQuery query=engine.query("sample(X)"); System.out.println(query.one()); } }