Revision of Jess. Programming Expert Systems with Jess CS3019, Knowledge-Based Systems Lecture 21

Similar documents
Artificial Intelligence

CHAPTER-3 KNOWLEDGE REPRESENTATION. Types of Knowledge Knowledge Pyramid Knowledge Representation Methods

YAYUMA AWARENESS LINE PROCESSOR

ACT-R ACT-R. Core Components of the Architecture. Core Commitments of the Theory. Chunks. Modules

6.S084 Tutorial Problems L05 Sequential Circuits

Tutorial 11 ChipscopePro, ISE 10.1 and Xilinx Simulator on the Digilent Spartan-3E board

Woodman s Guide To Get Video On Your Touchscreen Display For LR3/Discovery 3 or Range Rover 2006+

SIPROTEC 5 Application Note

Chapter 4. Predicate logic allows us to represent the internal properties of the statement. Example:

FORMAL METHODS INTRODUCTION

SWITCH: Microcontroller Touch-switch Design & Test (Part 2)

Level and edge-sensitive behaviour

PCM ENCODING PREPARATION... 2 PCM the PCM ENCODER module... 4

KNX Dimmer RGBW - User Manual

Sequential Circuits. Output depends only and immediately on the inputs Have no memory (dependence on past values of the inputs)

Lesson Sequence: S4A (Scratch for Arduino)

Breaker-and-a-half Automatic reclosing and leader follower.

Lineside Signal Aspect and Indication Requirements

Shifty Manual v1.00. Shifty. Voice Allocator / Hocketing Controller / Analog Shift Register

Alghorithm for Map Color

Expert Mastering Assistant (EMA) Version 2.0. Technical Documentation

The BBC micro:bit: What is it designed to do?

Real-Time Systems Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Automatic Speech Recognition (CS753)

Finite State Machine Design

Chapter 2: Lines And Points

Module 4: Traffic Signal Design Lesson 1: Traffic Signal (Arduino) Control System Laboratory Exercise Grade 6-8

BeoVision Guide

StepSequencer64 J74 Page 1. J74 StepSequencer64. A tool for creative sequence programming in Ableton Live. User Manual

Korg Kronos Workflow for Worship

Lecture 12: State Machines

Meaning Machines CS 672 Deictic Representations (3) Matthew Stone THE VILLAGE

ECSE-323 Digital System Design. Datapath/Controller Lecture #1

FPGA Laboratory Assignment 4. Due Date: 06/11/2012

HI-MORE CD-EM1 CONTROL SYSTEM OPERATIONAL MANUAL. (Rev B2, June 2004) SPI & EUROMAP (WITH 24-WIRE INTERFACE CABLE) FOR

Motif and the Modular Synthesis Plug-in System PLG150-PF Professional Piano Plug-in Board. A Getting Started Guide

Concept of ELFi Educational program. Android + LEGO

dbtechnologies QUICK REFERENCE

of of Re:connect M 203 Pioneer Interface Dominating Entertainment. Revox of Switzerland. E 2.03

You will be first asked to demonstrate regular operation with default values. You will be asked to reprogram your time values and continue operation

IJMIE Volume 2, Issue 3 ISSN:

RADview-PC/TDM. Network Management System for TDM Applications Megaplex RAD Data Communications Publication No.

User Guide & Reference Manual

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District UNIT-III SEQUENTIAL CIRCUITS

Lab 2, Analysis and Design of PID

Syrah. Flux All 1rights reserved

Lab #10 Hexadecimal-to-Seven-Segment Decoder, 4-bit Adder-Subtractor and Shift Register. Fall 2017

GK/GN0658. Guidance on Lineside Signal Aspect and Indication Requirements. Rail Industry Guidance Note for GK/RT0058

Security Challenges in the Internet of Things. Dr. Sigrid Schefer-Wenzl

ITU-T Y Functional framework and capabilities of the Internet of things

M-16DX 16-Channel Digital Mixer

17.2 Setting the slow speed Important advice on ABC Push-pull (shuttle) train control Push-pull operation without

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

ALGORHYTHM. User Manual. Version 1.0

of Loewe E 2.10_m1 1

Re:connect M 203. RS232 Interface Revox. Dominating Entertainment. Revox of Switzerland. E 2.03

4. Formal Equivalence Checking

Review Process - How to review

Type-2 Fuzzy Logic Sensor Fusion for Fire Detection Robots

6.034 Notes: Section 4.1

Copyright is owned by the Author of the thesis. Permission is given for a copy to be downloaded by an individual for the purpose of research and

administration access control A security feature that determines who can edit the configuration settings for a given Transmitter.

QUESTION: ANSWER TO THE QUESTION:

How to Set Up a DX8 Transmitter for the Blade 350 QX3

FPGA Development for Radar, Radio-Astronomy and Communications

HCS-4100/20 Series Application Software

SignalTap Plus System Analyzer

Environmental Conditions, page 2-1 Site-Specific Conditions, page 2-3 Physical Interfaces (I/O Ports), page 2-4 Internal LEDs, page 2-8

Shifty Manual. Shifty. Voice Allocator Hocketing Controller Analog Shift Register Sequential/Manual Switch. Manual Revision:

LUT Optimization for Memory Based Computation using Modified OMS Technique

EE178 Spring 2018 Lecture Module 5. Eric Crabill

Function Manual SIMATIC HMI TP900. Operator Panel.

Device Management Requirements

Previous Lecture Sequential Circuits. Slide Summary of contents covered in this lecture. (Refer Slide Time: 01:55)

80W SPOT MOVING HEAD CYCLONE-80 USER GUIDE April 2014 version

SPRING 4 FOR DEVELOPING ENTERPRISE APPLICATIONS: AN END-TO-END APPROACH BY HENRY H. LIU


Cable Testing Basic guide to cable testing for newly qualified SMTH staff or trainees.

For an alphabet, we can make do with just { s, 0, 1 }, in which for typographic simplicity, s stands for the blank space.

Media Tube HO ActionPad Configuration Manual V0.2 User Version

Signal Processing. Case Study - 3. It s Too Loud. Hardware. Sound Levels

INDE/TC 455: User Interface Design. Module 5.4 Phase 4 Task Analysis, System Maps, & Screen Designs

Vtronix Incorporated. Simon Fraser University Burnaby, BC V5A 1S6 April 19, 1999

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 9: Greedy

1 x 10 Component Video with Stereo and Digital Audio Distribution Amplifier over CAT5/6 compatible with AT-COMP300RL AT-COMP10SS

How to find out information about the report

ERTMS line certification using mobile diagnostic solutions. Vito Caliandro Product Line Manager, Signalling Solutions

Operating instructions V 514 / X-QAM quad

Protégé and the Kasimir decision-support system

Lecture 3: Nondeterministic Computation

The Micropython Microcontroller

The comparison of actual system with expected system is done with the help of control mechanism. False True

Spectra Flood Q40. Exterior Fixture User Manual. Order code: LEDJ Version LEDJ284N - 15 Version

Section 6.8 Synthesis of Sequential Logic Page 1 of 8

DIGITAL SATELLITE MODULATOR DSM-T1. [English] OPERATION MANUAL 1st Edition Serial No and Higher

Journal of Japan Academy of Midwifery Instructions for Authors submitting English manuscripts

R H Y T H M G E N E R A T O R. User Guide. Version 1.3.0

C - Smoother Line Following

DVB HD T/C/S2. Guide

Fiber Optic Testing. The FOA Reference for Fiber Optics Fiber Optic Testing. Rev. 1/31/17 Page 1 of 12

Transcription:

Revision of Jess Programming Expert Systems with Jess CS3019, Knowledge-Based Systems Lecture 21

What have we learned? Questions: What is a Knowledge-Based System or Expert System? What are the two main components of a Knowledge-based System? What is a Knowledge base? How do rules of a knowledge base influence each other during their execution? How does forward chaining work?

Knowledge-Based Systems What is a KB-System: A software system that uses inference to draw conclusions from a symbolic representation of knowledge The knowledge represented is central Also called an Expert System Knowledge Base Inference Engine Knowledge + Inference = Knowledge-based System Martin J. Kollingbaum, CS3019, University of Aberdeen 3

Observations IF LHS ANTECENT then RHS CONSEQUENT ( defrule R1 (A => (assert (B R1: If A is in Working Memory then assert B to Working Memory Rules fire when their antecedents / preconditions are true (satisfied/matched by known facts When rules fire, we gain additional knowledge the consequents of the rules may assert new facts that become part of our (working memory When rules fire, they may create a situation where other rules can fire as well More than one rule may be ready to fire, because their antecedents are true (we may have to choose which one fires first This form of inference is called Forward Chaining Martin J. Kollingbaum, CS3019, University of Aberdeen 4

The Jess Language A first little Jess program: Hello World (printout t "Hello, world!" crlf A more complicated program: define rules (defrule traffic-light-red (light red => (printout t "Stop" crlf (defrule traffic-light-green (light green => (printout t Go" crlf IF (light red then (printout t "Stop" crlf then IF (light green (printout t Go" crlf

The Jess Language Find material on the course web site: http://www.csd.abdn.ac.uk/~mkolling/teaching/cs30 19/information Web sites http://www.jessrules.com/ Tutorials http://www.cs.rochester.edu/~brown/242/docs/jesst utorial.html http://www.ida.liu.se/~her/jesstab/tutorial07/jesstab Tutorial.pdf

Executing Jess Expert Systems Questions: Jess maintains a Working Memory and an Agenda. How do they influence and determine the execution of Jess programs? What determines the sequence of actions taking place when Jess is executing a rule base?

Jess Execution Revisited Match? assert fact2 fact1 fact2 fact3 LHS LHS R1 R2 RHS RHS R1 R2 run factn Factlist Working Memory Agenda How can we influence the ordering of rule activations on the Agenda?

Rule Activation and Execution Rule Activation The Agenda is populated with activated rules due to assertion of facts into Working Memory Rules are deactivated and removed from the agenda, if the matching facts are removed from Working Memory Rule Execution (Firing: A rule fires, if Jess executes its RHS actions Sequence of actions determined by Agenda An action can be: new assertions of facts, removal / modification of facts, etc. Important: the Agenda can change during execution!! Observation: The content of the Agenda can be compared to a program that is executed (but this program can change during execution Martin J. Kollingbaum, CS3019, University of Aberdeen 9

Monotonic Inference What is monotonic inference? Knowledge only increases: we add facts to working memory, but never remove (retract them This is exactly what we have been doing so far Martin Kollingbaum CS3010, Lecture 08

Non-monotonic Inference Inference does not just mean new facts asserted by rules Non-monotonic inference we also remove ( retract facts that were asserted previously The RHS of a rule allows us to Assert new facts Retract facts Modify facts This allows us to model a changing world, for example exploring different options in search of an optimal solution: A robot moving blocks around and/or stacking them Putting goods into bags (finding the best combination per bag Martin Kollingbaum CS3010, Lecture 08

Flight Advisor Write an expert system that advises you on flights Our question Can we reach a particular destination from a start city? We have: Knowledge about routes from-to cities My travel plans from a start city to a destination We have to consider: From our start to our destination, there may be intermediate cities on our route. Therefore: We have to check a which intermediate cities are reachable from our start city, b which intermediate cities are reachable from these found intermediate cities, and c whether our destination is reachable from at least one of these intermediate cities

Flight Advisor What is the Output? The expert system should produce the following output: City <destination-city> is reachable from <start-city> What is the Input? Routing information / a database of pre-specified routes You can fly from Aberdeen to Heathrow, Gatwick, Luton, Amsterdam and Paris. You can fly from Heathrow to Paris, Berlin, Amsterdam and Rome. You can fly from Gatwick to Houston and Delhi. You can fly from Luton to Toulouse. You can fly from Amsterdam to Paris, Berlin and Moscow. Your question: For example: Can I fly from Aberdeen to Houston

a Intermediate city Flight Advisor b Start city Intermediate city Intermediate city Destination Intermediate city Intermediate city Intermediate city c Our expert system has to test whether a journey can be created from the start city to a destination city We have information about direct connections between cities (our route database, but not indirect connections We have to create rules that try to put together a journey, consisting of a chain of these connections to prove that a destination city can be reached from a start city We have to create new facts that record journey legs Let s create facts that represent all outgoing journey legs from our start city to another city as defined by our route database Let s create facts that represent all outgoing journey legs from any of these found cities Let s test whether any of the found cities is our destination

Flight Advisor Model data structures create deftemplate specifications for each of the data items we want to record in working memory Information about routes: (deftemplate route-database (slot from (slot to Our question (deftemplate my-travel (slot start (slot destination

Flight Advisor Data structures for testing whether a journey is possible Record journey legs (deftemplate reachable (slot from (slot to a Intermediate city b Start city Intermediate city Intermediate city Destination Intermediate city Intermediate city Intermediate city c

Flight Advisor Rule 1: create all journey legs for cities reachable from our start city (deftemplate route (slot from (slot to (deftemplate my-travel (slot start (slot destination (deftemplate reachable (slot from (slot to (defrule from-start (my-travel (start?start (route (from?start (to?intermediate-location => (assert (reachable (from?start(to?intermediate-location How many activations to we get for this rule?

Flight Advisor Activations for rule from-start Our database of routes: (deffacts routes (route (from Aberdeen (to Heathrow (route (from Aberdeen (to Gatwick (route (from Aberdeen (to Luton (route (from Aberdeen (to Amsterdam (route (from Aberdeen (to Paris (route (from Heathrow (to Paris (route (from Heathrow (to Berlin (route (from Heathrow (to Amsterdam (route (from Heathrow (to Rome (route (from Gatwick (to Houston (route (from Gatwick (to Delhi (route (from Luton (to Toulouse (route (from Amsterdam (to Paris (route (from Amsterdam (to Berlin (route (from Amsterdam (to Moscow (route (from Delhi (to Chennai Our question: (assert (my-travel (start Aberdeen (destination Chennai We get 5 activations of rule from-start and, therefore, 5 new reachable facts recording possible journey legs: [Activation: MAIN::from-start f-17, f-5 ; time=18 ; totaltime=24 ; salience=0] [Activation: MAIN::from-start f-17, f-4 ; time=18 ; totaltime=23 ; salience=0] [Activation: MAIN::from-start f-17, f-3 ; time=18 ; totaltime=22 ; salience=0] [Activation: MAIN::from-start f-17, f-2 ; time=18 ; totaltime=21 ; salience=0] [Activation: MAIN::from-start f-17, f-1 ; time=18 ; totaltime=20 ; salience=0]

Flight Advisor Rule 2: create all journey legs for new cities reachable from currently reachable cities (deftemplate route (slot from (slot to (deftemplate my-travel (slot start (slot destination (deftemplate reachable (slot from (slot to (defrule to-intermediate (reachable (from?start (to?intermediate-location1 (route (from?intermediate-location1 (to?intermediate-location2 => (assert (reachable (from?intermediate-location1 (to?intermediate-location2 We use our new knowledge and our route information

Flight Advisor Rule 3: test whether one of the newly created journey legs contains our destination city (deftemplate route (slot from (slot to (deftemplate my-travel (slot start (slot destination (deftemplate reachable (slot from (slot to (defrule to-destination (my-travel (start?start (destination?destination (reachable (from?intermediate-location (to?destination => (printout t "You can fly from "?start " to "?destination crlf We test whether our intermediate knowledge contains our destination city

Flight Advisor Try to run the flight advisor in single step to see how rule activation and fact assertion takes place: (reset (agenda (facts (run 1 (agenda (facts (run 1 (agenda (facts (run 1 (agenda (facts (run 1 (agenda (facts (run 1 (agenda (facts (run 1 (agen......... Jess, the Rule Engine for the Java Platform Copyright (C 2008 Sandia Corporation Jess Version 7.1p2 11/5/2008 This copy of Jess will expire in 305 day(s. [Activation: MAIN::from-start f-17, f-5 ; time=18 ; totaltime=24 ; salience=0] [Activation: MAIN::from-start f-17, f-4 ; time=18 ; totaltime=23 ; salience=0] [Activation: MAIN::from-start f-17, f-3 ; time=18 ; totaltime=22 ; salience=0] [Activation: MAIN::from-start f-17, f-2 ; time=18 ; totaltime=21 ; salience=0] [Activation: MAIN::from-start f-17, f-1 ; time=18 ; totaltime=20 ; salience=0] For a total of 5 activations in module MAIN. f-0 (MAIN::initial-fact f-1 (MAIN::route (from Aberdeen (to Heathrow f-2 (MAIN::route (from Aberdeen (to Gatwick f-3 (MAIN::route (from Aberdeen (to Luton f-4 (MAIN::route (from Aberdeen (to Amsterdam f-5 (MAIN::route (from Aberdeen (to Paris f-6 (MAIN::route (from Heathrow (to Paris f-7 (MAIN::route (from Heathrow (to Berlin f-8 (MAIN::route (from Heathrow (to Amsterdam f-9 (MAIN::route (from Heathrow (to Rome f-10 (MAIN::route (from Gatwick (to Houston f-11 (MAIN::.........

Flight Advisor Different Conflict Resultion Strategies for Agenda Try out (set-strategy depth

Pattern Matching and Variable Binding at the LHS of a Rule (deftemplate Book (slot hasname(slot hasauthor (defrule test-books (Book (hasname?name1(hasauthor?author1 (Book (hasname?name2(hasauthor?author2 (test (neq?name1?name2 (test (eq?author1 author2????? =>... We want to test whether two books have the same author

Remarks for Assessment Pattern Matching and Variable Binding at the LHS of a Rule Why not simply use one?author variable?? (deftemplate Book (slot hasname(slot hasauthor (defrule test-books (Book (hasname?name1(hasauthor?author (Book (hasname?name2(hasauthor?author (test (neq?name1?name2 =>...

Remarks for Assessment Pattern Matching and Variable Binding at the LHS of a Rule Use constraint instead of test (deftemplate Book (slot hasname(slot hasauthor (defrule test-books (Book (hasname?name1(hasauthor?author (Book (hasname?name2 & ~?name1(hasauthor?author =>...

Pattern Matching Problems Pattern Matching with Wildcards: Given the following fact in WM: (data red blue green yellow pink Let s assume that a rule has the following pattern (conditional element as its LHS: (data $??x $? Describe whether there is any match with the fact in WM and what values are bound to the variable?x: This pattern matches the fact 5 times with the following bindings» 1.?x = red» 2.?x = blue» 3.?x = green» 4.?x = yellow» 5.?x = pink

Pattern Matching with Constraints Problems Using constraints over variables Given the following fact in WM: (data red blue green yellow pink Let s assume that a rule has the following pattern (conditional element as its LHS: (data $??x & :(neq?x yellow Describe whether there is any match with the fact in WM and what values are bound to the variable?x: This pattern matches the fact 1 times with the following bindings» 1.?x = pink

Further Exercises 7. The following deftemplate is used to describe an individual: (deftemplate person (slot name (slot eye-colour (slot hair-colour (slot nationality Suppose that we represent the information about individuals in a group as deftemplate facts. Write three rules which will identify: (i Anyone in the group with blue or green eyes who has brown hair and who is from France. (ii Anyone in the group who does not have blue eyes or black hair and does not have the same colour hair and eyes. (iii Two people from the group: the first has brown or blue eyes, does not have blond hair and is German; the second has green eyes and the same hair colour as the first person; the second person's eyes may be brown if the first person's hair is brown.

Manipulating Lists Problem Manipulating Lists, deffunction You have the following list manipulation functions (length$ <item list> (create$ <item list> (nth$ <number> <item list> (first$ <item list> (rest$ <item list Let s assume, we have the following fact representing a list of items: (input red blue green yellow orange pink Create a deffunction that takes the input list and produces an output list that contains these elements in reverse order

Manipulating Lists Problem Manipulating Lists, using deffunction - Solution (deffunction reverse ($?input (bind?output (create$ output (bind?i (- (length$?input 1 (while (>?i 0 (bind?output (create$?output (nth$?i?input (bind?i (-?i 1 return?output

Controlling Execution of Jess How can we influence the ordering of rule activations on the agenda? How does salience order activations on the agenda How does Depth order activations on the agenda How does Breadth order activations on the agenda

Backward Chaining Backward Chaining How does Backward Chaining work Backward Chaining tries to proof that a given hypothesis or goal is true by chaining backwards through rules where, for a rule that matches our goal with its consequent, we have to proof sub-goals that match the antecedents of this rule How does Jess implement backward chaining

Example (do-backward-chaining price (defrule price-check (do-price-check?name (price?name?price => (printout t Price of?name is?price crlf Declare your fact for backward chaining Jess asserts a fact with prefix need- (need-price?name?price (defrule query-database (need-price?name? => (assert (price?name (querydb?name We can write rules that react to these facts We assume to have implemented a function querydb.

Rete Question How does the Rete algorithm work and how does it achieves efficiency Rete creates a network of tests for facts in WM Efficiency is achieved by (a storing intermediate matching results within the Rete network and (b by utilising similarities between the LHSs of rules that allow a sharing of parts of the Rete network between rules What are the main elements of a Rete network

Handling OR at the LHS Question How does Jess handle an OR conditional element as the LHS of a rule? It creates a separate subrule for each part of the OR conditional element What is the difference between adding a NOT conditional element as the first element to a LHS of a rule, compared to constructing a LHS, where the NOT conditional element is not the first element Explain, maybe using a simple example, how Jess handles the two cases

Handling OR A rule containing an OR conditional element at its LHS with n patterns is equivalent to n rules with a LHS containing one of these patterns: Jess creates subrules for each pattern in an OR conditional element (defrule r1 (or (myfirst (a?x (mysecond (d?x(e?y (mythird (f?y => (printout t "r1: x = "?x crlf (defrule r1 (myfirst (a?x => (printout t "r1: x = "?x crlf (defrule r1&1 (mysecond (d?x(e?y => (printout t "r1: x = "?x crlf (defrule r1&2 (mythird (f?y => (printout t "r1: x = "?x crlf

Careful with negation: (defrule r1 (myfirst (a?x (not(mysecond (d?x => (printout t "r1: x = "?x crlf Negation (defrule r2 (not(mysecond (d?x (myfirst (a?x => (printout t "r2: x = "?x crlf A NOT conditional element tests the absence of a fact Rule r1: the absence of all those facts (mysecond (d?x is tested where?x has a specific value Rule r2: the absence of any fact (mysecond (d?x is tested if one is present, the rule will not be activated

Scope of Variables and Negation Problem Given the following defrule (scope, negation, variables on the RHS (defrule rule-1b (or (myfirst (a?x(b?x(c yellow (mysecond (d?y => (printout t x="?x crlf (assert (mythird (f?x What is wrong with this definition?

Important Jess Language Constructs Wildcards http://www.jessrules.com/jess/docs/71/rules.html Jess> (defrule match-whole-list (grocery-list $?list => (printout t "I need to buy "?list crlf TRUE Jess> (assert (grocery-list eggs milk bacon <Fact-0> Jess> (run I need to buy (eggs milk bacon 1 Jess> (defrule match-list-with-bacon (grocery-list $? bacon $? => (printout t "Yes, bacon is on the list" crlf TRUE Jess> (assert (grocery-list eggs milk bacon <Fact-0> Jess> (run Yes, bacon is on the list 1

Important Jess Language Constructs Templates (deftemplate Rules (defrule Facts (deffacts Jess Functions (deffunction http://www.jessrules.com/jess/docs/71/deffunctions. html

External Material Web sites http://www.jessrules.com/ Tutorials http://www.cs.rochester.edu/~brown/242/docs/j esstutorial.html http://www.ida.liu.se/~her/jesstab/tutorial07/jes stabtutorial.pdf

Remarks for Assessment Instance Query Functions in JessTab (find-all-instances <instance-set-template> <query> (find-instance <instance-set-template> <query> (any-instancep <instance-set-template> <query> (do-for-instance <instance-set-template> <query> <action>* (do-for-all-instances <instance-set-template> <query> <action>* (delayed-do-for-all-instances <instance-set-template> <query> <action>* (deffunction count-all-instances (?bookobject Counting all Purchases of a particular book" (bind?count 0 (do-for-all-instances (?purchase http://www.cs4021/bookstore.owl#purchase (eq (slot-get?purchase http://www.cs4021/bookstore.owl#hasbook?bookobject (bind?count (+?count 1 return?count

Further Exercises If WM contains the following fact: (colour red green blue white say for each of the following condition elements whether it will match with the fact and if it does, the values bound to any variables in the condition elements. (i (colour??x $? (ii (colour $? green? (iii (colour $??x?y&:(neq?y green white (iv (colour red $?x?

Exercise 3 Gadgets Diagnose faults and errors Write an expert system that will test whether you can use your TV and/or your video equipment, based on whether these gadgets are plugged in a switched on Characteristics All electrical gadgets have a power switch and are either switched on or off Each gadget has a power plug There are wall sockets providing electricity that are either switched on or off A power plug connects a gadget to a location, which is a wall socket Each gadget has a state it is on, if the plug is connected to a socket and the socket is switched on Input data There are two gadgets, television and video recorder There are two plugs, plug_1 (television and plug_2 (video recorder There are three sockets: socket_a (switched on, socket_b (switched off and socket_c (switched on Output The expert system should report either watch TV or watch video (if both TV and video are on, based on the current state of the overall home entertainment setup, expressed as facts Experiment with different initial input data expressing on/off situations to see what the expert system suggests

Gadgets Write deftemplate specifications to describe a gadget, plug and socket Gadget Has a Name, Power Switch and Plug Plug Has a name and socket Socket Has a name and on-off-switch Name Name Gadget Powerswitch plug Plug Socket Name Socket On-offswitch

Gadgets (deftemplate gadget (slot name (type SYMBOL (slot power-switch (type SYMBOL(allowed-values on off(default off (slot plug (type SYMBOL (deftemplate plug (slot name (slot location (type SYMBOL (type SYMBOL (deftemplate socket (slot name (type SYMBOL (slot on-off-switch (type SYMBOL(allowed-values on off(default off

Gadgets Rule If there is a gadget, which is switched on And there is a socket that is switched on And there is a plug that belongs to gadget and is plugged into socket Then Record that gadget is in state on Rule If there is a record that gadget televison is on Then Say watch television Rule If there is a record that gadget television is on and gadget video is on Then Say watch video

(defrule status (gadget (name (plug (power-switch (plug (name (location (socket (name?gadgetname?plug on?plug?socket?socket (on-off-switch on => (assert (is-on?gadgetname Gadgets (defrule watch-television (is-on television => (printout t "watch television" crlf (defrule watch-video (is-on television (is-on video => (printout t "watch video" crlf