Loading and querying knowledge bases
-
Download the knowledge bases
kb1.pl
,kb2.pl
, andkb3.pl
(which are the knowledge bases that we just talked about). To download, right click on the following links and choose 'save link to disk'.kb1.pl kb2.pl kb3.pl -
Now type
consult('kb1.pl').
at the?-
prompt. This loads knowledge basekb1.pl
. Prolog should respond with% kb1.pl compiled 0.00 sec, 0 bytes Yes
-
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) | . Yes
-
If something else goes wrong and Prolog start writing crazy
things on the screen without getting back to showing you the
?-
prompt, typeCtrl-c
. This should show you the following line:Action (h for help) ?
Typea
(for abort) and press return. This should get you back to the?-
prompt. -
Load and query the other two knowledge bases (kb2.pl and
kb3.pl), 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 typingpl
). -
Play a bit with the knowledge bases
kb1.pl
,kb2.pl
, andkb3.pl
, before going on to the next section, which will tell you how to write your own knowledge bases.
Next: Writing knowledge bases.