Upload
nhoc-buong-binh
View
220
Download
0
Embed Size (px)
Citation preview
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 1/29
Java Expert System Shell
Matthieu Moisse
AAU
5 November 2009
Matthieu Moisse (AAU) Jess 5 November 2009 1 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 2/29
1 History
2 IntroductionExpert System
Rule-Based System
3 SyntaxFunctionsTemplates
FactsRules
4 Example
5 Use
6 My Opinion
7 Questions
8 References
Matthieu Moisse (AAU) Jess 5 November 2009 2 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 3/29
History
Dr. Ernest J. Friedman-Hill
Sandia National Laboratories (late 1995)
inspired by CLIPSC Language Integrated Production System1985 at NASA-Johnson Space Center
Syntax of LISP
Matthieu Moisse (AAU) Jess 5 November 2009 3 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 4/29
Expert System
Domain in AI
Simulates human brain
Expert Systems
Neural NetworksBlackboard SystemsBelief NetworksCase-Based ReasoningRule-Based Systems
Matthieu Moisse (AAU) Jess 5 November 2009 4 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 5/29
Why would we use it?
Procedural Programming
functions
logic control
sequentialdeterministic
Declarative Programming
rules & facts
no logic control
Matthieu Moisse (AAU) Jess 5 November 2009 5 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 6/29
Rule-Based System
Working Memory (Facts)
Rule Base (If Then Else)Inference Engine (Reasoning)
Matthieu Moisse (AAU) Jess 5 November 2009 6 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 7/29
Inference Engine
Pattern Matching (Rete)Activate RuleConflict ResolutionFire Rule
Matthieu Moisse (AAU) Jess 5 November 2009 7 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 8/29
Basics
Commands
(reset)(run)
Matthieu Moisse (AAU) Jess 5 November 2009 8 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 9/29
Basics
Symbols
letters
digits
$∗ = +/ <> ?#
Symbols
foofirst-value
contestant#1abc
Matthieu Moisse (AAU) Jess 5 November 2009 9 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 10/29
Basics
Numbersint
long
double
Numbers
34.5.643
5654L6.0E41D
Matthieu Moisse (AAU) Jess 5 November 2009 10 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 11/29
Basics
Strings
“ ”
no escape sequences
Strings
“foo”“Hello, World”“\“Nonsense,\” he said firmly.”
“Hello,There”
Matthieu Moisse (AAU) Jess 5 November 2009 11 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 12/29
Basics
Lists
everything is a list
Lists(+ 3 2)(a b c)(“Hello, World”)()
(deftemplate foo (slot bar))
Matthieu Moisse (AAU) Jess 5 November 2009 12 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 13/29
Function
Functions
(deffunction <function-name> [<doc-comment>] (<parameter>*)<exp>* [<return-specifier>])
Function(deffunction max “Calculates the max of 2 variables” (?a ?b)(if (> ?a ?b) then
(return ?a)else
(return ?b)))
Matthieu Moisse (AAU) Jess 5 November 2009 13 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 14/29
Facts
Facts
Templates
Unordered Facts
Ordered Facts
Shadow Facts
Matthieu Moisse (AAU) Jess 5 November 2009 14 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 15/29
Templates
Templates(deftemplate <template-name> [extends <extended-template-name>][<doc-comment>] (slot — multislot <slot-name> [some options])*)
Template
(deftemplate automobile“A specific car.”)(slot make)(slot model)
(slot year (type INTEGER))(slot color (default white))
)
Matthieu Moisse (AAU) Jess 5 November 2009 15 / 29
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 16/29
Unordered Facts
Template
(deftemplate automobile“A specific car.”)(slot make)(slot model)(slot year (type INTEGER))(slot color (default white))
)
Unordered facts
(<template-name> (<slot-name> <value>)*)
Unordered fact
(automobile (make ford) (year 1999) (model Explorere))
Matthieu Moisse (AAU) Jess 5 November 2009 16 / 29
O d d F
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 17/29
Ordered Facts
Ordered facts(<template-name> <value>*)
Ordered fact
Domain in AI Simulates human brain(shopping-list eggs milk bread)
Template
(deftemplate shopping-list
“A list of stuff we need to buy”(declare (ordered TRUE))
)
Matthieu Moisse (AAU) Jess 5 November 2009 17 / 29
Sh d F
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 18/29
Shadow Fact
Link to Java-Objects
Shadow Fact
(bind ?a (new Account))(add ?a)(printout t (?a getBalance) crlf)(modify 0 (balance 1))
Matthieu Moisse (AAU) Jess 5 November 2009 18 / 29
R l
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 19/29
Rules
Rules
(defrule <rule-name> [<doc-comment>] <LHS> => <RHS> )
LHSIFPattern Matching
RHS
THEN
. . .
Matthieu Moisse (AAU) Jess 5 November 2009 19 / 29
R l
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 20/29
Rules
Rule
(defrule all-fords“find all ford models”?car < − (automobile {make == ford})=>(printout t “A ” ?car.model “ is a model of ford!” crlf)
)
Rule
(defrule match-list-with-bacon
“Find grocery-lists that contains bacon”(grocery-list $? bacon $?)=>(printout t “Yes, bacon is on the list” crlf)
)
Matthieu Moisse (AAU) Jess 5 November 2009 20 / 29
E l
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 21/29
Example
Example
(deftemplate pants-color (slot of) (slot is))(deftemplate position (slot of) (slot is))
Matthieu Moisse (AAU) Jess 5 November 2009 21 / 29
Example
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 22/29
Example
Example
(defrule generate-possibilities=>
(foreach ?name (create$ Fred Joe Bob Tom)(foreach ?color (create$ red blue plaid orange)
(assert (pants-color (of ?name) (is ?color))))(foreach ?position (create$ 1 2 3 4)
(assert (position (of ?name) (is ?position))))))
Matthieu Moisse (AAU) Jess 5 November 2009 22 / 29
Example
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 23/29
Example
Example
(defrule find-solution;; There is a golfer named Fred, whose position is ?p1;; and pants color is ?c1
(position (of Fred) (is ?p1))
(pants-color (of Fred) (is ?c1));; The golfer to Fred’s immediate right;; is wearing blue pants.
(position (of ?n& Fred) (is ?p&:(eq ?p (+ ?p1 1))))(pants-color (of ?n& Fred) (is blue& ?c1))
;; Joe is in position #2(position (of Joe) (is ?p2&2& ?p1))(pants-color (of Joe) (is ?c2& ?c1))
Matthieu Moisse (AAU) Jess 5 November 2009 23 / 29
Example
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 24/29
...Example...
...Example...;; Bob is wearing the plaid pants
(position (of Bob)(is ?p3& ?p1& ?p& ?p2))
(pants-color (of Bob& ?n)(is plaid&?c3& ?c1& ?c2))
;; Tom isn’t in position 1 or 4;; and isn’t wearing orange
(position (of Tom& ?n)
(is ?p4& 1& 4& ?p1& ?p2& ?p3))(pants-color (of Tom)(is ?c4& orange& blue& ?c1& ?c2& ?c3))
Matthieu Moisse (AAU) Jess 5 November 2009 24 / 29
Example
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 25/29
...Example
...Example
=>
(printout t Fred ” ” ?p1 ” ” ?c1 crlf)(printout t Joe ” ” ?p2 ” ” ?c2 crlf)(printout t Bob ” ” ?p3 ” ” ?c3 crlf)(printout t Tom ” ” ?p4 ” ” ?c4 crlf crlf))
Matthieu Moisse (AAU) Jess 5 November 2009 25 / 29
Use
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 26/29
Use
puzzles
business environments
J2EE enterprise applications
Windows CE handhelds
DDG 1000 destroyer ship
Matthieu Moisse (AAU) Jess 5 November 2009 26 / 29
My Opinion
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 27/29
My Opinion
. . .
Matthieu Moisse (AAU) Jess 5 November 2009 27 / 29
Questions
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 28/29
Questions
?
Matthieu Moisse (AAU) Jess 5 November 2009 28 / 29
Use
7/27/2019 MatthieuMoisse2
http://slidepdf.com/reader/full/matthieumoisse2 29/29
Use
http://www.jessrules.com/
http://www.developer.com/java/other/article.php/3089641
http:
//www.sandia.gov/news/resources/releases/2008/jessengine.html
http://www.pjug.org/introtojess.ppt
Matthieu Moisse (AAU) Jess 5 November 2009 29 / 29