Writing knowledge bases
- Go to the shell and via "Session" open another shell.
- Start emacs (or another editor of your choice), by typing
emacs. Open a new file (via 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.
- 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: Traces.
Last modified: Thu Dec 2 12:03:26 CET 2004