Mostly adopted from Jason Morris notes
(Morris Technical Solutions)
Developed at Sandia National Laboratories in
late 1990s.
Created by Dr. Ernest J. Friedman-Hill.
Inspired by the AI production rule language
Fully developed Java API for creating rulebased expert systems.
Rule Base (knowledge base)
Working Memory (fact base)
Inference Engine (rule engine)
Pattern Matcher – decides what rules to fire
and when.
Agenda – schedules the order in which
activated rules will fire.
Execution Engine – responsible for firing rules
and executing other code.
Match the facts against the rules.
Choose which rules to fire.
Execute the actions associated with the
Jess matches facts in the fact base to rules
in the rule base.
The rules contain function calls that
manipulate the fact base and/or other Java
Jess uses the Rete algorithm to match
Rete network = an interconnected collection
of nodes = working memory.
Architecturally inspired by CLIPS
LISP-like syntax.
Basic data structure is the list.
Can be used to script Java API.
Can be used to access JavaBeans.
Easy to learn and use.
Your very first Jess
(printout t “Hello Class!” crlf)
Here are some valid lists in Jess:
(a b c)
(1 2 3)
(+ 2 3)
(foo ?x
; list of tokens
; list of integers
; an expression
world!”) ; a string
?y) ; a function call
Named containers that hold a single value
Begin with a ? mark
Can change types during lifetime
Assigned using bind function
Everything is a list in Jess!
EXAMPLE: Adding two numbers
(bind ?x 2) ; assign x = 2
(bind ?y 3) ; assign y = 3
(bind ?result (+ ?x ?y)) ; find
Even functions are lists.
(deffunction get-input()
“Get user input from
(bind ?s (read))
(return ?s))
(deffunction area-sphere
“Calculate the area of a
(bind ?area (* (* (pi) 2)(*
?radius ?radius)))
(return ?area))
How do we use this in Jess?
(printout t "The surface
area of a radius = 2 meter
sphere is " +
(area-sphere 2) + " m^2")
Facts have a head and one or more slots.
Slots hold data (can be typed).
Multislots can hold lists.
You can modify slot values at runtime.
Facts are constructed from templates.
Ordered – head only.
Ordered – single slot.
Unordered – multiple slot, like a database
Shadow – slots correspond to properties of
a JavaBean.
Used to define the structure of a fact.
pattern “A design pattern.”
(slot name)
(slot type (default “creation”))
(slot intent)
(slot solution))
Facts store the initial conditions.
;; Asserting a new “pattern” fact.
(printout t “Enter pattern name:”
(bind ?x getInput)
(assert (pattern (name ?x)))
;; An ordered fact with no
slots – a placeholder that
indicates state.
;; A ordered fact of one slot
(assert(weightfactor 0.75))
Shadow facts are unordered facts
whose slots correspond to the
properties of a JavaBean.
defclass – creates a deftemplate from a
definstance – adds bean to working
are the knowledge-base of the system.
fire only once on a given set of facts.
use pattern constraints to match facts.
are much faster than IF-THEN statements.
Rules have a “left-hand” side (LHS) and a
“right-hand” side (RHS).
The LHS contains facts fitting certain
The RHS contains function calls.
Checking working memory state.
;; A not very useful error handler
(defrule report-error
(printout t “There is an error”
Using pattern bindings in rules.
;; A more useful error handler
(defrule report-err
?err <- (is-error (msg ?msg))
(printout t "Error was: " ?msg crlf)
(retract ?err))
You can interactively access all Java APIs
from Jess.
This makes exploring Java somewhat
easier and immediate.
(import javax.swing.*)
(import java.awt.*)
(import java.awt.event.*)
(set-reset-globals FALSE)
(defglobal ?*frame* = (new JFrame "Hello You"))
(defglobal ?*button* = (new JButton "Click it"))
(?*frame* setSize 500 300)
((?*frame* getContentPane) add ?*button*)
(?*frame* setVisible TRUE)
Organized into 3 packages, 64
classes (not hard to learn)
jess - inference engine “guts”.
jess.awt – GUI wrappers.
jess.factory - Allows extensions that “get
into the guts of Jess”.
The reasoning engine and the central class in
the Jess library.
Executes the built Rete network, and
coordinates many other activities.
Rete is essentially a facade for the Jess API.
try {
Rete engine = new Rete();
engine.executeCommand(“printout t “Hello CS437”);;
catch (JessException je ){}
It is simple. All you really need to do is to
make an instance of Rete and call one or
more Rete methods.
Download Jess at:
 Join the Jess user community at:
 See Dr. Friedman-Hill’s Jess in Action at:
 CLIPS Expert System Shell
 FuzzyJ Website

similar documents