March 12, 2003UMontreal ift68021 JESS:Java Expert System Shell Course IFT6802 Student ZHENG ZHEN.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

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.
November 2, 2004AI: CLIPS Language Tutorial1 Artificial Intelligence CLIPS Language Tutorial Michael Scherger Department of Computer Science Kent State.
Chapter 8 Pattern Matching
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.
Introduction to CLIPS (Chapter 7) Fact List (contains data) Knowledge Base (contains rules) Inference Engine (controls execution)
Mary Lou Maher MIT Fall 2002 Jess: A Production System Language Agent-Based Virtual Worlds.
© C. Kemke CLIPS 1 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Outline Java program structure Basic program elements
© C. Kemke Control 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Chapter 8: Advanced Pattern Matching Expert Systems: Principles and Programming, Fourth Edition.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
Introduction to Jess.
Jess Presentation by Chun Ping Wang. What is Jess? Jess is an expert system shell made for java. Rete pattern algorithm. Purpose. –Jess is best use for.
CS 561, Session 25 1 Introduction to CLIPS Overview of CLIPS Facts Rules Rule firing Control techniques Example.
Abstract Data Types and Encapsulation Concepts
The JessTab Approach to Protégé and Jess Integration
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Intro to Jess The Java Expert System Shell By Jason Morris Morris Technical Solutions.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
1 Programming a Knowledge Based Application. 2 Overview.
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
Artificial Intelligence Lecture No. 17 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
How Java becomes agile riding Rhino Xavier Casellato VP of engineering, Liligo.com.
The Java Programming Language
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
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.
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
I Power Higher Computing Software Development Development Languages and Environments.
Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 Knowledge Based Systems (CM0377) Lecture 10 (Last modified 19th March 2001)
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
Artificial Intelligence Lecture No. 19 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
Intelligent systems Lecture 11 Tools for development of Expert Systems.
The CLIPS Expert System Shell Dr Nicholas Gibbins
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Summary for final exam Agent System..
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014.
Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS C Language Integrated Production System Developed at the Software Development Branch, NASA Lyndon B. Johnson.
Fundamentals of Programming I Overview of Programming
Integration Part 2 Intelligent Systems Integration Part 2
JESS-JAVA Integration
Working with Java.
Intelligent Systems JESS constructs.
Chapter 7: Introduction to CLIPS
Chapter 8: Advanced Pattern Matching
بسم الله الرحمن الرحیم آموزش نرم افزار CLIPS
Chapter 11: Classes, Instances, and Message-Handlers
JESS (Java Expert System Shall)
Jess Knowledge, Influence, Behavior
Focus of the Course Object-Oriented Software Development
Presentation transcript:

March 12, 2003UMontreal ift68021 JESS:Java Expert System Shell Course IFT6802 Student ZHENG ZHEN

March 12, 2003UMontreal ift68022 Overview What is Jess? tool for building intelligent software Jess is a tool for building a type of intelligent software called Expert Systems. An Expert System : a set of rules a set of rules can be repeatedly applied to a collection of facts Developed by Sandia Laboratories

March 12, 2003UMontreal ift68023 facts facts in Jess look like: (person "Bob Smith" Male 35) or (person (name "Bob Smith") (gender Male) (age 34)) slots rules rules in Jess look like: A rule A rule has two parts: LHS pattern => RHS action (defrule example-3 (not-b-and-c ?n1&~b ?n2&~c) (different ?d1 ?d2&~?d1) => (printout t "Found what I wanted!" crlf))

March 12, 2003UMontreal ift68024 What are advantages?  Jess is a rule engine  Jess is a scripting environment for Java Jess call Java  Jess is faster than some popular expert system shells written in C  Jess is easy to extend with new commands  …

March 12, 2003UMontreal ift68025 How to start?  Start as command-line interface java -classpath jess.jar jess.Main  Start as console-style GUIs java -classpath jess.jar jess.Console

March 12, 2003UMontreal ift68026 Introduction  Basics: Atom Atom letters, numbers and $*=+/<>_?#. case sensitive Numbers, Strings, Comments (;) Lists Lists fundamental unit of syntax in Jess ( a b c), variables variables (?) + atoms : ?x multivariable multivariable $+ variable: $?y (defrule example (grocery-list $?list) => (printout t "I need to buy " $?list crlf)) Jess> (assert (grocery-list eggs milk bacon)) Global variable Global variable : ?*x* or ?*all-values*

March 12, 2003UMontreal ift68027 Function: Function: can be defined with two ways 1) define a function directly (deffunction max (?a ?b) (if (> ?a ?b) then ?a else ?b)) Function calls are simply lists Jess> (printout t "The greater of 3 and 5 is " (max 3 5) crlf) The greater of 3 and 5 is 5 2) "wrap" extra code around any Jess function (defadvice before + (bind $?argv (create$ $?argv 1))) Jess> (+ 2 2) 5 Examples: FunctionVariables

March 12, 2003UMontreal ift68028  Java reflection 1) Jess can create and manipulate Java objects directly (bind ?ht (new java.util.Hashtable)) Jess> (call ?ht put "key1" “Apple") Jess> (?ht get "key1") “Apple" 2) Jess access member variables of Java objects Jess> (bind ?pt (new java.awt.Point)) Jess> (set-member ?pt x 37) 37 Jess> (set-member ?pt y 42) 42 Jess> (get-member ?pt x) 37

March 12, 2003UMontreal ift68029  access static members by using the name of the class Jess> (get-member System out)  Jess can import either a whole package using (import java.io.* ) or a single class using (import java.awt.Button)  Type conversion (Rete Utilities, RU) null'nil'boolean/Boolean'TRUE','FALSE' void'nil'byte, short, int/wrappersRU.INTEGER StringRU.STRINGdouble, float /wrappersRU.FLOAT An arraymultifieldChar/CharacterRU.ATOM long / LongRU.LONGanything elseRU.EXTERNAL_ADDRESS

March 12, 2003UMontreal ift  Facts Facts Facts is one of the most important parts of Jess ordered facts (1) ordered facts Factsunordered facts Facts (2) unordered facts definstance facts (3) definstance facts (1): (assert (person "Bob Smith" Male 35) ) (2): using the deftemplate define the slots ( deftemplate person (slot name ) (slot age ) (slot gender ) ) after that assert unordered fact: (assert (person (name "Bob Smith") (age 34) (gender Male)))

March 12, 2003UMontreal ift (3): template similarity Java Beans slots similarity properties Jess provides: defclassJava Beans Jess template definstance Bean representation fact base import java.io.Serializable; public class ExampleBean implements Serializable { private String m_name = "Bob"; public String getName() { return m_name; } public void setName(String s) { m_name = s; } }// end of class Jess> (defclass simple ExampleBean) Jess> (ppdeftemplate simple)

March 12, 2003UMontreal ift Jess> (bind ?sb (new ExampleBean)) Jess> (definstance simple ?sb static) dynamic Jess> (facts) f-0 (MAIN::simple (class ) (name "Bob") (OBJECT )) For a total of 1 facts A fact representing the Bean appears in the knowledge base Examples: FactsConsole

March 12, 2003UMontreal ift  Rules Rules Rules can take actions based on the contents of facts It is similar to if … then…, but … Jess> (watch all) Jess> (defrule do-change-baby "If baby is wet, change baby's diaper.“ (baby-is-wet) => (change-baby)) Jess> (deffunction change-baby () (printout t "Baby is now dry" crlf)) Jess> (assert (baby-is-wet)) Jess> (run) FIRE 1 MAIN::do-change-baby f-1 Baby is now dry <== Focus MAIN 1

March 12, 2003UMontreal ift  Basic Patterns Jess> (defrule example (different ?d1 ?d2&~?d1) (same ?s ?s) (more-than-one-hundred ?m&:(> ?m 100)) (red-or-blue red|blue) (one-more ?X =(+ ?X 1)) => (printout t "Found what I wanted!" crlf)) Which facts can fire this rule? 1. (different ) 2. (same d d) 3. (red-or-blue white) 4. (more-than-one-hundred 101) 5. (one-more 72 73)

March 12, 2003UMontreal ift  Pattern bindings A pattern-binding variable used to retract /modify the fact Jess> (defrule example-5 ?fact (retract ?fact)) 1.Jess> (assert (a "retract me")) ==> f-1 (MAIN::a "retract me") ==> Activation: MAIN::example-5 : f-1 If we try assert the fact again, Jess prompt ‘FALSE’ 2.Jess> (assert (a "retract me")) FALSE 3.Jess> (run) FIRE 1 MAIN::example-5 f-1 <== f-1 (MAIN::a "retract me") <== Focus MAIN 1

March 12, 2003UMontreal ift Jess> (run) 0 5. Jess> (assert (a "retract me")) ==> f-2 (MAIN::a "retract me") ==> Activation: MAIN::example-5 : f-2 6.Jess> (facts) f-0 (MAIN::initial-fact) f-2 (MAIN::a "retract me") For a total of 2 facts. Where is the f-1? pattern-binding variable ?fact <---- fact ID <----a reference to a jess.Fact objectjess.Fact

March 12, 2003UMontreal ift  Salience Salience is a kind of rule priority, each rule has one Salience high be fired if same salience then conflict resolution strategy Salience low Salience values can be integers, global variables, or function calls Jess> (defrule example-6 (declare (salience -100))... => ….) Or call(set-salience-evaluation..) Activated Rule1 Activated Rule2 Activated Rule3. Activated Rule n

March 12, 2003UMontreal ift  Conditional Element (CE.)  'and' used to construct complex logical conditions with or and notornot  'or' Jess> (defrule or-example-1 (or (a) (b) (c)) =>) MAIN::or-example-1: =1+1+1+t ……. (1) MAIN::or-example-1&1: t……. (2) MAIN::or-example-1&2: t……. (3) TRUE Jess> (assert (a) (b) (c)) Jess> (printout t (run) crlf) FIRE 1 MAIN::or-example-1 f-3 FIRE 2 MAIN::or-example-1 f-2 FIRE 3 MAIN::or-example-1 f-1 3 (1),(2) and (3) are 3 separate sub-rules

March 12, 2003UMontreal ift  'not‘ Jess> (defrule forall-example (not (and (a ?x) (not (b ?x)))) =>) “ a => b ; a V b” cannot define any variables used in subsequent patterns only evaluated a fact matching it exists if a not CE is the first on a rule's LHS (not () …=>) the first in an and group (or (..) (not(..))..=>) the only pattern on a given branch of an or group then (initial-fact) is inserted as preceding pattern Why usually write (reset) before (run) in the Jess file?

March 12, 2003UMontreal ift Rearranging not CE together with and and or Based on DeMorgan's rules for logical operations 1. (not (and (x) (y))) => (or (not (x)) (not (y))) “  (x  y) => (  x)  (  y)” 2. (not (or (x) (y))) => (and (not (x)) (not (y))) “  (x  y) => (  x)  (  y)” Two constraints of Jess rule LHS: 1. or CE must be at the top level 2. not CE must apply DeMorgan's rules Conjunctive Normal Form atom exclude ‘  ’, conjunct with ‘  ‘

March 12, 2003UMontreal ift  'test' Jess> (deftemplate person (slot age)) Jess> (defrule example-8 (person (age ?x)) (test (> ?x 60)) => (printout t ?x " is over 60!" crlf)) Jess> (assert (person (age 65))) ==> f-8 (MAIN::person (age 65)) ==> Activation: MAIN::example-8 : f-8, Jess> (run) FIRE 1 MAIN::example-8 f-8, 65 is over 60!

March 12, 2003UMontreal ift test CE is evaluated as long as evaluated the preceding pattern so Jess> (defrule rule_1 (foo ?X) (test (> ?X 3)) =>) same as Jess> (defrule rule_2 (foo ?X&:(> ?X 3)) =>) therefor IF a test CE is the first pattern on the LHS, or the first pattern in a branch of an or CE (initial-fact) must insert as the "preceding pattern " Why usually write (reset) before (run) in the Jess file?

March 12, 2003UMontreal ift  'logical' logical CE specify logical dependencies among facts Jess> (defrule rule-1 (logical (faucet-open)) => (assert (water-flowing))) Jess> (assert (faucet-open)) Jess> (run) Jess> (facts) f-0 (MAIN::faucet-open) f-1 (MAIN::water-flowing) For a total of 2 facts. Jess> (watch facts) Jess> (retract (fact-id 0)) <== f-0 (MAIN::faucet-open) <== f-1 (MAIN::water-flowing) TRUE logical CE must be the first patterns in the rule

March 12, 2003UMontreal ift  'unique' Jess> (deftemplate tax-form (slot social-security-number)) Jess> (deftemplate person (slot social-security-number) (slot name)) Jess> (defrule unique-demo (tax-form (social-security-number ?num)) (unique (person (social-security-number ?num) (name ?name))) => (printout t "Auditing " ?name "..." crlf)) unique CE hint to Jess that only one can have a given SSN so Jess don’t look further in the same patten, unique don’t combine with either test or not CEs unique is quite similar to Prolog’s ! (cut)

March 12, 2003UMontreal ift  'exists' Jess> (defrule exists-demo (exists (honest ?)) => (printout t "There is at least one honest man!" crlf)) (exists (A)) same as (not (not (A))). in the same pattern, exists may not be combined with a test CE. Combination of various CE can provide the powerful flexible inference engine

March 12, 2003UMontreal ift  Forward and backward chaining 1) supports both forward and backward chaining 2) To use backward chaining in Jess, use like Jess> (do-backward-chaining factorial) Prolog is backwards chaining: given the rules human(Socrates). mortal(X) :- human(X) Jess, though, is forwards chaining. Here, you have Jess> (assert (human Socrates)) Jess> (defrule mortal (human ?X) => (assert (mortal ?X))) Jess> (watch facts) Jess> (run) ==> f-1 (MAIN::mortal Socrates) 1

March 12, 2003UMontreal ift  Defqueries defquery create a special kind of rule with no RHS Jess> (defquery search (declare (variables ?X)) (foo ?X ?Y)) Jess> (deffacts data (foo blue red) (bar blue green) (foo blue pink) (foo red blue) (foo blue blue) (foo orange yellow) (bar blue purple)) Jess> (reset) Jess> (bind ?it (run-query search blue)) Jess> (while (?it hasNext) (bind ?token (call ?it next)) (bind ?fact (call ?token fact 1)) (bind ?slot (fact-slot-value ?fact __data)) (bind ?datum (nth$ 2 ?slot)) (printout t ?datum crlf)) red pink blue FALSE

March 12, 2003UMontreal ift  Defmodules Modules divide rules and templates into distinct groups By default, current module is "MAIN::“ Jess> (defmodule WORK) Jess> (deftemplate WORK::job (slot salary)) TRUE Jess> (list-deftemplates WORK) WORK::job For a total of 1 deftemplates. Jess> (get-current-module) WORK The MAIN is global namespace for templates.

March 12, 2003UMontreal ift680229

March 12, 2003UMontreal ift  Returning from a rule RHS return terminates the execution of RHS and focus module popped from the focus stack using focus call a module from a rule's RHS using return return from the call like a subroutine

March 12, 2003UMontreal ift Jess vs. Java  use Jess library in Java import jess.*; public class ExSquare { public static void main(String[] unused) { try { Rete r = new Rete(); r.executeCommand("(deffunction square (?n) (return (* ?n ?n)))"); Value v = r.executeCommand("(square 3)"); // Prints '9' System.out.println(v.intValue(r.getGlobalContext())); } catch (JessException ex) { System.err.println(ex); } } C:\> java ExSquare 9

March 12, 2003UMontreal ift  jess.Rete class : the rule engine itself 1. each jess.Rete object : an independent reasoning engine 2. jess.Rete object in a multithreaded environment assert or retract in a given jess.Rete object at a time 3. Call Jess functions directly in Java run(), reset(), clear(), assertFact(Fact), retract(Fact), retract(int), and halt(). 4. Executing other Jess commands Rete class's executeCommand(String cmd) a parseable String returns the jess.Value object & interpreted in the global context

March 12, 2003UMontreal ift Value resolution static values (atoms, numbers, strings) jess.Value dynamic values (variables, function calls) dynamic values need to be interpreted in a particular context before use jess.Value.intValue(jess.Context) is self-resolving jess.Value. type() return RU.VARIABLE for a jess.Value object jess.Value. resolveValue() resolve the return value

March 12, 2003UMontreal ift Transferring values between Jess and Java On java side methods are available in the jess.Rete public Value store(String name, Value val); public Value store(String name, Object val); public Value fetch(String name); public void clearStorage(); On jess side : (store ) (fetch ) (clear-storage)

March 12, 2003UMontreal ift import jess.*; public class ExFetch { public static void main(String[] unused) throws JessException { Rete r = new Rete(); r.store("DIMENSION", new java.awt.Dimension(10, 10)); r.executeCommand("(defclass dimension java.awt.Dimension)"); r.executeCommand("(definstance dimension (fetchDIMENSION) static)"); r.executeCommand("(facts)"); } C:\> java ExFetch f-0 (MAIN::dimension (class ) (height 10.0) (size ) (width 10.0) (OBJECT )) For a total of 1 facts.

March 12, 2003UMontreal ift Adding new functions to the Jess by implements interface Rete.addUserfunction() import jess.*; public class ExMyUpcase implements Userfunction { public String getName() { return "my-upcase"; } public Value call(ValueVector vv, Context context) throwsJessException { return new Value(vv.get(1).stringValue(context).toUpperCase(), RU.STRING); } } C:\> java ExMyUpcase Jess> (load-function ExMyUpcase) Jess> (my-upcase foo) "FOO"

March 12, 2003UMontreal ift Jess vs. Jade  Jade : Multi-agent platform  Jess + Jade : Multi-intelligent agent platform Jade call Jess = Java call Jess Jess template ~ Jade ontology public class BasicJessBehaviour extends CyclicBehaviour{ …. public class JessSend implements Userfunction { ….. jess.executeCommand(ACLJessTemplate()); jess.executeCommand("(deftemplate MyAgent (slot name))"); jess.addUserfunction(new JessSend(myAgent,this)); jess.executeCommand("(deffacts MyAgent \"All facts about this agent\" (MyAgent (name " + myAgent.getName() + ")))"); ….

March 12, 2003UMontreal ift Jess VS. Protege  Difficult manage large/complex ontologies – Ontology editors should be programmable  Difficult to integrate problem solving and ontology development – OO languages/shells need an graphical counterpart Protégé: – Knowledge acquisition and ontology development tool – Developed by SMI, Stanford University – JessTab – Combining two popular systems JessTab is a tab plug-in for running Jess inside Protégé

March 12, 2003UMontreal ift  Jess console window in Protégé

March 12, 2003UMontreal ift  Mirroring Jess definitions in Protégé knowledge bases

March 12, 2003UMontreal ift  Editing Jess definitions in Protégé

March 12, 2003UMontreal ift Agent frameworks  Jess + Jade + Protégé = JadeJessProtégé Your system Your tab JessTab FuzzyJessPrologTab JadeJessProtege FloraTab More Protégé plug-ins More Jess extension s JADE JessProtégé

March 12, 2003UMontreal ift References   Obtain Jess – Download from – License required (commercial or free academic) – Compilation required  Get JessTab – Download from  Obtain Protégé – Download from