Frame-based expert systems
5.4 Methods and demons
As we have already discussed, frames provide us with a structural and concise means of organising knowledge. However, we expect an expert system to act as an intelligent assistant – we require it not only to store the knowledge but also to validate and manipulate this knowledge. To add actions to our frames, we need methods and demons.
What are methods and demons?
A method is a procedure associated with a frame attribute that is executed whenever requested (Durkin, 1994). In Level5 Object, for example, a method is represented by a series of commands similar to a macro in a spreadsheet program. We write a method for a specific attribute to determine the attribute’s value or execute a series of actions when the attribute’s value changes.
Most frame-based expert systems use two types of methods: WHEN CHANGED and WHEN NEEDED.
In general, a demonhas an IF-THEN structure. It is executed whenever an attribute in the demon’s IF statement changes its value. In this sense, demons and methods are very similar, and the two terms are often used as synonyms. However, methods are more appropriate if we need to write complex procedures. Demons, on the other hand, are usually limited to IF-THEN statements.
Let us now examine a WHEN CHANGED method. A WHEN CHANGED method is executed immediately when the value of its attribute changes. To understand how WHEN CHANGED methods work, we consider a simple problem adapted from Sterling and Shapiro (1994). We will use the expert system shell Level5 Object, which offers features commonly found in most frame-based expert systems and object-oriented programming languages.
The expert system is required to assist a loan officer in evaluating credit requests from small business ventures. A credit request is to be classified into one of three categories, ‘Give credit’, ‘Deny credit’ or ‘Consult a superior’, based on the collateral and financial rating of the business, and the bank’s expected yield from the loan. When a loan officer provides a qualitative rating of the expected yield from the loan, the expert system compares the business collateral with the amount of credit requested, evaluates a financial rating based on a weighted sum of the business’s net worth to assets, last year’s sales growth, gross profit on sales and short-term debt to sales, and finally determines a category for the credit request.
The expert system is expected to provide details of any business venture and evaluate the credit request for the business selected by the user (a loan officer).
The input display for the request selection is shown in Figure 5.7. The data on the display change depending on which business is selected.
The classAction Data, shown in Figure 5.8, is used to control the input display. The user can move to the next, previous, first or last request in the list of requests and examine the business data. The WHEN CHANGED methods here allow us to advance through a list of requests. Note that all attributes in Figure 5.8 are declared as simple[S]. Simple attributes can assume either a value of TRUE or FALSE. Let us examine the WHEN CHANGED method attached to the attribute
Goto Next.
How does this method work?
In Level5 Object, any method begins with the reserved words WHEN CHANGED or WHEN NEEDED, which are followed by the reserved word BEGIN and a series of commands to be executed. The reserved word END completes a method. To refer to a particular attribute in a method, we must specify the class name as well as the attribute name. The syntax is:
<attribute name> OF <class name>
For example, the statementGoto Next OF Action Datarefers to the attributeGoto Nextof the classAction Data.
TheNext pushbutton on the input display is attached to the attributeGoto Nextof the classAction Data. When we select this pushbutton at run time, the attribute Goto Next receives a value of TRUE, causing the WHEN CHANGED method attached to it to execute. The method’s first command assigns the Figure 5.7 Input display for the request selection
143 METHODS AND DEMONS
number of the currently selected instance of the class Requestto the attribute
Current Request Number, which is used as a reference point. The FIND command uses the number stored inCurrent Request Numberto determine the next request in the list. The LIMIT 1 command tells Level5 Object to find the first instance that matches the search condition. The WHERE clause
WHERE Request Number OF Request > Current Request Number
locates the first instance of the class Requestwhose number is greater than the value of Current Request Number. The request list is maintained in increasing order to ensure that the proper instance is retrieved. If, for example, the current instance number is 6, then the FIND command will retrieve the instance with the number 7.
Let us now consider the classRequestand its instances represented in Figure 5.9. The instances,Request 1andRequest 2, have the same attributes as the class
Request, but each instance holds specific values for these attributes. To show the attribute values on the input display, we have to create value-boxes (display items that show data) and then attach these value-boxes to the appropriate attributes. When we run the application, the value-boxes show the attribute Figure 5.8 The classAction Dataand WHEN CHANGED methods
Figure 5.9 ClassRequestand its instances
145 METHODS AND DEMONS
values of the currently selected instance of the class Request and WHEN CHANGED methods cause actions to occur.
When are WHEN NEEDED methods to be used?
In many applications, an attribute is assigned to some initial or default value. However, in some applications, a WHEN NEEDED method can be used to obtain the attribute value only when it is needed. In other words, a WHEN NEEDED method is executed when information associated with a particular attribute is needed for solving the problem, but the attribute value is undetermined. We will return to this method when we discuss rules for our credit evaluation example.