0% found this document useful (0 votes)
66 views21 pages

Rule Based Programming: 3rd Year, 2nd Semester

This document provides information about a Rule Based Programming course, including an overview of the course content and schedule. The course covers declarative programming and expert systems, with a focus on CLIPS for rule-based programming. It will cover the RETE algorithm, forward and backward chaining, and introduce other rule languages like PROLOG, OPS5, and DROOLS. Evaluation will include exams, lab exercises, and a project to be completed over weeks 8-13.

Uploaded by

Dany Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views21 pages

Rule Based Programming: 3rd Year, 2nd Semester

This document provides information about a Rule Based Programming course, including an overview of the course content and schedule. The course covers declarative programming and expert systems, with a focus on CLIPS for rule-based programming. It will cover the RETE algorithm, forward and backward chaining, and introduce other rule languages like PROLOG, OPS5, and DROOLS. Evaluation will include exams, lab exercises, and a project to be completed over weeks 8-13.

Uploaded by

Dany Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Rule Based Programming

3rd year, 2nd semester

Declarative Programming
Expert Systems
CLIPS
Course information
Course timetable: https://profs.info.uaic.ro/~orar/discipline/orar_pbr.html

Course webpage: https://profs.info.uaic.ro/~ipistol/PBR

Course syllabus: https://drive.google.com/file/d/1uCsW6SQ5xUvosKtl_fX13sMjiZ-yK6JW/view

Evaluation:

● Written exam at the end of the semester (E - maximum 40). The written exam is mandatory.
● Lab exercises (L - 7 * 4 + 6 * 2, maximum 40).
● Project work (PP - weeks 8-13, maximum 40).
● Grades are set using the formula ROUND (L + PP + E)/10. To pass you need L + PP + E at least 50.
Programming paradigms: imperative
● You tell the computer exactly what to do.
● Easy to debug.
● Easy to implement - it needs the bare
minimum of data.
● Fast execution (program as good as the
programmer).
● Hard to adapt to changing goals.

Enter the building, climb to the first floor using


the stairs to your left, turn left and go past the
hall, enter the second door to your left in the
next corridor.
Programming paradigms: declarative
● You tell the computer exactly what to do.
● Hard to debug.
● Hard to implement - it needs as much data
as possible.
● Slow execution (limited control by a good
programmer).
● It can solve almost anything you can
describe.

Go to C309.
Expert systems
Human experts
● Expensive
● Hard to access
● Adaptable

Expert systems
● Much cheaper
● Very easy access
● Little adaptability
● Still require human experts to be
built
What is knowledge?

Intelligence applied to
information produces knowledge.

Knowledge supplements
intelligence.

Intelligence is asking the right


question, knowledge is having the
right answer.
Expert knowledge
is next to
A B

● A and B are labels (data) used


● IF A and B THEN A ‘is next to’ B
● IF A ‘is next to’ something THEN something = B

All formal knowledge can be represented like this.

Is an imperative language suitable to implement an expert system?


Rule Based Programming

Inference
Knowledge Base Inference Rules
Engine

Knowledge base: Set of facts known to be true.


Inference rules: Set of IF-THEN rules applied on facts or patterns.
Inference engine: An engine capable of inferring (adding) new facts from the rules and facts
available.
C-Language Integrated Production System
● Originally built by NASA from 1985 (original name NASA's AI Language).
● Original purpose: diagnosis software for propulsion system.
● Since 1996 is an open domain software maintained and developed by volunteers.
● Latest version: 6.4 (september 2018).
● Official webpage: http://www.clipsrules.net/.
● Many libraries available for other languages
accepting CLIPS input: Jess and CLIPSJni(JAVA),
PyCLIPS (Python), CLIPS.NET (.NET)
Writing CLIPS code
Everything is a parenthesised prefix (Polish form) notation.

(field1 field2 field3 ….) unlimited number of fields

5 + 2 + 6 * (7 - 2) is written as (+ 5 2 (* 6 (- 7 2)))

Easier to parse: each parenthesis is a call to a function identified by the first field.
CLIPS: Knowledge Base (I)
Contains facts. A fact can be anything (as long as it doesn’t contain & or | or ~ and the first
field starts with a char - not a number).

Creating a fact:
(assert (minge))
(assert (lista 1 2 3 4 5))

Creating multiple facts:


(deffacts fapte (minge rosie) (minge mare))
CLIPS: Knowledge Base (II)
Facts are added to the workspace KB. To view current KB:
(facts)

(facts)
f-0 (initial-fact)
f-1 (minge rosie)
f-2 (minge mare)
For a total of 3 facts.

Each fact is assigned (by CLIPS) an unique identifier. All future references to that fact can
only be done by referencing that identifier.
CLIPS: Knowledge Base (III)
Deleting a fact:
(retract 1)

(facts)
f-0 (initial-fact)
f-2 (minge mare)
For a total of 2 facts.

Each identifier is unique for the current workspace.


CLIPS: Knowledge Base (IV)
(assert (minge rosie))

(facts)
f-0 (initial-fact)
f-2 (minge mare)
f-3 (minge rosie)
For a total of 3 facts.

For CLIPS, a fact is a pair (id, content). Once retracted, no other fact with the same id can
ever exist. This is the first important CLIPS tip. Use it in many situations to control the
order of rules, for example by using a fact as a flag/switch.
CLIPS: Inference Rules (I)
Name of the rule. Has to be unique and provided
(defrule name by the user!
(minge rosie)
(minge mare) } Left side: conditions (patterns) to be matched
on the KB
=>
(assert (minge frumoasa)) Right side: actions to be taken affecting the KB
)
CLIPS: Inference Rules (II)
(rules)
name
For a total of 1 defrule.

(run) - start the inference engine

(facts)
f-0 (initial-fact)
f-1 (minge rosie)
f-2 (minge mare)
f-3 (minge frumoasa)
For a total of 4 facts.
CLIPS: Interacting with the user (I)
(printout t "message" crlf))
t = terminal crlf = carriage return line feed
(defrule read_fact
(minge mare)
=>
(assert (minge (read))
)
CLIPS: Interacting with the user (II)
● (read)gets the first field entered at the terminal
(assert (lista (read))
one two three CR will get (lista one)

● To read all fields, use (readline) - will merge all fields before enter into a single
field! (lista “one two three”)

● To split the input into multiple fields use explode$ :


(assert (lista (explode$ (readline))))
will get (lista one two three)
CLIPS: writing and running code
Step 1: Edit a file with your preferred editor (parenthesis highlight recommended). Save file
as name.clp
Step 2: In CLIPS, (clear) the workspace to avoid interference from other facts/rules.
Step 3: (load “name.clp”) , if all is fine T or TRUE will be the last message
displayed. This step just checks if CLIPS can understand everything in that file.
Step 4: (reset) CLIPS. This returns the workspace to a state in which all commands
from all loaded files are executed.
Step 5: (run) the inference engine.

Highly recommended: keep the facts window opened at all times.


PBR course overview
Course 1,2 and 3: CLIPS, agenda, the RETE algorithm, open and closed worlds, forward
and backward chaining

Course 4,5 and 6: PROLOG, logic programming, cuts, recursive procedures

Course 7: Project overview and specifications

Course 8: CLIPS Object Oriented Programming

Course 9: Fuzzy Logic and FUZZYCLIPS


PBR course overview
Course 10: Expert systems: MYCIN, Prospector, Dendral, Mass/Charge, XCON, PXDES,
CADET.

Course 11: OPS5 and RC++

Course 12: Constraint Handling Rules

Course 13: DROOLS and EPSILON

You might also like