Classifying animals (PP)


next up previous
Next: Running the program
Up: Supplement 4
Previous: Introduction
Back: to main list of student notes

Classifying animals (PP)

This section introduces a simple animal classifier. Please start by loading the animals knowledge base. Make a printed copy of it if you want, too. You can look at it by doing showlib animals.pl from Prolog, and print it by ctcprint from VED.

The classifier is similar to the ski advisor of Supplement 1, but unlike the latter, it contains some unary (one-argument) predicates, such as gives_milk and flies. There are none with more than two arguments, but you will see some of these later, in the trading game.

A complete list of predicates follows. After each, I have stated what I intend it to mean. For example, from the description of spots below, you can see that the fact

    spots( pip, black ).
means Pip has black spots.

Notice that I have taken care to indicate what type of thing each argument refers to, and what the names used for individuals of each type are. For instance I have listed the body parts used in the second argument of has. If you write programs for yourself, it is important to make sure that you know what each predicate does, how many arguments it has, what can go in or come out, and which order the arguments are in. It is all too easy to think that you should write gives(A,milk) when elsewhere you have gives_milk(A); that you should write colour(A,dark) when elsewhere you have color(A,black); that you should write lays(eggs,A) when elsewhere you have lays(A,eggs). When writing down such information, you need not be as formal as I have, but you should note it down somehow. If you have programmed before, you will know that most computer languages let you put such notes as comments in your program.

Care is especially necessary because Prolog does not detect spelling errors. Usually they just make it say ``No''. For instance, suppose you have the fact

    colour( pip, black ).
and you ask
    colour( Who, dark ).
Prolog treats dark as completely different from black, and will say no, when what you want is probably Yes - Who=pip. The same would happen if you were to ask
    colour( dark, Who ).
    black_colour( Who ).




next up previous
Next: Running the program
Up: Supplement 4
Previous: Introduction
Back: to main list of student notes



Jocelyn Paine
Tue Jun 4 17:58:48 BST 1996