Embedded Prolog Interpreter/Compiler for Java
Asked Answered
X

13

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?

Xylia answered 29/11, 2009 at 22:30 Comment(6)
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.Chorography
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 :-)Xylia
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.Chorography
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.Xylia
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.Xylia
Have you tried Drools? It's a full production system (rete) in Java and easily deployed. jboss.org/droolsEmplane
P
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!

Privileged answered 29/11, 2009 at 23:1 Comment(4)
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.Xylia
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.Vindication
Wikipedia lists much more Prolog systems with Java interface: JIProlog, Jekejeke Prolog, JLog, jTrolog, XSB Prolog, YAP Prolog.Bronchiole
TuProlog is awesome, can be embedded, and is quite flexible. I've ported it to Android.Emplane
C
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.

Charlacharlady answered 29/11, 2009 at 22:43 Comment(2)
SWI Prolog and SiCStus require native installation to be usable from Java.Xylia
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.Charlacharlady
S
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.

Solana answered 30/11, 2009 at 16:30 Comment(0)
T
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.

Tasse answered 22/12, 2011 at 18:4 Comment(0)
L
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.

Labanna answered 29/11, 2009 at 22:51 Comment(0)
H
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)

Holliman answered 5/7, 2011 at 14:13 Comment(0)
D
3

Prof. Paul Tarau made available from his page several implementations

Jinni Prolog

Kernel Prolog

Dissertation answered 20/11, 2013 at 14:54 Comment(0)
S
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

Sienna answered 22/3, 2010 at 12:28 Comment(0)
K
2

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

Keifer answered 6/7, 2011 at 5:16 Comment(0)
T
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.

Tauro answered 21/1, 2010 at 19:16 Comment(0)
H
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.

Helmer answered 3/3, 2010 at 10:2 Comment(0)
X
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

Xylia answered 13/4, 2010 at 13:20 Comment(0)
L
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.

Lapidary answered 21/4, 2010 at 6:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.