General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Writing knowledge bases

  • Start emacs (or another editor of your choice), open a new file called Name.pl (where Name is a name of your choice), write your knowledge base, save the file. You can then load and query this knowledge base in the same way as you loaded and queried the knowledge bases kb1.pl, kb2.pl, and kb3.pl. When making changes to Name.pl, you have to save the file again and you have to load it into Prolog again.
  • If you don't know emacs, go here for a quick introduction.
  • As a first exercise, write a Prolog knowledge base specifying the following facts and rules:
    1. Harry is a wizard.
    2. Hagrid scares Dudley.
    3. All wizards are magical.
    4. Uncle Vernon hates anyone who is magical.
    5. Aunt Petunia hates anyone who is magical or scares Dudley.
    Hints
  • Load this database into Prolog. Prolog should give you a short answer saying that it compiled your knowledge base. If it gives you a different answer, there might be a problem with your knowledge base. Skip ahead to the next section to see which are the things that Prolog may complain about.
  • Ask the following queries:
    1. Does Aunt Petunia hate Hagrid? (The answer should be yes.)
    2. Who does Uncle Vernon hate? (The answer should be Harry.)
    3. Who does Aunt Petunia hate? (The answer should be Harry and Hagrid. Type semicolon to get the second answer.)

Next: Interpreting error messages and warnings.

Back to the practical session of day 1.