Knowledgebase Objects

The execution of Prolog goals is based on defined predicates and built-in predicates. These predicates are found inside a knowledge base. The Prolog interpreter initializes a knowledge base with system defined predicates and system built-in predicates. The Prolog API allows the application programmer to define custom built-ins in the form of Java foreign predicates.

Since we do not yet have a module system the organization of predicates is relatively simple. Each interpreter can maximally have one knowledge base associated. For each predicate specification there is a separate entry in the knowledge base, independent whether it is a defined predicate or built-in predicate. Defined predicates have a list of clauses associated. System built-ins have some protected data associated. Custom built-ins in the form of a Java foreign predicates refer exactly to one Java method.


Picture 6: Example Knowledgebase

The clauses of defined predicates can be either asserted dynamically or statically consulted from a file. Dynamic predicates can be abolished dynamically whereas static predicates are only abolished in the initialization phase of a re-consult. Java foreign predicates can be registered dynamically or via a directive in a file. In both cases they can be abolished dynamically and they will be also abolished in the initialization phase of a re-consult.

There is a contract between a predicate and the interpreter. This contract regulates what the interpreter has to expect form a predicate and vice versa. A first element of the contract is the handling of exception. Each defined predicate and built-in predicate is expected to either throw an interpreter message or an interpreter exception. Interpreter messages do not consists of a Prolog stack trace. When the interpreter receives an interpreter message it will turn it into an interpreter exception by adding a Prolog stack trace. Interpreter exceptions are directly passed down.

The contract also regulates the behaviour of deterministic and non-deterministic predicates. A deterministic predicate does either succeed or fail without leaving a choice point. Non-deterministic predicates on succeeding for the first time might create a new choice point. When there is a choice point the predicate is retried upon backtracking. The predicate might then succeed again by adapting the choice point or it might even succeed with dropping the choice point. Whenever a predicate succeeds without a choice point, the interpreter can apply tail recursion optimization.


Picture 7: Example Class Path

Besides collecting a number of predicates a knowledge base servers further functions to the interpreter. It also holds the class loader which is responsible for the resolution of Prolog source file names and Java class names. The class loader is equipped with a class path. The class path can contain either directories or archives. Relative source paths are resolved by looking them up in the directories and archives, and returning the first found location. Java class names are resolved by first converting the full class name into a relative source path, and then looking up this relative source path.

The development environment allows enhancing the class path via its settings dialog. As a result the developer can easily work with Java foreign predicates. The developer has only to add the directory or archives that contain the Java classes of the Java methods he wants to use. In case of the runtime library there are multiple scenarios. For standalone applications the class path can be specified on the command line. For applets the class path can be specified inside the applet tag. For servlets the class path corresponds to the WEB-INF/lib directory. The later should also work when the runtime library is shared among different web contexts. The directories and archives can also deliver Prolog sources.

Finally the knowledge base gives a context for internationalization. This is explored for both the runtime library and the development environment. But we do not provide an exposure of an application programming interface to access this facility at the current stage. But it is in-ternally used by the runtime library and the development environment for the display of user friendly error messages. The facility allows the mapping of Prolog terms to text templates found in Java property files. And then apply the text templates to some arguments of the Prolog terms. The facility is further use to internationalize the dialogs and menus of the de-velopment environment.

Kommentare