Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intelligent Systems JESS constructs.

Similar presentations


Presentation on theme: "Intelligent Systems JESS constructs."— Presentation transcript:

1 Intelligent Systems JESS constructs

2 CLIPS C Language Integrated Production System – 1984
Supports three programming paradigms: Rule based Object oriented Procedural Integrated with other languages (C, Ada, Java, etc) Portable through operating systems Low cost Efficient

3 JESS Java based implementation of the CLIPS language
Very good integration with all Java functionality Supports both forward and backward chaining reasoning styles IDE Integrated with Eclipse Also available as a command line interface java -classpath lib\jess.jar jess.Console

4 Programming with JESS Pure Jess language scripts. No Java code at all.
Pure Jess language scripts, but the scripts access Java APIs. Mostly Jess language scripts, but some custom Java code in the form of new Jess commands written in Java. Half Jess language scripts, with a substantial amount of Java code providing custom commands and APIs; main() provided by Jess. Half Jess language scripts, with a substantial amount of Java code providing custom commands and APIs; main() provided by Java. Mostly Java code, which loads Jess language scripts at runtime. All Java code, which manipulates Jess entirely through its Java API. JESS language AND JESS API

5 Introductory Concepts
Facts Rules Inference engine Hello world: (deffacts initial (start)) (defrule hello-rule (start) => (printout t “Hello world” crlf) ) (reset) (run)

6 Syntax and data types LISP like syntax Case sensitive
Comments: starts with “;” or block comments /*…*/ Fields: primitive data types Symbol: accepts $*=+/<>_?# and start with letters, nil, TRUE, FALSE Numbers: Integers, Long Integers, Double Strings Lists: ( a b c 1 2) Variables: ?varName, global variables: ?*globalVar*

7 Facts Unstructured (ordered facts):
(is_morning) (digits ) Structured/Ordered (deftemplate facts), have slots: (time_of_day (id morning) (start-hour 0) (end-hour 10) ) (person (name Calin Sandru) (address “V. Parvan 4, Timisoara”) Pure facts and Shadow facts: connected to Java objects

8 Deftemplate Facts Facts templates: enforces structure
Constructs: allow for adding knowledge (deftemplate person “Sample deftemplate” (multislot name) (slot address) ) Dotted variables ?x.y : the slot y of the variable x Ordered facts have a default generated template: (deftemplate digits (multislot values) (digits (values ))

9 Managing facts (facts) (assert (retract <fact number>)
(person (name John White) (address “Timisoara”)) (person (name Marry Smith) (address “Bucuresti”))) (retract <fact number>) (modify 0 (address Arad)) (duplicate 1 (name Dan Smith)) (deffacts people “Known people” (person (name John White) (address “Timisoara”)) (person (name Dan Smith) (address “Bucuresti”))) (watch facts) – monitor facts (initial-fact) (reset) : does not reset the global variables but reset the others

10 Rules IF <preconditions> THEN <actions>
IF the light is green THEN cross the street Preconditions: set of patterns (deftemplate light (slot colour)) (deftemplate response (slot action)) (defrule decide_to_cross (light (colour green)) => (assert (response (action cross-the-street))) ) Salience: rule priority

11 More complex sample (deftemplate available (multislot teacher) (multislot schedule_time)) (deftemplate assignment (slot room) (slot class) (deftemplate free_room (multislot schedule_time ) )

12 (defrule assign_IS (free_room (room 045C) (schedule_time Monday "8.00")) (available (teacher "Calin Sandru") (schedule_time Monday "8.00")) => (assert (assignment (room 045C) (teacher "Calin Sandru") (class IS) (schedule_time Monday "8.00") )

13 More complex templates
(deftemplate template-name [extends template-name] ["Documentation comment"] [(declare (slot-specific TRUE | FALSE) (backchain-reactive TRUE | FALSE) (from-class class name) ;creates slots for bean properties (include-variables TRUE | FALSE) ; create slots for public vars (ordered TRUE | FALSE))] (slot | multislot slot-name ( [(type ANY | INTEGER | FLOAT | NUMBER | SYMBOL | STRING | LEXEME | OBJECT | LONG)] [(default default value)] [(default-dynamic expression)] [(allowed-values expression+)])*)

14 Slot specific (deftemplate car (declare (slot-specific TRUE))
(slot color) (slot type) ) (defrule paint_compact_cars ?d <- (car (type compact)) => (modify ?d (color red)) ;;endless loop without slot specific

15 Agenda & Execution Match-Select-Fire cycle (agenda)
(run <max # of rules>) Refraction: avoiding infinite activations for the same rule (refresh <rule-name>) – makes the rule firing again (watch rules) – monitor rules firing (watch activations) – monitor agenda modifications

16 Manipulating constructs
(list-defrules) (list-deffacts) (list-deftemplates) (ppdefrule <defrule-name>) (ppdeffacts <deffacts-name>) (ppdeftemplate <deftemplate-name>) (undefrule <defrule-name>) (undeftemplate <deftemplate-name>) (undeffacts <deffacts-name>) (clear)

17 Variables (defrule print_person_name (defrule find_free
(person (name ?name) (address ?)) => (printout t ?name crlf ) ) (defrule find_free (free_room (room 045C) (schedule_time $?time)) (printout t $?time crlf) (assert (free_room (room 045C) (schedule_time Tuesday "9.30"))) (agenda) > find_free: f-1 (run) >(Tuesday "9.30”)

18 Facts addresses (defrule assign_IS_retract
?f <- (free_room (room 045C) (schedule_time Monday "8.00")) ?f 1<- (available (teacher "Calin Sandru") (schedule_time Monday "8.00")) => (assert (assigned (room 045C) (teacher "Calin Sandru") (class IS) (schedule_time Monday "8.00") ) (retract ?f ?f1)

19 Facts: Integration with Java
(import gov.sandia.jess.example.pricing.model.*) (deftemplate order (declare (from-class Order))) (definstance <template-name> <Java object> [static | dynamic | auto] ) Ex: (definstance order (new Order price)) (add <Java object>) (definstance <classname> <Java object> auto) (undefinstance (<java-object> | * ))

20 Links http://www.jessrules.com/jess/docs/


Download ppt "Intelligent Systems JESS constructs."

Similar presentations


Ads by Google