Note that the RHS actions also use the same syntax for the instance The change

Note that the rhs actions also use the same syntax

This preview shows page 89 - 92 out of 308 pages.

Note that the RHS actions also use the same syntax for the instance. The change is easy to implement due to the interchangeability of facts and rules in Prolog. Oops refers to fact s, expecting to find data. Foops uses the same code, but implements the relation fact as a rule, which calls getf . Following is the code that matches the premises from the LHS . It is the the same as in the previous version except that the definition of fact has been changed to reflect the new nature of each individual premise. match([], []). Building Expert Systems in Prolog 79
Image of page 89
match([Prem|Rest], [Prem/Time|InstRest]) :- mat(Prem, Time), match(Rest, InstRest). mat(N:Prem, Time) :- !, fact(Prem, Time). mat(Prem, Time) :- fact(Prem, Time). mat(Test, 0) :- test(Test). fact(Prem, Time) :- conv(Prem, Class, Name, ReqList), getf(Class, Name, ReqList, Time). conv(Class-Name with List, Class, Name, List). conv(Class-Name, Class, Name, []). The conv relation is used to allow the user to specify instances in an abbreviated form if there is no attribute value list. For example, the following rule uses an instance of the class goal where the name is the only important bit of information: rule f1: [goal - couch_first, couch - C with [position-none, length-LenC], door - D with [position-wall/W], ... The only other change which has to be made is in the implementation of the action commands which manipulate working storage. These now manipulate frinst structures instead of the pure facts as they did in Oops . They simply call the appropriate frame instance predicates. assert_ws( fact(Prem, Time) ) :- conv(Prem, Class, Name, UList), addf(Class, Name, UList). update_ws( fact(Prem, Time) ) :- conv(Prem, Class, Name, UList), uptf(Class, Name, UList). retract_ws( fact(Prem, Time) ) :- conv(Prem, Class, Name, UList), delf(Class, Name, UList). Adding Prolog to Foops Now that frames and Oops have been integrated into a new system, Foops , the next step is to integrate Prolog as well. This has already been done for the frame based system with the various demons that can be associated with frame slots. The Prolog predicates referred to in the demon slots can simply be added directly to the knowledge base. Adding Prolog to the rules is done by simply adding support for a call statement in both the test (for the LHS) and take (for the RHS) predicates. ... test(call(X)) :- call(X). ... ... take(call(X)) :- call(X). ... 80 Chapter 7 - Integration
Image of page 90
Calls to Prolog predicates can now be added on either side of a rule. The Prolog can be simple predicates performing some function right in the knowledge base, or they can initiate more complex processing, including accessing other applications. Figure 7.1 shows the major components of the Foops shell. Frames and Prolog code have been added to the knowledge base. Working storage is composed of frame instances, and the inference engine includes the frame manipulation predicates. User Interface command_loop read write Inference Engine getf go addf match delf process uptf Knowledge Base initial_data frame rule Prolog Working Storage frinst Figure 7.1 Major predicates of Foops shell 7.2 Room Configuration Now that Foops is built, let's use it to attack the room configuration problem again. Many
Image of page 91
Image of page 92

You've reached the end of your free preview.

Want to read all 308 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture