45

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?

false
  • 10,264
  • 13
  • 101
  • 209
Sami
  • 3,263
  • 3
  • 29
  • 37
  • 1
    I've never used a Prolog-in-Java, but another option is to write your own. I know of at least 2 Lisp books which do this in not too many pages (On Lisp, and PAIP), so it can't be *that* hard, even in Java. – Ken Nov 29 '09 at 22:52
  • 4
    Sure, you can make a toy logic programming language in a few pages of code, but I'm looking for something a bit more robust. Now, you can do a toy lisp in a couple of pages of code too, so I guess I'll just need four pages and I'll good to go :-) – Sami Nov 30 '09 at 00:35
  • Those are some loaded words you're throwing around! I'm not sure what makes a small Prolog implementation a "toy", or in what way they're not "robust" enough. One of Norvig's lessons was "Prolog is similar to Lisp on the main points"; a tiny Prolog-on-Lisp, then, isn't a "toy", but rather a different UI for your compiler. It won't be as much fun in Java but I don't think he was doing *that* much with macros. – Ken Dec 05 '09 at 05:55
  • 1. No libraries. 2. No syntax. While with Lisp, you can reuse the Lisp syntax and Lisp libraries ("Prolog is similar to Lisp on the main points"), this is not so with Java. Instead, you'd end up having to also implement the parser and the libraries. Additionally, even with the Lisp implementation, the lack of use of Prolog syntax and libraries prevents you from using any externally available Prolog libraries. – Sami Dec 05 '09 at 18:48
  • 1
    Sure, you can claim that you can reuse the Java syntax and libraries in a similar way as to how you would use anonymous objects instead of closures. But as anyone with functional programming experience who has tried this knows, the added complexity and verbosity of the syntax just makes this mostly just a painful exercise. – Sami Dec 05 '09 at 18:49
  • Have you tried Drools? It's a full production system (rete) in Java and easily deployed. http://www.jboss.org/drools – ProfVersaggi Jan 18 '14 at 16:36

13 Answers13

23

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!

false
  • 10,264
  • 13
  • 101
  • 209
Chip Uni
  • 7,454
  • 1
  • 22
  • 29
  • 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 Nov 30 '09 at 00:38
  • 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 Mar 03 '10 at 10:26
  • 2
    Wikipedia lists much more Prolog systems with Java interface: JIProlog, Jekejeke Prolog, JLog, jTrolog, XSB Prolog, YAP Prolog. –  Oct 24 '12 at 16:28
  • TuProlog is awesome, can be embedded, and is quite flexible. I've ported it to Android. – ProfVersaggi Jan 18 '14 at 19:46
9

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
  • 20,075
  • 11
  • 87
  • 171
  • 1
    SWI Prolog and SiCStus require native installation to be usable from Java. – Sami Nov 30 '09 at 00:40
  • 2
    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 Nov 30 '09 at 01:12
7

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
  • 28,823
  • 42
  • 111
  • 133
5

Clojure is a JVM based Lisp-like language with a library (core.logic) supporting logic and constraint based programming. Clojure also has a large number of facilities for generating java classes and working with java code, so inter-op between the two languages is trivial.

deterb
  • 3,994
  • 1
  • 28
  • 33
4

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
  • 102,349
  • 23
  • 137
  • 192
3

Prof. Paul Tarau made available from his page several implementations

Jinni Prolog

Kernel Prolog

CapelliC
  • 59,646
  • 5
  • 47
  • 90
3

You can also take a look at the Prol engine that I created. It allows you to embed Prolog into your Java programs (but it is not very fast one)

Igor Maznitsa
  • 833
  • 7
  • 12
Igor M.
  • 31
  • 1
2

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

2

Two commercial Prologs written in Java: Minerva by IF Computer Japan and Jekejeke. Both are very close to ISO.

false
  • 10,264
  • 13
  • 101
  • 209
1

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
  • 11
  • 1
1

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
  • 11,661
  • 4
  • 46
  • 85
1

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
  • 3,263
  • 3
  • 29
  • 37
1

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
  • 121
  • 1