Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions.

Slides:



Advertisements
Similar presentations
Programming Paradigms and languages
Advertisements

CS 484 – Artificial Intelligence1 Announcements Choose Research Topic by today Project 1 is due Thursday, October 11 Midterm is Thursday, October 18 Book.
The CLIPS Programming Tool History of CLIPS –Influenced by OPS5 and ART –Implemented in C for efficiency and portability –Developed by NASA, distributed.
Expert System Shells - Examples
Samad Paydar Ferdowsi University of Mashhad.  C Language Integrated Production System (CLIPS)  A tool for building expert systems  An expert system.
1 01/12/2011Knowledge-Based Systems, Paula Matuszek Intro to CLIPS Paula Matuszek CSC 9010, Spring, 2011.
Reasoning System.  Reasoning with rules  Forward chaining  Backward chaining  Rule examples  Fuzzy rule systems  Planning.
JESS : Java Expert System Shell
Chapter 7: Introduction to CLIPS
Artificial Intelligence Lecture No. 18 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Knowledge Engineering.  Process of acquiring knowledge from experts and building knowledge base  Narrow perspective  Knowledge acquisition, representation,
Rule Based Systems Michael J. Watts
Chapter 12: Expert Systems Design Examples
Introduction to CLIPS (Chapter 7) Fact List (contains data) Knowledge Base (contains rules) Inference Engine (controls execution)
Artificial Intelligence CAP492
1 Chapter 9 Rules and Expert Systems. 2 Chapter 9 Contents (1) l Rules for Knowledge Representation l Rule Based Production Systems l Forward Chaining.
Rules and Expert Systems
© C. Kemke1Reasoning - Introduction COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
© C. Kemke Control 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Marakas: Decision Support Systems, 2nd Edition © 2003, Prentice-Hall Chapter Chapter 7: Expert Systems and Artificial Intelligence Decision Support.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
EXPERT SYSTEMS Part I.
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
CS 561, Session 25 1 Introduction to CLIPS Overview of CLIPS Facts Rules Rule firing Control techniques Example.
C++ fundamentals.
Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions.
Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Expert Systems Infsy 540 Dr. Ocker. Expert Systems n computer systems which try to mimic human expertise n produce a decision that does not require judgment.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
Artificial Intelligence Lecture No. 15 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
Review Topics Test 1. Background Topics Definitions of Artificial Intelligence & Turing Test Physical symbol system hypothesis vs connectionist approaches.
Chapter 14: Artificial Intelligence Invitation to Computer Science, C++ Version, Third Edition.
1 Programming a Knowledge Based Application. 2 Overview.
Introduction to Python
13: Inference Techniques
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
Sudoku Hands-on Training Masters Project Presentation Yiqi Gao March 19, 2014.
Production Systems A production system is –a set of rules (if-then or condition-action statements) –working memory the current state of the problem solving,
CMPD 434 MULTIMEDIA AUTHORING Chapter 06 Multimedia Authoring Process IV.
Programming Lifecycle
Expert Systems An Introduction to Expert Systems and CLIPS by Charles Weddle.
Jess: A Rule-Based Programming Environment Reporter: Yu Lun Kuo Date: April 10, 2006 Expert System.
Java Expert System Shell JESS 報告者 : 江梓安. Why we need an expert systems? Conventional programming languages Conventional programming languages Complex.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
CS62S: Expert Systems Based on: The Engineering of Knowledge-based Systems: Theory and Practice, A. J. Gonzalez and D. D. Dankel.
1 Knowledge Based Systems (CM0377) Lecture 10 (Last modified 19th March 2001)
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Artificial Intelligence Lecture No. 19 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Chapter 9. Rules and Expert Systems Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
AD Lab Andrews-Dalkilic Data Exploration. AD Lab Outline Architecture What is Bioinformatics? Explore some bioinformatics problems and tools Talk about.
Expert System Seyed Hashem Davarpanah University of Science and Culture.
Artificial Intelligence Knowledge Representation.
The CLIPS Expert System Shell Dr Nicholas Gibbins
Summary for final exam Agent System..
Intelligent Systems JESS constructs.
Intro to Jess The Java Expert System Shell
Chapter 9. Rules and Expert Systems
Chapter 7: Introduction to CLIPS
Knowledge Representation
Intro to Jess The Java Expert System Shell
Computer Programming.
Artificial Intelligence
JESS (Java Expert System Shall)
Jess Knowledge, Influence, Behavior
Intro to Jess The Java Expert System Shell
Chapter 9. Rules and Expert Systems
Presentation transcript:

Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions

Quotable Quotes Each problem that I solved became a rule which served afterwards to solve other problems. - Rene Descartes

Quotable Quotes As a rule we disbelieve all the facts and theories for which we have no use. - William James

Agenda What are expert systems? What are rule-based expert systems? Introduction to Jess The Jess Language 5 minute break

Agenda Scripting & The Jess API Demo 1 : Design Pattern Expert Demo 2 : Catalog Servlet References and Further Study Q & A

Expert Systems… Are a branch of artificial intelligence. Simulate human reasoning in some domain. “Reason” by heuristic or approximate methods. Explain and justify solutions in user-friendly terms.

Types Of Expert Systems Neural Networks Blackboard Systems Belief (Bayesian) Networks Case-Based Reasoning Rule-Based Systems

Rule-Based Expert Systems Originated from AI research in the 70s and 80s. Problem data stored as facts. “Reason” using IF…THEN…ELSE rules. Can “reason” deductively (forward- chaining) or inductively (backward-chaining).

When to Use Rule-Based Systems Problem Domain = narrow, well- understood domain theory Knowledge Representation = facts and rules Output = recommendation Explanation = rule firing trace Learning Ability = generally no (but…)

Inference Process 1.Rules and facts compared using pattern matcher. 2.Matched rules activated into a conflict set. 3.Conflict set resolved into agenda (process called conflict resolution). 4.Rule engine fires on agenda. 5.Engine cycles until all rules are satisfied.

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. Fully developed Java API for creating rule-based expert systems.

Rule-Based Expert System Architecture Rule Base (knowledge base) Working Memory (fact base) Inference Engine (rule engine)

Inference (Rule) Engines 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.

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

How Does Jess Work? 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 (ree-tee) algorithm to match patterns. Rete network = an interconnected collection of nodes = working memory.

Jess Architecture Diagram WORKING MEMORY RULE BASE EXECUTION ENGINE INFERENCE ENGINE PATTERN MATCHER AGENDA

Procedural Programming Traditional programming (BASIC, C, FORTRAN, Pascal, etc.). Largely based on functions. Programmer controls logic. Sequential and deterministic. Object-oriented programming is procedural within object methods.

Declarative Programming New programming paradigm - rules. Programmer does not really control code logic. Rule engine finds most efficient “path” of code execution. Replaces hard to maintain nested IF…THEN…ELSE coding.

Wait a minute! Well…yes and no…but don’t worry, Calvin! What? I…I can’t control my code??

Thought Experiment… Imagine writing a procedural/OOP algorithm to solve a jigsaw puzzle pieces, different shapes and colors. Polymorphism runs amok! Yet we manage to solve the puzzle…

Intuition and Rules Dump the puzzle pieces on a card table in no particular order. Your brain instinctively begins to apply rules to solve the puzzle! What might this look like in code?

Intuitive Inferencing (corner_found (piece_is_corner) => (assert corner-found) (save_piece)) (corner_found (piece_is_corner) => (assert corner-found) (save_piece)) (edge_found (piece_is_edge) => (assert edge-found) (save_piece)) (edge_found (piece_is_edge) => (assert edge-found) (save_piece)) Your brain “knows” what to do with a corner piece … … and an edge piece.

What’s Going On… Your brain recalls rules or heuristics to solve the problem. Your brain pattern-matches, prioritizes, and applies rules according to the facts in memory. A particular solution algorithm emerges as rules “fire” on facts.

The Jess Language 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.

Obligatory Tradition (printout t “Hello PJUG-ers!” crlf) Your very first Jess program!

Lists in 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:

Jess Variables Named containers that hold a single value. Untyped. Begin with a ? mark. Can change types during lifetime. Assigned using bind function.

Jess Variables and Lists 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!

Control Flow foreach if/then/else while apply build eval progn CommonJess-specific

Jess Functions (deffunction get-input() “Get user input from console.” (bind ?s (read)) (return ?s)) Even functions are lists.

Jess Function Example (deffunction area-sphere (?radius) “Calculate the area of a sphere” (bind ?area (* (* (pi) 2)(* ?radius ?radius))) (return ?area))

Jess Function Example (printout t "The surface area of a radius = 2 meter sphere is " + (area-sphere 2) + " m^2") How do we use this in Jess?

Working With Facts 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.

Jess Fact Types Ordered – head only. Ordered – single slot. Unordered – multiple slot, like a database record. Shadow – slots correspond to properties of a JavaBean.

Deftemplate Used to define the structure of a fact. (deftemplate pattern “A design pattern.” (slot name) (slot type (default “creation”)) (slot intent) (slot solution))

Asserting Facts ;; Asserting a new “pattern” fact. (printout t “Enter pattern name:” crlf) (bind ?x getInput) (assert pattern (name ?x)) Facts store the initial conditions.

All Kinds of Facts ;; 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))

Shadow Facts 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.

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

Rule Syntax 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.

Simple Rule Example ;; A not very useful error handler (defrule report-error (error-is-present) => (printout t “There is an error” crlf)) Checking working memory state.

A More Complex Rule ;; 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.

More Pattern and Control Tools Literal / variable constraints Logical conditional tests Predicate functions Salience Modules Defquery Backward- chaining matchingcontrol and structure

Break Time! Let’s take a quick 5 minute pause…

Scripting Java from Jess You can interactively access all Java APIs from Jess. This makes exploring Java somewhat easier and immediate. No code, compile, debug cycle.

Scripting Java with 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 ) ((?*frame* getContentPane) add ?*button*) (?*frame* setVisible TRUE) swingDemo.bat

Demo 1: PAT (Pattern Analysis Tool) PAT is a simple decision-tree for choosing a Java design-pattern. Uses an initial interview to establish problem space. Recommends a GoF Java design- pattern to fit the available facts. examples/pattern.clp

The Jess API 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)

The Rete (ree-tee) Object 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.

Using the Jess API… …is simple…all you really do need to do is call one or more Rete methods … try { Rete engine = new Rete(); engine.executeCommand( “printout t “Hello PJUG”); engine.run(); } catch (JessException je {}

Demo 2: Catalog Servlet import jess.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public abstract class BaseServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }... Here is an example of a Jess application running as a Java servlet…

Pattern References Shalloway, A., Design Patterns Explained, Addison-Wesley, 2002 Gamma, E. et. al., Design Patterns: Elements of Reusable Object-Orient Software, Addison- Wesley, 1995

Expert Systems References Friedman-Hill, E. J., Jess In Action, Manning Press, 2003 Jackson, P., Introduction to Expert Systems – 3 rd Ed., Addison-Wesley, 1999 Giarratano, J., Expert Systems: Principals and Programming, PSW- Kent, 1989

Links Download Jess at: Join the Jess user community at: html See Dr. Friedman-Hill’s Jess in Action at:

For Further Study CLIPS Expert System Shell FuzzyJ Website IR_public/fuzzy/ fuzzyJToolkit2.html

Q & A Thanks for your attention, and I hope that you try Jess !