PoiNtEr->: CLIPS {c language integrated Production system}

                             Difference between a dream and an aim. A dream requires soundless sleep, whereas an aim requires sleepless efforts.

Search This Blog

Monday, April 25, 2011

CLIPS {c language integrated Production system}


CLIPS is a public domain software tool for building expert systems.


Install CLIPS:
On Ubuntu : sudo apt-get install clips
on terminal


for Windows and MacOs:
click here
 

Facts and rules:

 At its most basic, CLIPS operates by maintaining a list of facts and a set of rules which operate on them. A fact is a piece of information such as (colour green) or (parent_of John Susan). Facts are created by asserting them onto the fact database using the assert command. Here’s an example, complete with the response from CLIPS:

    CLIPS>(assert (colour green))
The part is the response from CLIPS to say that a new fact (fact number 0) has been placed on the fact database. The (facts) command will list all current facts. Try it, and you’ll get the following:
    CLIPS>(facts) f-0 (colour green) For a total of 1 fact.
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)) CLIPS>(assert (colour red))
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.
There are two things to note here: firstly, to retract a fact you must specify a number (the fact-index), not the fact itself, and secondly, fact-indices are not reused. Once fact 0 has been retracted, the next fact asserted will have the index 2, not 0.
Facts on their own are of only limited use. The application of rules is necessary to develop a program capable of some useful function. In general, a rule is expressed in the form ‘IF something is true THEN do some action’. This kind of rule is known as a production. For this reason, rule-based expert systems are often known as production systems (CLIPS actually stands for C Language Integrated Production System). In CLIPS, a typical rule looks like this:
    (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 ‘if there is a fact (animal-is duck) on the fact database, then assert another fact, (sound-is quack), onto the fact database’. Try it. Clear the system, then type in the rule exactly as printed above. Typing (rules) will give you a list of rules (just the one, in this case) present in the system. At this point, there are no facts present. Now, type (assert (animal-is duck)). Check the fact list - there’s one fact. To trigger your rule, type (run). Although nothing appears to happen, if you check the fact list again you’ll see that there is a new fact, (sound-is quack), which has been inferred by the rule. This is the power of rule-based programming - the ability to make inferences from data, particularly as the results of one rule can be used as the pattern for another. 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 ‘IF the animal has webbed feet AND the animal has feathers THEN the animal is a duck’ (taxonomists and pedants may disagree with this rule). If you now assert the facts (animal-has webbed-feet) and (animal-has feathers) there will be two facts present. (run) the rules, and suddenly there are four. 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.
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
      (animal-is duck)
      =>
      (assert (sound-is quack))
      (printout t "it’s a duck" crlf))

 {*well i am working on Expert system Project these days so if you have any problem related to expert system just comment below*}

No comments:

Post a Comment