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 baseskb1.pl
,kb2.pl
, andkb3.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:
- Harry is a wizard.
- Hagrid scares Dudley.
- All wizards are magical.
- Uncle Vernon hates anyone who is magical.
- Aunt Petunia hates anyone who is magical or scares Dudley.
- 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:
- Does Aunt Petunia hate Hagrid? (The answer should be yes.)
- Who does Uncle Vernon hate? (The answer should be Harry.)
- Who does Aunt Petunia hate? (The answer should be Harry and Hagrid. Type semicolon to get the second answer.)