Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 33

Kingdom of Saudi Arabia

Ministry of Higher Education ‫المملكة العربية السعودية‬


Taibah University ‫وزارة التعليم العالي‬
College of Computer Science and ‫جامعة طيبة‬
Engineering ‫كلية علوم و هندسة الحاسبات‬

MSCS822 – Expert Systems and Knowledge Engineering


Applications

Lectures of Week 8:
Expert Systems Programming and Shells – Part 1
RECAP
• Defining the nature and scope of the
problem
– Rule-based ES are appropriate when the nature
of the problem is qualitative, knowledge is
explicit, and experts are available to solve the
problem effectively and provide their knowledge

• Identifying proper experts


– A proper expert should have a thorough
understanding of:
» Problem-solving knowledge
» The role of ES and decision support technology
» Good communication skills
RECAP
• Acquiring knowledge
– Knowledge engineer
An AI specialist responsible for the technical side of
developing an expert system. The knowledge
engineer works closely with the domain expert to
capture the expert’s knowledge.

– Knowledge engineering (KE)


The engineering discipline in which knowledge is
integrated into computer systems to solve complex
problems normally requiring a high level of human
expertise.
Development of ES
Selecting the building tools
General-purpose
Expert system shell
development environment
Specialized software tools designed
specifically for developing expert
software platforms or
systems. Shells often come with
tools used for developing
built-in features for knowledge
Definition a wide range of
representation, inference engines,
applications, not limited
and user interface design, which can
to expert systems
significantly speed up the
development process.

IDEs: (Eclipse, Visual


Studio)
Examples ExSys Corvid
programming languages:
Python, Java, C++.
Development of ES

Choosing an ES development tool


– Consider the cost benefits

–Consider the functionality and flexibility of the tool

–Consider the tool's compatibility with the existing


information infrastructure

–Consider the reliability of and support from the vendor


A Popular Expert System Shell
An ES Consultation with ExSys
• See it yourself…
• Go to ExSys.com
• Select from a number of interesting expert
system solutions/demonstrations
CLIPS Programming Language

• CLIPS is a multiparadigm programming


language that provides support for:
– Rule-based
– Object-oriented
– Procedural programming
• Syntactically, CLIPS resembles:
– Eclipse
– CLIPS/R2
– JESS

Expert Systems: Principles and Programming, Fourth Edition 8


CLIPS Characteristics
• CLIPS supports only forward-chaining rules.

• The OOP capabilities of CLIPS are referred to as


CLIPS Object-Oriented Language (COOL).

• The procedural language capabilities of CLIPS are


similar to languages such as:
–C
– Ada
– Pascal
– Lisp

Expert Systems: Principles and Programming, Fourth Edition 9


CLIPS Characteristics

• CLIPS is an acronym for C Language


Integrated Production System.

• CLIPS was designed using the C language at


the NASA/Johnson Space Center.

• CLIPS is portable.

Expert Systems: Principles and Programming, Fourth Edition 10


The CLIPS Programming Tool
• CLIPS is a productive development and delivery
Expert System tool which provides a complete environment
for the construction of rule and/or object based expert
systems. Created in 1985, it is widely used throughout
government, industry, and academia. Its key features are:

• Knowledge Representation: CLIPS provides a cohesive tool


for handling a wide variety of knowledge with support for
three different programming paradigms: rule-based, object-
oriented and procedural.
The CLIPS Programming Tool

• The procedural programming capabilities provided by


CLIPS are similar to capabilities found in languages such
as C++, Java, Ada, and LISP.

• Portability: CLIPS is written in C for portability and speed


and has been installed on many different Operating
systems, i.e., MS Windows, MacOS X, and Unix.
The CLIPS Programming Tool

• Fully Documented: CLIPS comes with extensive


documentation including a Reference Manual and a
User Guide.

• Low Cost: CLIPS is maintained as public domain


software.

• Version 6.31 of CLIPS is available at:

http://www.clipsrules.net/Downloads.html
Components of CLIPS
• Rule-Based Language
– Can create a fact list
– Can create a rule set
– An inference engine matches facts against rules

• Object-Oriented Language
– Can define classes
– Can create different sets of instances
– Special forms allow you to interface rules and
objects
Defining Facts
• Facts can be asserted
CLIPS> (assert (today is sunday))
<Fact-0>

• Facts can be listed


CLIPS> (facts)
f-0 (today is sunday)

• Facts can be retracted


CLIPS> (retract 0)
CLIPS> (facts)
Managing Facts
• Clearing all facts
CLIPS> (clear)
CLIPS> (facts)

• Grouping facts - typically in a file (“today.clp”)


(deffacts today
(today is sunday)
(weather is warm)
)
• After loading facts, assert with (reset)
Managing Facts
• Facts may also be retracted (removed) from the
fact database by using the retract command. As an
example, assert two facts as shown:

• CLIPS>(assert (colour green))


<Fact-0>
CLIPS>(assert (colour red))
<Fact-1>
• Then retract the first fact and display the fact list:

• CLIPS>(retract 0)
CLIPS>(facts)
f-1 (colour red)
For a total of 1 fact.
Facts
1. Relation name or Ordered fact
– symbolic field used to access the information
– often serves as identifier for the fact
– (example: (today is Sunday), (color green))
2. deffacts
– used to define groups of facts
– (example on slide 15)
3. deftemplate construct
– used to define the structure of a fact
» names and number of slots (zero or more)

Slots are symbolic fields with associated values.


Examples of deftemplate

(deftemplate person "deftemplate example"


(slot name)
(slot age)
(slot eye-color)
(slot hair-color))
Instances

An instance of a single fact is created by


following CLIPS code:
(assert (person
(name "Abdul Ahad Siddiqi")
(age 50)
(eye-color dark-brown)
(hair-color dark-brown)) )
Initial Facts

(deffacts siddiqi "some members of the Siddiqi family"


(person (name “Ali Siddiqi") (age 49)
(eye-color dark-brown) (hair-color dark-brown))
(person (name “Umar Siddiqi") (age 44)
(eye-color black) (hair-color black))
(person (name “Aisha Siddiqi") (age 35)
(eye-color brown) (hair-color black))
)
Usage of Facts
Adding facts
– (assert <fact>+)
Deleting facts
– (retract <fact-index>+)
Modifying facts
– (modify <fact-index> (<slot-name> <slot-value>
+ )
» retracts the original fact and asserts a modified fact
Inspection of facts
– (facts)
» prints the list of facts on screen
Defining Rules
• Rule has the following structure

(defrule rule-name optional-comment


optional-declaration
condition
...
condition
=>
action
...
action )
Rule Components
Rule header
– defrule keyword, name of the rule, optional
comment string
Rule antecedent (LHS)
– patterns to be matched against facts
Rule arrow
– separates antecedent and consequent
Rule consequent (RHS)
– actions to be performed when the rule fires
Example of Rules
Simple rule
(defrule birthday-siddiqi
(person (name "Abdul Ahad Siddiqi")
(age 50)
(eye-color dark-brown)
(hair-color dark-brown))
(date-today April-04-2016)
=>
(printout t "Happy Birthday, Siddiqi!") )

Note: We can modify now age at the top level


(modify 1 (age 51)) ; 1 is fact index number for

example defined on slide 19


Managing Rules
(defrule duck
(animal-is duck)
=>
(assert (sound-is quack)))

• The rule consists of three parts. The first part, (defrule duck,
simply gives the rule a unique name.

• The second part, (animal-is duck), is the pattern (the IF part)


of the rule and the last part, (assert (sound-is quack)), is the
action (the THEN part).

• In plain language, this rule means there is a fact (animal-is


duck) on the fact database, then assert another fact, (sound-
is quack), onto the fact database
Managing Rules
• Add the rule

(defrule is-it-a-duck
(animal-has webbed-feet)
(animal-has feathers)
=>
(assert (animal-is duck)))

• Then type (reset) to clear the facts (the rules will be


untouched). Note that this rule has two patterns. Both must
be satisfied for the action to be taken. This translates to the
animal has webbed feet AND the animal has feathers THEN
the animal is a duck.
Managing Rules
• If you now assert the facts (animal-has webbed-
feet) and (animal-has feathers) there will be two
facts present.
• Then (run) the rules, and there are four facts now.

• Firstly, rule is-it-a-duck has fired, asserting the


fact (animal-is duck). This fact has then triggered
rule duck, which has asserted the fact (sound-is
quack).

• Very powerful systems can be built using this


ability to chain rules.
Managing Rules
• Asserting facts is a rather unsatisfactory way of presenting
results. Type in the first rule again, this time with the multiple
actions as shown below:

(defrule duck
(declare (salience 20))
; salience in the interval [-10000, 10000] to set priority of rules
(animal-is duck)
=> (assert (sound-is quack))
(printout t "it’s a duck" crlf))

• Next time you run the rules, you'll get a message on


screen as well as the asserted quack fact.
An Example CLIPS Rule

(defrule sunday "Things to do on thursday "


(declare (salience 10))
; salience in the interval [-10000, 10000] to set the priority of rules
(today is thursday)
(weather is sunny)
=>
(assert (chore shop mall))
(assert (chore picnic seaside) ))

• So, if fact list contains conditions, add assertions


Getting the Rules Started
• The reset command creates a special fact
CLIPS> (load “today.clp”)
CLIPS> (facts)
CLIPS> (reset)
CLIPS> (facts)
f-0 (initial-fact) ...

(defrule start
(initial-fact)
=>
(printout t "hello there " crlf) )
Tracing & Recording Things
• Watch command can watch facts (and rules)
CLIPS> (watch facts)
CLIPS> (reset)
==> f-0 (initial-fact)
CLIPS> (retract 0)
<== f-0 (initial-fact)

• Contents of dialog window can be sent to file


CLIPS> (dribble-on “dribble.clp”); any file name will do
...
CLIPS> (dribble-off “dribble.clp”)
References
1. Dr. Franz J. Kurfess, CSC 481 - Knowledge-based Systems,
http://users.csc.calpoly.edu/~fkurfess/Courses/CSC-481/, 2005.

2. Giarratano JC, Riley GD. Expert Systems: Principles and Programming.


2n' edition. PWS Kent, 1992.

3. Peter Jackson, Introduction to Expert Systems, 3rd Edition, Addison-


Wesley, 1999.

4. Wan Hussain Wan Ishak, Expert Systems Course,


http://staf.uum.edu.my/hussain, UUM Malaysia, 2009.

You might also like