Subject: Re: Interfacing Java and Prolog both ways

From: Fred Dushin <[email-masked]>
Date: Sat, 22 Jan 2000 11:16:21 -0500

> Yes indeed! We have just been working on a system in which Java is the motor
> behind an 'intelligent' web application, which calls Prolog for some
> reasoning tasks. But then Prolog calls back on the Java program to ask for
> SQL-queries in an Access-database, since we weren't able to call to the
> database directly.
> We are working in B-Prolog, which is largely the same as SWI-Prolog. The
> Java program incorporates a an object called prologinterface, which consists
> of a function that call Prolog, called 'askQuestion' (asks Prolog to
> interpret a written Dutch sentence), and several functions that can be
> called by Prolog, like 'returnOutput' (delivers output in string format to
> the output stream) and 'selectDBQuery' (takes paramaters from Prolog to
> construct an SQL-query, then returns the result in a certain format to
> Prolog).

I see how that can be useful, but it looks like your selectDBQuery has to be
coded directly into C, whose implementation then calls the JNI to get an
instance of some class (perhaps as a static/globally accessible structure),
marshalls the data from Prolog engine into arguments for some Java class method,
and then makes the call to the method (which I presume then uses the JDBC to
send and receive SQL queries).

That's fine, but what I am after is a general enough interface so that Java
classes and methods can be invoked seamlessly from Prolog without the user
having to touch any C.  This, after all, is what JPL provides in the opposite
direction.  Unfortunately, the only way I can see to do this would be to
implement the JNI as a set of foreign predicates.  This is a rather large
undertaking, however, and it would be incredibly cumbersome on the programmer.

Another idea is to think about alternative technologies.  CORBA is one that
comes to mind; it provides a language-neutral way to write interfaces between
different languages.  To my knowledge, there is no (standard) Prolog mapping
from IDL, though, so that is something that would need some thought, though it
looks like Jan has covered some of that territory.  But having an ORB in the
Prolog engine would be pretty nice.  It would actually make JPL unecessary
(insofar as it is necessary at all...)  But I can also see how Prolog purists
might scoff at the idea.  I can't see non-deterministic CORBA calls going over
so well.

Jan, any status on your work with CORBA and Prolog?  I saw your online paper,
but I wasn't sure where you had taken that work.

Fred