Manual for Clips is available at Clips homepage
An intelligent computer program that uses knowledge and inference procedures to solve problems that are difficult enough to require significant human expertise for their solutions.
–Prof. Edward Feigenbauma, Stanford University
In particular, expers systems can be compared to a program that simulates work of an human expert in decision making tasks. An Expert is a person who has very specialist knowledge, unavailable for majority of people. An Expert can solve a problem that most of people would not be able to solve, or would not do it effectively enough.
Experts systems using Clips can be created in two ways:
An exerise is aimed at creating simple calculator for creditworthiness. Rules presented below are fictional
Creditworthiness will be defined as an ability of a borrower to pay current debt in a timely manner.
clips
(exit)
(load filename) (reset)
Command (reset) loads facts defined with deffacts (See sectopnFacts).
(clear)
(run)
(help)
(deffacts my_facts "comment" (name jan) (surname kowalski) (age 24))
To add defined facts the (reset)) comman has to be invoked. Attention Facts within deffacts are not connected with each other in any way. In an example from above to a fact base three independent facts would be added: (name jan), (surname kowalski) and (age 24).
(assert (age 23))
The assert command would add a fact immediatelly, howewer after invoking (reset) command, only facts defined with deffact would remain and those added with assert will be lost.
(deffacts myFacts (year 2010) (person jan kowalski 45) (informatyka stosowana))
(facts)
Using deffacts, define facts that would represent persoal data such as name, surname, age, salary.
Load created file into the Clips, and list all files.
(defrule rule-1 "Comment" (name jan) => (printout t "Hello World!" crlf))
(defrule rule-1 "Comment" (name ?value) => (printout t "Hello World!" ?value crlf))
(defrule rule-1 "Comment" (name ?imie) (age ?age) (test (< ?age 18)) => (printout t "Hi " ?imie ". Your not supposed to be here!" crlf))
Define two rules that would describe weather a person can be a potential debtor. If an age of a peerson is less than 18 it can not be, if it is geater and the person's salary exceedes 1500$ - a credit can be granted.
After the inference process is run, „Credit granted” or „Credit not granted” message should be printed in the screen.
A fat can contain any number of elements. Both following facts are valid:
(assert (name szymon)) (assert (person with a name szymon))
Aobove notation is not convinient for facts that sould represent more complex data.
for more complex facts, deftemplate lub defclass constructs are used:
(deftemplate person (slot name) (slot surname) (slot age))
It is possible to acces some of the slots ommiting other:
(assert (person (name jan) (surname kowalski) (age 50)) (defrule rule "" (person (age ?value)) (test (>= 18 ?value)) => (printout t "Hello!" crlf))
Define a temaplate person which would store data defined in previous exercises. Modify defined rules to work with template data.
Modules in Clips are used fro several reasons
A module is defined with a defmodule construct:
(defmodule myModule)
To define that some rule belongs to some module a:: operator is used (it is simiellar to known from C++ scope resolution operator):
(defrule myModule::rule "" => (printout t "---- Rule in myModule ----" crlf)
While defining modules it can be defined if facts added by rules/templates/classes that belongs to the module should be visible outside its scope:
(defmodule myModule (export ?ALL))
For exported data to be visible inside other module, it has to be specified which data and from which module should be imported::
(defmodule myModule (export ?ALL) (defmodule myOtherModule (import myModule ?ALL))
All data not explicetely assign to any module by defauld belongs to a MAIN module.
It is required sometimes to redefine MAIN module to export all data, so it can be imported in other modules:
(defmodule MAIN (export ?ALL))
it is possible to define order in which defined modules will be processed by an inference engine.
(defrule MAIN::startrule "" => (printout t "---- STARTING ----" crlf) (focus salutation greeting userMessage) ; inference control )
(defrule MAIN::reugla "" (osoba (wiek ?value)) (test (>= 18 ?value)) => (printout t "I'm switching from MAIN to adoult" crlf) (focus adoult))
Define three modules: PrivateCapability FinancialCapability and FinalCapability. Add facts privCap, finCap, endCap that would be set in aforementioned modules.
privCap should be calculated based on table below:
Age | Number of famili members | privCap |
---|---|---|
<0 ; 17> | ANY | 0 |
<18 ; 24> | <0; 2> | 3 |
<18 ; 24> | <3 ; 4> | 2 |
<18 ; 24> | <4 ; inf> | 0 |
<25 ; 65> | <0; 2> | 5 |
<25 ; 65> | <3 ; 4> | 3 |
<25 ; 65> | <4 ; oo> | 1 |
<66 ; 75> | <0; 2> | 4 |
<66 ; 75> | <3 ; 4> | 3 |
<66 ; 75> | <4 ; inf> | 2 |
<75 ; oo> | ANY | 0 |
finCap should be calculated based on table below:
Salary | Type of contract | Other credits | finCap |
---|---|---|---|
<0; 1000> | ANY | ANY | 0 |
<1001; 2000> | oprace | nie | 2 |
<1001; 2000> | oprace | tak | 1 |
<1001; 2000> | inne | ANY | 0 |
<2001; 6000> | oprace | nie | 4 |
<2001; 6000> | oprace | tak | 2 |
<2001; 6000> | inne | ANY | 1 |
<6001; 30000> | oprace | nie | 6 |
<6001; 30000> | oprace | tak | 4 |
<6001; 30000> | inne | ANY | 2 |
<30001; oo> | ANY | ANY | 6 |
endCap should be calculated according to the following equation:
(zdpriv*2 + zdfin*5)*1000.
Modules should be fired in following order (use focus):
To read data from the jeyboard a (read) command is used:
defrule regula "" => (printout t "Podaj swoj wiek: ") (bind ?wiek (read)) (printout t "Podaj swoje imie: ") (bind ?imie (read)) (printout t "Podaj swoje nazwisko: ") (bind ?nazwisko (read)) (assert(osoba(imie ?imie)(nazwisko ?nazwisko)(wiek ?wiek))))
Reading data from the user can be done only in RHS of the rule.
Modify program from previous exercise by providing user interface that would allow user to type his famili status, age, salary.
After that an inference process should be fired and information about the amount of credid allowd for the user printed.
Z braku lepszego miejsca tutaj studenci wpisujš komentarze natury ogólnej do tego lab.