Practical Work - Week 1
Login to Unix, and create a
directory for this module.
Go to www.cems.uwe.ac.uk/~ryang/prolog/code/boy_names.pl
to download a Prolog file, ``boy_names.pl¡±.
The file ``boy_names.pl''
contains some information about the top 50 most popular boy's names from 1700
to 1988 (total 9 sample years). It defines the following relation in Prolog:
boy_names(Name, Year, N)
which means that Name is the top N most popular first name in Year. For
example,
boy_names(john, 1925, 1).
boy_names(william, 1925, 2).
state that ``john'' is the most popular name in 1925;
and ``william'' is the second popular name in 1925.
Now follow the step-by-step
instructions as below:
(1) Save this file to your place. Start Prolog then load the file (i.e. type the following).
Prolog
|?- [boy_names].
(2) Write the queries in Prolog to answer the following questions.
Note that after the first solution is printed on the screen, please
type ``;'', Prolog
will then carry on looking for the next solution. Please also remember that in Prolog you need a
full stop to end every input line.
(3) So far, we have only tried Prolog queries. Now let's try to write some simple Prolog programs. A Prolog
program defining a name which is in the top 20 for both 1925 and
1975 can be written as
follows.
top20_in_25_75(X):- boy_names(X,
1925, Y1), Y1 =< 20,
boy_names(X, 1975, Y2), Y2 =< 20.
Write
a similar program to define names which are below the top 5 and above the top
45 in years 1875, 1925 and 1975. Note that you need to open a text file to
write the program first. Then save it and load it into Prolog. Please try it out by entering some queries.
(4) If you still have time,
write a program to define old fashion
name and forever popular name.
You can make up your
own definitions.