As previously mentioned, I have an actual business requirement that involves migrating a rules engine to a Java environment.  I am starting to review various functional programming languages after the CodeMash conference heightened my awareness them.

I have prior experience playing with Prolog, so I started with it.  I had already written a simplified two-card poker game using tuProlog, which is written in Java.

I was able to complete a proof-of-concept application that demonstrates how Prolog statements can implement a rules engine.  The rules engine is launched from a normal Java application.

The Java program collects dynamic data and rules, combines them with the static Prolog statements for the core engine, and loads them into an instance of Prolog.  The Java program then invokes the Prolog engine to solve a designated goal.

The goal drives the Prolog engine to apply its rules to its internal data store.  The engine seeks to fulfill the goal by collecting result data into a compound nested-list data structure.

Upon completion of its analysis, the Prolog engine returns a solution information object to the Java application.  If the object indicates success, the Java logic processes a compound nested-list data structure included in the solution information.  This data structure contains the results of the Prolog rules execution.

While the Prolog engine is in control, it can also call back to the Java application using custom predicates written in a Java library class.  The application developer defines appropriate logic for these custom predicates.  This mechanism provides another way for data to be transferred between the Prolog engine and the surrounding Java application.

Here is a detailed tutorial on this demonstration application.  Included are links to the downloadable files to run or modify the application:

News Goggles Rules Engine Demo

Advertisements