Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Loading and querying knowledge bases

  • Download the knowledge bases,, and (which are the knowledge bases that we just talked about). To download, right click on the following links and choose 'save link to disk'.
  • Now type consult(''). at the ?- prompt. This loads knowledge base Prolog should respond with
    % compiled 0.00 sec, 0 bytes
  • Type listing. to see which facts and clauses Prolog now knows about.
  • If you now send queries to Prolog, they will be answered based on this knowledge. Try this. Here are some queries that you could send.
    Is ron a wizard?wizard(ron).
    Is ron a muggle?muggle(ron).
    Who is a muggle?muggle(X).
    Who does crookshanks chase? chases(crookshanks,X).
    Who chases whom? chases(X,Y).
  • Don't forget to put a full stop at the end of each query before pressing return. If you do forget to put a full stop, Prolog will react by just doing nothing. This is what you will see on the screen:
    ?- wizard(harry)
    To fix it just type a full stop and press return again:
    ?- wizard(harry)
    |    .
  • If something else goes wrong and Prolog start writing crazy things on the screen without getting back to showing you the ?- prompt, type Ctrl-c. This should show you the following line:
    Action (h for help) ?
    Type a (for abort) and press return. This should get you back to the ?- prompt.
  • Load and query the other two knowledge bases ( and, as well. It is probably a good idea to clean Prologs internal knowledge base before loading a new one. The easiest way to do this, is to actually leave Prolog by typing halt. and restart it (by typing pl).
  • Play a bit with the knowledge bases,, and, before going on to the next section, which will tell you how to write your own knowledge bases.

Next: Writing knowledge bases.

Back to the practical session of day 1.