jess: a rule-based programming environment reporter: yu lun kuo e-mail: [email protected] date:...
TRANSCRIPT
Jess: A Rule-Based Programming Environment
Reporter: Yu Lun KuoE-mail: [email protected]: April 10, 2006
Expert System
Page 2
Why Expert System
Question of project developer– Program = algorithm + Data Structure (Hard)
– Software Engineering• Demand Design Coding (Demand Phase)
– Programmer
Expert Systems– Rule-based computer programs that capture the
knowledge of human experts in their own fields of experience
Page 3
Rules
A rule is a kind of instruction or command that applies in certain situationsRules are a lot like the if-then statements of traditional programming languages– if part of a rule is often called its left-hand side– then part of a rule is often called its right-hand side
• A rule-based system is a system that uses rules to derive conclusions from premises
if predicate or premisesthen actions or conclusions
Page 4
Rule Engine
A rule engine doesn’t contain any rules until they are programmed in– A rule engine knows how to follow rules, without
containing any specific knowledge itself
– deployment environment
Page 5
Architecture of a Rule-Based System
A typical rule engine contains– Inference engine
• Forward Chaining – LISP, CLIPS• Backward Chaining - PROLOG
– Rule base (knowledge base)– Working memory (fact base)
Inference engine consists of– Pattern matcher– Agenda– Execution engine
Page 6
Pattern Matcher
The working memory contains thousands of facts, and each rule has two or three premises
The pattern matcher need to search through millions of combinations of facts to find those combinations that satisfy rules– All the rules are compared to working memory
– Decide which ones should be activated during this cycle
Page 7
Agenda
Inference engine figures out which rules should be fired, it still must decide which rule to fire first– The list of rules that could potentially fire is stored
on the agenda
– Ex.Give high priority
Page 8
Execution Engine
The execution engine is the component of a rule engine that fires the rules
Some modern rule engines offer a complete programming language you can use define– What happen when a give rules fires
Page 9
Conflict Set
Conflict Resolution
Fired
Page 10
Page 11
Jess (Java Expert System Shell)
The Java Rule Engine API defined by the javax.rules package– A standard enterprise API for accessing rule engines– Site: http://www.jcp.org/jsr/detail/94.jsp
Jess rule engine– A rule engine and scripting language developed at
Sandia National Laboratories in Livermore, California in the late 1990s
– It can access to all of Java’s powerful APIs for networking, graphics, database access, and so on
Page 12
Jess (Cont.)
The Jess language can directly access all Java classes and libraries– This allows you to experiment with Java APIs
interactively and build up large programs incrementally
– Jess is therefore useful in a wide range of situations
– Jess can be used in command-line applications, GUI applications, servlets, and applets.
Page 13
The most important step in developing a Jess application is to choose an architecture– Pure Jess language, with no Java code
– Pure Jess language, but the program accesses Java APIs
– Mostly Jess language code, but with some custom Java code in the form of new Jess commands written in Java
– Half Jess language code, with a substantial amount of Java code providing custom commands and APIs. Jess provides the main() function
– Half Jess language code, with a substantial amount of Java code providing custom commands and APIs. You write the main() function
– Mostly Java code, which loads Jess language code at runtime
– All Java code, which manipulates Jess entirely through its Java API
Page 14
Scripting Java with Jess
From Java code, you can access all parts of the Jess library– Easy to embed Jess in any Java application
– Use Jess for experimenting with Java APIs• Jess is therefore a kind of scripting language for Java
You can create the windows, buttons, and other graphical components with a few lines of Jess code
Page 15
Representing facts in Jess
The contents of Jess’s working memory are held in your computer’s RAM
Most other constructs in Jess, facts are stored as lists
Jess offers a set of functions to let a program perform the basic collection operations on the working memory– add, remove, modify, duplicate
Page 16
Working memory
assert – Add facts to working memoryClear – Clears all of JessDeffacts – Defines the initial contents of
working memoryFacts – Display the content of working memoryReset – Initializes the working memoryRetract – Removes facts from working memoryWatch – Tells Jess to print diagnostics when
interesting things happen