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 necessarily 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?
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.
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
There's Mini-Kanren for Scala, which gives you a native JVM implementation of a lean, hackable, modern Horn-clause based logic programming language.
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.
Prof. Paul Tarau made available from his page several implementations
Jinni Prolog
Kernel Prolog
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!