Escolar Documentos
Profissional Documentos
Cultura Documentos
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
Quotable Quotes
Hell, there are no rules here -we're trying to accomplish something. - Thomas A. Edison
Quotable Quotes
Get your facts first, and then you can distort them as much as you please. - Mark Twain
Quotable Quotes
If the facts don't fit the theory, change the facts.
Albert Einstein
Quotable Quotes
There are two rules for success: 1) Never tell everything you know. - Roger H. Lincoln
Quotable Quotes
Facts do not cease to exist just because they are ignored. - Aldous Huxley
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.
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.
Inference Process
Match the facts against the rules. Choose which rules to fire. Execute the actions associated with the rules.
INFERENCE ENGINE
PATTERN MATCHER
EXECUTION ENGINE
RULE BASE
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 IFTHENELSE coding.
Wait a minute!
What? II cant control my code??
Thought Experiment
Imagine writing a procedural/OOP algorithm to solve a jigsaw puzzle. 500+ pieces, different shapes and colors. Polymorphism runs amok!
Yet we manage to solve the puzzle
Intuitive Inferencing
(corner_found (piece_is_corner) => (assert corner-found) (save_piece)) (edge_found (piece_is_edge) => (assert edge-found) (save_piece)) Your brain knows what to do with a corner piece
Whats 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.
Obligatory Tradition
Your very first Jess program!
(printout t Hello PJUG-ers! crlf)
Lists in Jess
Here are some valid lists in Jess: (a b c) (1 2 3) (+ 2 3) (Hello (foo ?x ; list of tokens ; list of integers ; an expression world!) ; a string ?y) ; a function call
Jess Variables
Named containers that hold a single value. Untyped. Begin with a ? mark. Can change types during lifetime. Assigned using bind function.
Control Flow
Common Jess-specific
Jess Functions
Even functions are lists.
(deffunction get-input() Get user input from console. (bind ?s (read)) (return ?s))
(printout t "The surface area of a radius = 2 meter sphere is " + (area-sphere 2) + " m^2")
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
Facts store the initial conditions.
;; Asserting a new pattern fact. (printout t Enter pattern name: crlf) (bind ?x getInput) (assert pattern (name ?x))
Shadow Facts
Shadow facts are unordered facts whose slots correspond to the properties of a JavaBean. defclass creates a deftemplate from a bean. definstance adds bean to working memory.
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.
Break Time!
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 designpattern to fit the available facts.
examples/pattern.clp
engine.executeCommand(
printout t Hello PJUG); engine.run();
}
catch (JessException je {}
Here is an example of a Jess public abstract class BaseServlet extends HttpServlet { application running as a public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, Java servlet
ServletException { doGet(request, response); } }...
Pattern References
Shalloway, A., Design Patterns Explained, Addison-Wesley, 2002 Gamma, E. et. al., Design Patterns: Elements of Reusable Object-Orient Software, AddisonWesley, 1995
Links
Download Jess at:
http://herzberg.ca.sandia.gov/jess/index.shtml
Q&A
Thanks for your attention, and I hope that you try Jess!