Acquire® Demonstrations: About the Java Whale Watcher
Overview
The Java Whale Watcher is a demonstration of the Acquire® expert system. At Acquired Intelligence Inc, we have a small knowledge base which can be used to determine the species of an observed whale. Details of the observation (such as the whale's size) are used by the knowledge base to reach a conclusion. This knowledge base was not designed to be an exhaustive whale identifier but it can be used to identify many species of whales, particularly those found in Canadian coastal waters.The Java Whale Watcher is quite similar to the CGI-based Whale Watcher it even uses the same knowledge base. The obvious difference between the two Whale Watchers is the method of displaying information to the user. The CGI version uses HTML web pages to present information, and the Java version displays all information in the Applet's window. Although the methods of displaying information are somewhat similar, the inner workings of the Java version of the Whale Watcher are vastly different from its CGI-based counterpart.
The Java Whale Watcher uses two components from the Acquire®SDK: The Acquire® Server and the Acquire® Java API. These components each provide an end-point of a network connection, enabling the Applet to access the inference engine.
The Acquire® Server
The Acquire® Server allows remote clients to connect to an inference engine. The Server listens on a TCP/IP socket and responds to commands that it receives from the client. The Server is capable of simultaneously serving multiple knowledge bases to multiple clients.
Due to security constraints of the Java SecurityManager, Applets are not allowed to open network connections to arbitrary hosts. The only host to which an Applet can create a socket is the one from which it was served. This means for example if an Applet comes from a web server on www.host.com, the Acquire® Server must also be running on
www.host.com.
The Acquire® Java API
The Acquire® Java API is an interface between a Java Applet (or Java Application) and an Acquire® Server. The API provides anAcquire object, which is simply a wrapper around a socket. This object has a wide range of methods which allow you to both interact with the
Server's inference engine, and to set and query the states of the knowledge bases it provides.
With the Acquire® Java API and Acquire® Server, it is easy to add the flexibility and power of an expert system to your Java Applets. The Whale Watcher Applet demonstrates just how simple this is.
How the Whale Watcher Applet Works
The Java Whale Watcher operates in much the same manner as the CGI-based Whale Watcher, except that it maintains a persistent network connection to the Acquire® Server. As with its CGI counterpart, the Java Whale Watcher begins by asking the user about the details of the observed whale. When enough information regarding the whale is present in the inference engine, a conclusion regarding the whale's species is given to the user.To perform these tasks, the Applet does the following:
- 1. Connect to the Acquire® Server
- The connection to the Server is made by instantiating an
Acquireobject with the desiredhostnameandportparameters. By creating this object, a TCP/IP connection is made between the Applet and the Server. - 2. Open and run the knowledge base
- 3. Display question text to the user
- When the inference engine is run, it will require input from the user. The question text and possible answers
are retrieved from the Server, and are displayed in the Applet window. At this point, the Applet waits for the
user to respond to the question.
- 4. Retrieve the user's response to the question
- When the user responds to the question in the Applet window, the Applet will set the response to the question in
the inference engine. At this point, the engine will either ask another question (at which time step 3 will be
repeated), or a conclusion will be reached (and step 5 will be executed).
- 5. Display the inference engine's conclusion
- When the inference engine reaches a conclusion, the HTML text is displayed in the Applet window.
The Applet's "Back" Button
The Whale Watcher Applet contains a "Back" button, so that the user can move back up the chain of questions which were asked by the inference engine. In order to support this behaviour, the Applet stores the engine state by keeping track of the user's previous responses. When the "Back" button is clicked, the inference engine is stopped and then cleared. The previous responses are loaded into the engine, and then it is run again.Performance and Portability Notes
The Java Whale Watcher provides better performance than its CGI counterpart, as it uses a persistent connection to the inference engine. The result is that you do not need to load the knowledge base, set its state, and run the engine every time the user answers a question. This is a great improvement over the CGI version of the Whale Watcher.However, the benefits of the Java approach are not without their own drawbacks. The Applet uses the Java Virtual Machine (JVM), which is contained in the browser. As each browser has its own implementation of the JVM, the programmer must deal with the inconsistencies and bugs which are unique to each JVM. Additionally, the version of Java which is available in most browsers does not support HTML, so a HTML-capable class had to be written for the Whale Watcher. The Java Whale Watcher was written using the 1.1 version of the Java Developer's Kit, and therefore only works with Netscape Navigator versions 4 and above, and Microsoft Explorer version 4 and above.
As you can see, the efficiency gains of using Java are offset by portability problems. In some environments, such as handheld computers, the available web browsers do not support Java, and the portability benefits of using a CGI program make it necessary to overlook the problem of efficiency.
Although the Java Foundation Classes and implementations of the JVMs are improving, widespread use of stable and up-to-date JVMs will not be found in the near future. However, Java is a powerful language, and the Whale Watcher Applet demonstrates that these limitations can be overcome with a little effort.
If you need to put your expert system application on the World Wide Web, contact us for help in finding the best solution for your particular situation.
|
Copyright © 1996-2008 Acquired Intelligence Inc.
All rights reserved. |
Acquire® is a registered trademark of Acquired Intelligence Inc.
Contact Webmaster |