Top Banner
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
31

Preliminary Introduction to JESS

Jan 19, 2016

Download

Documents

Talisa

Preliminary Introduction to JESS. Mostly adopted from Jason Morris notes (Morris Technical Solutions). The Java Expert System Shell. Developed at Sandia National Laboratories in late 1990s. Created by Dr. Ernest J. Friedman-Hill. Inspired by the AI production rule language CLIPS . - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Preliminary Introduction to JESS

Mostly adopted from Jason Morris notes (Morris Technical Solutions)

Page 2: Preliminary Introduction to JESS

Developed at Sandia National Laboratories in late 1990s.

Created by Dr. Ernest J. Friedman-Hill. Inspired by the AI production rule language

CLIPS. Fully developed Java API for creating rule-

based expert systems.

Page 3: Preliminary Introduction to JESS

Rule Base (knowledge base) Working Memory (fact base) Inference Engine (rule engine)

Page 4: Preliminary Introduction to JESS

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.

Page 5: Preliminary Introduction to JESS

Match the facts against the rules. Choose which rules to fire. Execute the actions associated with the

rules.

Page 6: Preliminary Introduction to JESS

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 code.

Jess uses the Rete algorithm to match patterns.

Rete network = an interconnected collection of nodes = working memory.

Page 7: Preliminary Introduction to JESS

WORKINGMEMORY

RULE BASE

EXECUTIONENGINE

INFERENCEENGINE

PATTERNMATCHER

AGENDA

Page 8: Preliminary Introduction to JESS

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.

Page 9: Preliminary Introduction to JESS

(printout t “Hello Class!” crlf)(printout t “Hello Class!” crlf)

Your very first Jess program!

Page 10: Preliminary Introduction to JESS

(a b c) ; list of tokens (1 2 3) ; list of integers (+ 2 3) ; an expression (“Hello world!”) ; a string (foo ?x ?y) ; a function call

Here are some valid lists in Jess:

Page 11: Preliminary Introduction to JESS

Named containers that hold a single value

Untyped Begin with a ? mark Can change types during lifetime Assigned using bind function

Page 12: Preliminary Introduction to JESS

EXAMPLE: Adding two numbers

(bind ?x 2) ; assign x = 2(bind ?y 3) ; assign y = 3(bind ?result (+ ?x ?y)) ; find sum

Everything is a list in Jess!

Page 13: Preliminary Introduction to JESS

(deffunction get-input()“Get user input from console.”(bind ?s (read))(return ?s))

Even functions are lists.

Page 14: Preliminary Introduction to JESS

(deffunction area-sphere (?radius)

“Calculate the area of a sphere”

(bind ?area (* (* (pi) 2)(* ?radius ?radius)))

(return ?area))

Page 15: Preliminary Introduction to JESS

(printout t "The surface area of a radius = 2 meter sphere is " +

(area-sphere 2) + " m^2")

How do we use this in Jess?

Page 16: Preliminary Introduction to JESS

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.

Page 17: Preliminary Introduction to JESS

Ordered – head only. Ordered – single slot. Unordered – multiple slot, like a

database record. Shadow – slots correspond to properties

of a JavaBean.

Page 18: Preliminary Introduction to JESS

Used to define the structure of a fact.

(deftemplate pattern “A design pattern.”(slot name)(slot type (default “creation”))(slot intent)(slot solution))

Page 19: Preliminary Introduction to JESS

;; Asserting a new “pattern” fact.(printout t “Enter pattern name:” crlf)

(bind ?x getInput)(assert (pattern (name ?x)))

Facts store the initial conditions.

Page 20: Preliminary Introduction to JESS

;; An ordered fact with no slots – a placeholder that indicates state.

(assert(answer-is-valid))

;; A ordered fact of one slot(assert(weightfactor 0.75))

Page 21: Preliminary Introduction to JESS

defclass – creates a deftemplate from a bean.

definstance – adds bean to working memory.

Shadow facts are unordered facts whose slots correspond to the properties of a JavaBean.

Page 22: Preliminary Introduction to JESS

… 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.

Page 23: Preliminary Introduction to JESS

Rules have a “left-hand” side (LHS) and a “right-hand” side (RHS).

The LHS contains facts fitting certain patterns.

The RHS contains function calls.

Page 24: Preliminary Introduction to JESS

;; A not very useful error handler(defrule report-error

(error-is-present)=>(printout t “There is an error” crlf))

Checking working memory state.

Page 25: Preliminary Introduction to JESS

;; A more useful error handler(defrule report-err?err <- (is-error (msg ?msg))=>(printout t "Error was: " ?msg crlf)(retract ?err))

Using pattern bindings in rules.

Page 26: Preliminary Introduction to JESS

You can interactively access all Java APIs from Jess.

This makes exploring Java somewhat easier and immediate.

Page 27: Preliminary Introduction to JESS

(import javax.swing.*)

(import java.awt.*)

(import java.awt.event.*)

(set-reset-globals FALSE)

(defglobal ?*frame* = (new JFrame "Hello PJUG"))

(defglobal ?*button* = (new JButton "Click my PJUG"))

(?*frame* setSize 500 300)

((?*frame* getContentPane) add ?*button*)

(?*frame* setVisible TRUE)

Page 28: Preliminary Introduction to JESS

jess - inference engine “guts”. jess.awt – GUI wrappers. jess.factory - Allows extensions that

“get into the guts of Jess”.

Organized into 3 packages, 64 classes (not hard to learn)

Page 29: Preliminary Introduction to 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.

Page 30: Preliminary Introduction to JESS

It is simple. All you really need to do is to make an instance of Rete and call one or more Rete methods.

try {

Rete engine = new Rete();

engine.executeCommand(“printout t “Hello CS437”);

engine.run();

}

catch (JessException je {}

Page 31: Preliminary Introduction to JESS

Download Jess at: http://herzberg.ca.sandia.gov/jess/index.shtml Join the Jess user community at:http://herzberg.ca.sandia.gov/jess/mailing_list.shtml See Dr. Friedman-Hill’s Jess in Action at:http://www.manning.com/friedman-hill/ CLIPS Expert System Shellhttp://www.ghg.net/clips/CLIPS.html FuzzyJ Websitehttp://www.iit.nrc.ca/IR_public/fuzzy/fuzzyJToolkit2.html