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.
/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.MainYou must be in the
/ai/jess
directory for this command to work.
This will launch JESS's command line interface.
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):
(assert (fact_representation))
- Create a fact
(retract fact_number)
- Remove a fact
(facts)
- List all current facts
(reset)
- Remove all facts and assert the special fact
"initial-fact"
(clear)
- Remove all facts and rules. Do not assert the
special fact "initial-fact"
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 comparisonSection 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:
(rules)
- List the names of all the defined rules
(agenda)
- Lists the currently satisfied rules that have yet
to finish firing
(batch filename)
- Loads the specified file. The file may
contain rules, facts, functions and so on. Several example files are
provided in /ai/jess/examples
(run)
- Starts the inference engine. This will cause the
agenda to be processed
(matches rule_name)
- Print out state information about
the specified rule (if it has any state)
(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.