Lab 1 - Introduction to the Java Expert System Shell (JESS)

This lab is worth 10 points.
Due: Friday January 11, 2008 at 5pm

The Java Expert System Shell (JESS) is an expert system shell written by Ernest J. Friedman-Hill at Sandia National Laboratories. This program is NOT open source, but is available for academic use with a license, which we have for using JESS on Helios. It uses a scripting language based off of CLIPS, which is an open source project. If you want an expert system shell to use on your home machine, download CLIPS. You may also SSH into Helios to use JESS on Helios.

JESS on Helios

You can access JESS on Helios by changing to the directory /ai/jess. If you cannot access that directory, contact me. You will have access to this directory for the duration of the class. The version of JESS installed on Helios is 6.1p8. To run JESS, type:
java jess.Main
You must be in the /ai/jess directory for this command to work. This will launch JESS's command line interface.

Brief JESS Tutorial

First, read the official Language Documentation for Jess v6.1. Pay particular attention to sections 2.1, 2.2, 2.3, 2.7.1 and 2.8. You may skip the other sections as they are more advanced topics.

In brief, JESS provides a functional language where all commands are a function in the following format:

(function_name variable_list)
The variable_list is optional. Each item in the variable list is seperated by a space. For example, to calculate 5 * 10, you would use the following function:
(* 5 10)
A full list of functions supported by JESS is provided at http://herzberg.ca.sandia.gov/jess/docs/61/function_index.html.

Facts in JESS can be simple ordered facts (Section 2.7.1) or more complex slotted facts (Section 2.7.2). We will focus on simple ordered facts for this class. Ordered facts are just a space seperated list of variables that you the programmer have assigned meaning to. For example, in the lecture we created the fact (priv host1 2) to encode the sentence "The attacker has root on Host1". Each fact is assigned an index number when you create it in JESS. This give JESS a unique way to reference each fact. The commands most useful for facts are as follows (refer to Section 2.7.1 for examples):

As soon as a fact is asserted, it is compared against the rules. If that fact causes a rule to be satisfied, the rule is added to the list of satisfied facts called the agenda. If the inference engine is running, it will then fire the rules on the agenda.

Rules are defined via the defrules command (Section 2.8). Rather than require a literal "if" and "then", the defrules command takes the following format:

(defrule rule-name "Comment on the Rule"
  (antecedent1)
  (antecedent2)
  ...
  (antecedentN)
  =>
  (consequence1)
  (consequence2)
  ...
  (consequenceN))
All of the antecedents are ANDed together by default. You can however have NOT and OR as part of a single antecedent. The antecedents contain a pattern that is matched against the fact base. The patterns can be literal or can have variables. Variables can be used in a Boolean expression to compare the variable to some value. The example given in lecture showed both forms. That example was:
(priv host1 2)                 A literal antecedent
(priv ?m ?p&:(= ?p 2))         An antecedent that uses variables and comparison
Section 2.8.1 shows more examples of how to create these patterns in the antecedent.

As said in lecture, the consequences can be any JESS function. The most useful consequences will of course alter the factbase so that other rules might end up being satisfied. I/O operations are another useful consequence.

Useful commands for interacting with rules are as follows:

Lab Assignment

Start up JESS and run the provided "Guess the Animal" game by typing the following JESS function:
(batch examples/animal.clp)
Play the game as often as you like. When you finish, try the following commands at the JESS prompt:
(facts)
(rules)
(matches MAIN::initialize-1)
Then give a (reset) command and try those commands again. Note how the output has changed.

Give the (clear) command to remove all of the Game facts and rules from the system. Now create the following simple rule from Section 2.6 of the book:

(defrule rule1 "Rule 1"
   (Y)
   (D)
   =>
   (printout t "Rule 1 fired" crlf)
   (assert (Z))
)
Now assert Y and D using the following:
(assert (Y))
(assert (D))
Notice that the rule did not fire. That's because we have not yet started the inference engine. Before starting the inference engine, check (agenda). As long as there were no typos, you should see rule1 listed in the agenda. Now give the (run) command. The rule will fire.

To exit JESS, give the (exit) command.

Lab Write-Up

Write at least one paragraph on what you saw while playing the "Guess the Animal" game and one paragraph on what you saw while creating the "Rule1" rules. Submit these paragraphs as your write-up for this lab. As a reminder from the syllabus, you may either submit a hard copy or send an email to my Helios account. If sending an email, use only plain text or PDF format.