Скачать презентацию JESS Java Expert System Shell Mark Maslyn Скачать презентацию JESS Java Expert System Shell Mark Maslyn

d9061622a3abede937bb2a8995259b94.ppt

  • Количество слайдов: 42

JESS : Java Expert System Shell Mark Maslyn mmaslyn@msn. com JESS : Java Expert System Shell Mark Maslyn [email protected] com

Java Expert System Shell Java Application A “Rules-Engine” Developed by Ernest Friedman-Hill at Sandia 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

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

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

java jess. Main Jess, the Java Expert System Shell" src="https://present5.com/presentation/d9061622a3abede937bb2a8995259b94/image-5.jpg" alt=""Hello World" in JESS c: >java jess. Main Jess, the Java Expert System Shell" /> "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. 1 p 7 5/7/2004 Jess>(printout t "Hello World" crlf) Hello World Jess>

Jess Can Call Java Functions (bind ? frame (new JFrame “Pumps Demo”)) (call (? Jess Can Call Java Functions (bind ? frame (new JFrame “Pumps Demo”)) (call (? frame get. Content. Pane) set. Layout(new Grid. Layout 2 3))

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

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

Returning Values import jess. *; . . . Rete engine = new Rete( ); Returning Values import jess. *; . . . Rete engine = new Rete( ); Value result = engine. execute. Command ( “(+ 2 2 )”); System. out. println(result. int. Value(null));

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

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

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

Rule Syntax: if (LHS) then RHS defrule example_rule LHS => RHS if (left hand 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

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

Rule Conditions Can’t Call Functions NO (defrule equals (eq 1 1) => (printout t 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))

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

4 Golfers Logic Problem ● Four Golfers: Fred, Joe, Bob and Tom are in 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

Step 1: Define Templates (deftemplate pants-color (slot person) (slot color)) (deftemplate golfer-position (slot person) 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))

Step 2: Write JESS rules to generate combinations as “facts” (defrule generate-combos => (foreach 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$ 1 2 3 4) (assert (golfer-position (person ? name) (position ? pos))))))

Step 3: Run JESS to find solution. (defrule find-solution ; ; The golfer to Step 3: Run JESS to find solution. (defrule find-solution ; ; The golfer to Fred's right is wearing blue pants. (position (person Fred) (position ? p 1)) (pants-color (person Fred) (color ? c 1)). . . => (printout t Fred " " ? p 1 " " ? c 1 crlf) (printout t Joe " " ? p 2 " " ? c 2 crlf) (printout t Bob " " ? p 3 " " ? c 3 crlf) (printout t Tom " " ? p 4 " " ? c 4 crlf) )

Logic Problem Demo Logic Problem Demo

Search Tree Search Tree

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

Rule Engines Contain • Rule base • Working memory • Inference engine Rule Engines Contain • Rule base • Working memory • Inference engine

Asimov's 3 Laws of Robotics • 1) A robot may not injure a human 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.

3 Laws (Continued) • 3) A robot must protect its own existence as long 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.

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

Animals Expert System Demo Animals Expert System Demo

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

Shadow Facts Java Bean public class dimmer. Switch { private int brightness = 0; Shadow Facts Java Bean public class dimmer. Switch { private int brightness = 0; public int get. Brightness( ) { return brightness; } public void set. Brightness( int value ) { brightness = value; } }

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

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

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

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

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

Example Packages by Partner Package Price SBC 49. 95 Free-For-All Description TV with no Example Packages by Partner Package Price SBC 49. 95 Free-For-All Description TV with no equipment to buy! SBC Digital Home 29. 95 Connect up to 2 Advantage TV's free! Sprint America's Top 60 34. 95 America's Top 60 Cable Channels! Sprint Digital Home 59. 95 Connect up to 2 Advantage TV's free! Sprint America's Top 49. 95 America's Top 100 Cable Channels!

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

Retrieve Packages By Partner Rule (assert (package-partner Sprint)) ; ; example partner name … 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)))

Filter Packages By Credit Score Rule (assert (credit-score 620)) … (defrule filter-by-credit-score (credit-score ? 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))

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

JESS Pros and Cons Pros • Very Flexible System • Free for Government or 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

Jess Resources Jess Home Page herzberg. ca. sandia. gov/jess/index. shtml Jess In Action (Book) Jess Resources Jess Home Page herzberg. ca. sandia. gov/jess/index. shtml Jess In Action (Book) www. manning. com/friedman-hill My Website www. sawatchsoftware. com (click on the Jess link)