views:

576

answers:

9

I'm working on an application in Java, that needs to do some complex logic rule deductions as part of its functionality. I'd like to code my logic deductions in Prolog or some other logic/constraint programming language, instead of Java, as I believe the resulting code will be significantly simpler and more maintainable.

I Googled for embedded Java implementations on Prolog, and found number of them, each with very little documentation. My (modest) selection criteria are:

  • should be embeddable in Java (e.g. can be bundled up with my java package instead of requiring any native installations on external programs)
  • simple interface to use from Java (for initiating deductions, inspecting results, and adding rules)
  • come with at least a few examples on how to use it
  • doesn't necessarely have to be Prolog, but other logic/constraint programming languages with the above criteria would suit my needs, too.

What choices do I have and what are their advantages and disadvantages?

+4  A: 

SWI prolog A very popular implementation seems to have a Java interface as does SiCStus which would be easier than using JNI to instantiate an instance in your Java Process. I've used both from C quite a while ago and do recommend them. My prefference would be SWI as it is open-source and from my experience the de facto implementation.

The documentation for SWI's Java interface seems to be adequate, and the embedding process quite straight forward.

Hassan Syed
SWI Prolog and SiCStus require native installation to be usable from Java.
Sami
I'm sure you can package the executables or DLL's up to be included in your JAR files. SWI started as a unix application so I would assumed it does not do things which are required by real installers -- i.e., make registry changes or install com objects.
Hassan Syed
+2  A: 

Amzi prolog has been around for a while. I have used it briefly but not the embedded version. however they do have good documentation and support can be bought. They have Java port so it might be worth a look.

Vincent Ramdhanie
+3  A: 

According to Wikipedia, the following versions of Prolog have Java interfaces. I've linked to the main pages for them:

Good luck with your search!

Chip Uni
TuProlog seems like the only one of these that wouldn't require any external applications to be installed first. I'll look into that. Thanks.
Sami
I like TuProlog a lot. Documentation maybe isn't that hot, but implementation is pretty nice and, as you said, it doesn't require mixing things up.
JUST MY correct OPINION
+1  A: 

I've needed to do the same 2 years ago. I used SWI interface which is called JPL. It lets you load a Prolog file, assert on it and query on it. It does required an installation of SWI Prolog but that's not problem at all. SWI Prolog is available for many platforms.

I've also tried alternatives that were 100% implemented in Java and didn't required external programs. All them were buggy or hard to use. Don't waste your time.

Juanjo Conti
A: 

Prova 3.0 http://www.prova.ws is nearing completion. It is, however, not just another Prolog but a mix of programming styles, particularly, useful for easy bi-directional Java integration, reactive agent programming, integration with ESB's, workflow logic, and event processing. This version is a complete rewrite from zero so some older features, like OWL integration, are missing, but are bound to return in the next revision.

alexk
A: 

There's Mini-Kanren for Scala, which gives you a native JVM implementation of a lean, hackable, modern Horn-clause based logic programming language.

Charles Stewart
A: 

LPA does offer the LPA Intelligence Server as a way of embedding its Prolog engine within a whole variety of mainstream languages including Java, .Net etc

Clive

http://www.lpa.co.uk/int.htm

clive spenser
A: 

Another worthwhile option I recently came across is JSetL. It's not a Prolog, but a constraint programming library for Java, with support for logic variables, unification, constraint solving and non-determinism.

http://prmat.math.unipr.it/~gianfr/JSetL/index.html

Sami
A: 

There are a number of Prolog implementations in Java. They are not terribly fast, but convenient to use from within Java. Examples are: TuProlog or PrologCafe You can also have a look at the following Bachelor's thesis on the subject of Execution and Analysis of Prolog Programs in Java.

Michael