Presentation is loading. Please wait.

Presentation is loading. Please wait.

JESS : Java Expert System Shell

Similar presentations


Presentation on theme: "JESS : Java Expert System Shell"— Presentation transcript:

1 JESS : Java Expert System Shell
Mark Maslyn

2 Java Expert System Shell
Java Application A “Rules-Engine” Developed by Ernest Friedman-Hill at Sandia National Laboratory Processes “Jess” Scripting Language Can by called by Java Programs or act as a Java Command Interpreter

3 Java and JESS Jess Calls Java JESS Java Calls Jess Java App

4 JESS Uses Templates (data structure definitions)
Facts (templates with data values) Rules (logic and program flow) Commands (to the JESS shell) Java Beans

5 "Hello World" in JESS c:\>java jess.Main
Jess, the Java Expert System Shell Copyright (C) 2001 E.J. Friedman Hill and the Sandia Corporation Jess Version 6.1p7 5/7/2004 Jess>(printout t "Hello World" crlf) Hello World Jess>

6 Jess Can Call Java Functions
(bind ?frame (new JFrame “Pumps Demo”)) (call (?frame getContentPane) setLayout(new GridLayout 2 3))

7 Java Calling JESS import jess.*; ... Rete engine = new Rete( );
engine.executeCommand ( “(printout t \”Hello Word\” crlf)”);

8 Jess Value Types RU.FLOAT RU.INTEGER RU.LONG RU.LIST RU.STRING
float, double long, short, int, byte, char Same A Java array String, char, Character Wrapper classes

9 Returning Values import jess.*; ... Rete engine = new Rete( );
Value result = engine.executeCommand ( “(+ 2 2 )”); System.out.println(result.intValue(null));

10 Steps to Solve A Problem With Jess
Define Templates and Facts Write Rules Run Jess

11 Templates (Data Structures)
(deftemplate employee “employees in the database” (slot name) (slot gender) (slot job_title))

12 Facts (Structures with Values
(employee (name John Smith) (gender male) (job_title programmer))

13 defrule example_rule LHS => RHS
Rule Syntax: if (LHS) then RHS defrule example_rule LHS => RHS if (left hand side) conditions are true then clauses on the right hand side are executed

14 Example Rule “if” (LHS) rule name “then” (RHS)
(defrule change-baby-if-wet ?wet <- (baby-is-wet) => (change-baby) (retract ?wet)) “then” (RHS)

15 Rule Conditions Can’t Call Functions
NO (defrule equals (eq 1 1) => (printout t “1 and 1 are equal” crlf)) YES (defrule equals (test (eq 1 1) ) => (printout t “1 and 1 are equal” crlf))

16 Search Space Problems Jess Can Solve Constraint or Search Space Problems (e.g. Logic, Scheduling)

17 4 Golfers Logic Problem Four Golfers: Fred, Joe, Bob and Tom are in line at the tee Golfer to Fred's right is wearing blue pants Joe is second in line Bob is wearing plaid pants Tom isn't in position 1 or 4 Tom is wearing orange pants

18 Step 1: Define Templates
(deftemplate pants-color (slot person) (slot color)) (deftemplate golfer-position (slot person) (slot position)) (pants-color (person Bob) (color red)) (golfer-position (person Bob) (position 2))

19 Step 2: Write JESS rules to generate combinations as “facts”
(defrule generate-combos => (foreach ?name (create$ Fred Joe Bob Tom) (foreach ?color (create$ red blue plaid orange) (assert (pants-color (person ?name) (color ?color)))) (foreach ?golfer-position (create$ ) (assert (golfer-position (person ?name) (position ?pos))))))

20 Step 3: Run JESS to find solution.
(defrule find-solution ;; The golfer to Fred's right is wearing blue pants. (position (person Fred) (position ?p1)) (pants-color (person Fred) (color ?c1)) ... => (printout t Fred " " ?p1 " " ?c1 crlf) (printout t Joe " " ?p2 " " ?c2 crlf) (printout t Bob " " ?p3 " " ?c3 crlf) (printout t Tom " " ?p4 " " ?c4 crlf) )

21 Logic Problem Demo

22 Search Tree

23 Rules Engine Jess Can Act As a “Rules Engine” For Expert System Type Problems (e.g. Diagnosis, Configuration, Personalization)

24 Rule Engines Contain Rule base Working memory Inference engine

25 Asimov's 3 Laws of Robotics
1) A robot may not injure a human being or, through inaction allow a human being to come to harm. 2) A robot must obey orders given it by human beings except where such orders would conflict with the First Law.

26 3 Laws (Continued) 3) A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.

27 Robots Existence Rule (defrule third_law (first_law_obeyed)
(second_law_obeyed) => protect_robots_existence)

28 Animals Expert System Demo

29 “Shadow” Facts and Java Beans
JESS fact Java Bean (employee (name “John Smith”) (gender Male) (job_title programmer))

30 Shadow Facts Java Bean public class dimmerSwitch {
private int brightness = 0; public int getBrightness( ) { return brightness; } public void setBrightness( int value ) { brightness = value; } }

31 Adding the Java Bean to Jess...
Step 1: Generate a Jess template with defclass (defclass dimmer dimmerSwitch) Step 2: Create and bind an instance of this class in Jess (bind ?ds (new dimmerSwitch)) (definstance dimmer ?ds)

32 Calling the Java Bean... Step 3: Call the Java Bean methods
(call ?ds setBrightness 10 ))

33 Customization and Filtering
Customer in DB? Customer Name, Address Java App DB Packages Credit Score Promos JESS Web Service Rules Filtered Results

34 Lookup Customer and Credit Score
Customer in DB? Customer Name, Address Java App DB Packages Credit Score JESS Promos Web Service Rules Filtered Results

35 Load Packages, Promotions and Rules
Customer in DB? Customer Name, Address Java App DB Packages Credit Score Promos JESS Web Service Rules Filtered Results

36 Example Packages by Partner
Price Description SBC Free-For-All 49.95 TV with no equipment to buy! Digital Home Advantage 29.95  Connect up to 2 TV's free! Sprint America's Top 60 34.95 America's Top 60 Cable Channels! 59.95 America's Top 100 America's Top 100 Cable Channels! Qwest 39.95

37 Packages and Promotions Templates
deftemplate package (slot partner) (slot name) (slot desc) (slot price)) deftemplate promotion (slot partner) (slot name) (slot desc) (slot amount))

38 Retrieve Packages By Partner Rule
(assert (package-partner Sprint)) ;; example partner name ;; find all packages with Sprint as the partner (defrule get-packages (prod-partner ?p) (package (partner ?p)(name ?n) (desc ?d) (price ?pr)) => (assert (results ?p ?n ?d ?pr)))

39 Filter Packages By Credit Score Rule
(assert (credit-score 620)) (defrule filter-by-credit-score (credit-score ?c) ?f<-(results (partner ?p)(name ?n)(desc ?d) (price ?pr)) (test (and (< ?c 650)(> ?pr 39.95))) => (retract ?f))

40 Use Rules to Filter Packages and Promotions
Customer in DB? Customer Name, Address Java App DB Packages Credit Score JESS Promos Web Service Rules Filtered Results

41 JESS Pros and Cons Pros Very Flexible System
Free for Government or Academic Use Source Code Available Very Fast Rete Algorithm Planned Integration with Eclipse Cons Lisp – like syntax Limited GUI interface – New Interface in 7.0

42 Jess Resources Jess Home Page herzberg.ca.sandia.gov/jess/index.shtml
Jess In Action (Book) My Website (click on the Jess link)


Download ppt "JESS : Java Expert System Shell"

Similar presentations


Ads by Google