[Next] [Up] [Previous]
Next: Exercises Up: Appendix: Production Rules Previous: Appendix: Production Rules

Using a Production System in the Automated Tourist Guide

Since production rules are useful for representing human rule-based knowledge, an example related to the Automated Tourist Guide might be a What's-On Guide to London. The `action' part of some of the production rules can prompt the user for information about, for example, preferred kinds of entertainment and the area to visit. Applying the rules will deduce suitable events. To begin with the working memory must indicate that the system knows neither the type of entertainment the user might want nor the area of London:

 
 [ 		 [entertainment type unknown]

[entertainment place unknown]] -> database;

The rule find_type (which, being the first to be loaded and given the conflict resolution strategy already described, will be the first that is fired by the database) will establish what type of entertainment the tourist wishes. The only acceptable responses to the rule as given below are `cinema' and `theatre', though of course the rulebase could be enlarged and modified to allow other options, such as pubs, parks, or nightclubs:

 
rule find_type [entertainment type unknown];

vars ent_type;

[What type of entertainment would you like:

cinema or theatre?] =>>

readline() -> ent_type;

remove([entertainment type unknown]);

add([entertainment type ^^ent_type]);

endrule;

Having established the type of entertainment the tourist is seeking, the system next finds out the desired location:

 
rule find_place [entertainment place unknown];

vars place;

[Where do you want to go in the city:

centre or suburbs?] =>>

readline() -> place;

remove([entertainment place unknown]);

add([entertainment place ^^place]);

endrule;

A good place for looking for theatres in the centre of London is in the environs of Piccadilly Circus:

 
rule centre_theatre [entertainment type theatre]

[entertainment place centre];

add([location piccadilly circus]);

endrule;

Alternatively, if the tourist has indicated a wish to go to the cinema, then Leicester Square is a good place to start:

 
rule centre_cinema [entertainment type cinema]

[entertainment place centre];

add([location leicester square]);

endrule;

Whichever the city centre location, the tourist now needs to know how to get there:

 
rule suggest_centre [location ??x];

[I suggest you take the underground to ^^x

and look around] =>>

endrule;

If, on the other hand, the tourist has expressed a preference for the suburbs (irrespective of whether or not cinema or theatre has been asked for), then the following rule is fired:

 
rule suggest_suburbs [entertainment place suburbs];

[I suggest you look at the entertainments

section of the London Standard] =>>

endrule;

The production system can then be run by calling the procedure run:

run();
What type of entertainment would you like : cinema or theatre ?
? cinema
Where do you want to go in the city : centre or suburbs ?
? centre
I suggest you take the underground to leicester square and look around

The production system can then be incorporated into the Automated Tourist Guide. The system should be initially triggered by a tourist's query, such as, ``What entertainments are there in London?'' The answer procedure needs to be altered to match the query and run the production system. It should look something like this:

 

define answer(query) -> response;

  if query matches [what == entertainments ==] then

    [[entertainment type unknown]

     [entertainment place unknown]] -> database;

    run();

    flush([entertainment ==]);

    [Consultation finished] -> response;

   ...

  else

       [i cannot answer that] -> response;

  endif;

enddefine;

Now, whenever the user asks an appropriate question, the database will be loaded with the initial content of working memory, and the production system will be set in action. Since the system relies on the POP-11 database, which is already full of facts about London, then, to avoid confusion, all the items added by the production system begin with [entertainment ...]. The flush command acts like remove but remove all the items in the database that match the pattern, in this case all the items added by the production system.


[Next] [Up] [Previous]
Next: Exercises Up: Appendix: Production Rules Previous: Appendix: Production Rules

Cogsweb Project: luisgh@cogs.susx.ac.uk