Presentation is loading. Please wait.

Presentation is loading. Please wait.

JESS : Java Expert System Shell Mark Maslyn

Similar presentations


Presentation on theme: "JESS : Java Expert System Shell Mark Maslyn"— 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 Java App JESS Java Calls Jess Jess Calls Java

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 import jess.*;... Rete engine = new Rete( ); engine.executeCommand ( “(printout t \”Hello Word\” crlf)”); Java Calling JESS

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 name) (slot gender) (slot gender) (slot job_title)) (slot job_title))

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

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

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

15 Rule Conditions Can’t Call Functions YES (defrule equals (test (eq 1 1) ) => (printout t “1 and 1 are equal” crlf)) NO (defrule equals (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 Java Bean JESS fact (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 Name, Address DB Web Service Credit Score Customer in DB? Java App JESS Filtered Results Packages Promos Rules

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

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

36 PartnerPackagePriceDescription SBCFree-For-All49.95TV with no equipment to buy! SBCDigital Home Advantage Connect up to 2 TV's free! SprintAmerica's Top America's Top 60 Cable Channels! SprintDigital Home Advantage 59.95Connect up to 2 TV's free! SprintAmerica's Top America's Top 100 Cable Channels! QwestFree-For-All39.95TV with no equipment to buy! Example Packages by Partner

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

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) (prod-partner ?p) (package (partner ?p)(name ?n) (desc ?d) (price ?pr)) (package (partner ?p)(name ?n) (desc ?d) (price ?pr)) => => (assert (results ?p ?n ?d ?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) (credit-score ?c) ?f<-(results (partner ?p)(name ?n)(desc ?d) (price ?pr)) ?f<-(results (partner ?p)(name ?n)(desc ?d) (price ?pr)) (test (and ( ?pr 39.95))) (test (and ( ?pr 39.95))) => => (retract ?f)) (retract ?f))

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

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 Jess In Action (Book) My Website (click on the Jess link) herzberg.ca.sandia.gov/jess/index.shtml


Download ppt "JESS : Java Expert System Shell Mark Maslyn"

Similar presentations


Ads by Google