CLIPS is a type of computer language designed for writing applications called expert systems. An expert system is a program which is specifically intended to model human expertise or knowledge.
To begin forming WSD rules with the help of CLIPS , we will take a small example sentence.
In the above two sentences the word "chair" has different Hindi meanings "कुर्सी" and "अध्यक्षता करना " respectively. These two different Hindi meanings are coming due to the different POS(Part of Speech) category of the word "chair" -- noun and verb respectively. Hence the rule will be:
(defrule chair0 (declare (salience 4000)) (id-root ?id chair) ?mng (retract ?mng) (assert (id-wsd_root_mng ?id kursI)) (if ?*debug_flag* then (printout wsd_fp "(rule_name-id-wsd_root_mng chair0 " ?id " kursI )" crlf)) )
(defrule chair1 (declare (salience 4000)) (id-root ?id chair) ?mng (retract ?mng) (assert (id-wsd_root_mng ?id aXyakRawA_kara)) (if ?*debug_flag* then (printout wsd_fp "(rule_name-id-wsd_root_mng chair1 " ?id " aXyakRawA_kara)" crlf)) )
We can divide each of the above CLIPS rules into two parts -- condition part and action part. In the condition part we will give all the required conditions for pattern matching. If all the conditions are matched, then the required action is defined in the action part.
Now we will try to understand each line in the above CLIPS rules.
This line gives a unique rule id "chair0" to the given rule. For ease of identification we are adding a number after the word.
Here we are giving the saliency (priority) to the rule. Priority is controlled with the help of range of numbers.
The need of giving priority to a rule is required , for the reason , if there are multiple rules for a single word, we can set the order in which these rules will be fired by the CLIPS inference engine.
The following rule of thumb may help you to fix the saliency of a 'sense'. The 'default' sense (which is the most general sense and is usually listed as the first meaning in the dictionary) has the least number of constraints stated in the rule. The saliency of the default sense would be 'very low'. As the constraints become more and more complex and specific for a sense, the saliency goes higher. In the event of there being an extremely specific condition for a sense, the saliency would be 'very high'.
The syntax of the above statement is like "son-father Ram Dasarath". The relation is between two entities separated by a hyphen. For e.g "id-root" . The relation is between id and root . In a sentence we are assigning a serial id to each word on the basis of its position. This helps giving a unique id to each word in a sentence irrespective of its repetition. For e.g. 'The farmer took two months to produce the grains but he took much longer to find a market for his produce'. The word 'produce' has been used twice but for each occurrence of the word it has to be assigned a distinct id.
This fact is a dummy fact to control the firing of rules . If the given rule is matched then in the action part we will retract(remove) this fact. Hence it will check the inference engine from firing further rules.
For e.g , Given above are two rules for chair. If first rule "chair0" is fired then this dummy fact will be retracted , hence the next rule "chair1" will never be matched.
This is like the previous fact "(id-root ?id chair)". Here the relation is "id-cat_coarse". Hence the first entity is "id" and the second entity is its coarse category.
This defines the end of the "Condition part" and start of the "action part".
As described this statement removes the fact "?mng
This statement asserts a new fact which assigns a Hindi root meaning to the word having position id as "?id", e.g., here the Hindi meaning " kursI" is assigned to the word having id "?id?
This statement is simply for debugging purpose. It prints a line to the debugging file that this meaning has been decided by this rule id. It helps in rechecking the rule , if there are number of rules for a word.
Please note that some of the statements both in the condition and action parts are constant, i.e., they never change. For example,
If you have noticed, for each opening parenthesis , we have a close one. But in the first line "(defrule chair0" , it is not closed . The closing paranthesis is at the end of the rule .