Next: Responses
Up: Dafydd Gibbon: Introduction to
Previous: Syllable network
Goal of this unit:
To learn the basic principles of relational database construction, and to construct elementary relational databases, for example on topics such as the following:
- Recipes.
- Courses you attend.
- Calendar.
- Universities with linguistics departments.
- Football matches and their results.
- Lexical databases.
- Phoneme inventories with features.
Points for discussion:
- What is a fact?
- What are data?
- What is a relation?
- What is a property?
- Check out the terms `proposition', `statement', `predicate' and `argument' in a logic book (or in an Internet logic course).
- What is a variable?
- When and by whom was the Prolog programming language invented, and what for?
Basic information about Prolog:
One way of looking at Prolog is as a theory of how people think. It is not necessarily the best theory, and it may be quite a long way from the truth, in detail.
Nevertheless, Prolog `emulates' certain aspects of the structure of thought,
providing precise theories of what concepts such as the following might mean:
- Name, object.
- Predicate, property, relation.
- Fact.
- Data, database.
- Rule.
- Conjunction, disjunction.
- Inference, deduction.
- Query, response.
Another way of looking at Prolog is to see it as a kind of precise shorthand for statements such as the following: `Sue is mother of John.', `Sue is mother of Anne.' `If Sue is mother of John and Sue is mother of Anne, then John is sibling of Sue.', and so on.
However, a number of conventions for two kinds of statement and their parts (the syntax of Prolog) are required in order to do this, and these will be outlined below.
- Prolog statements consist of the following parts:
- Names (starting with a lower-case letter, e.g. sue, john, anne); if names contain special characters, or are to start with an upper-case letter they must be contained in right-hand quotes, e.g. 'Susan'.
- Variables over names (starting with an upper case letter, e.g. X, Y, Variable_1, Somebody).
- Predicates (starting with a lower-case letter, e.g. mother, sibling.
- Operators, such as `,', `;', `:-', `.'.
- Brackets ( ... ), [ ... ]
- There are just three kinds of statement in Prolog are:
- Facts, each consisting of a predicate such as mother and its arguments, i.e. names such as sue, john, and anne; e.g. mother(sue,john)., mother(sue,anne).
- Rules, which permit additional information which relates different facts to be inferred (deduced) e.g.
sibling(X,Y) :- mother(Z,X), mother(Z,Y).
in other words, X is a sibling of Y if they have the same mother, i.e. if there is some Z who is mother of X and mother of Y.
- Queries, of which there are two kinds:
- facts, rather like `yes/no questions', to be compared with facts in the database (resulting in answers of yes or no), such as mother(sue,john).
- fact schemas, i.e. facts with one or more names replaced by variables, rather like `wh-questions' (to be answered by assignments of names to the variables).
Actually, facts associated with some predicates, such as halt, write, do not just extend the information in the databse, but are rather like `indirect speech acts', because they are more like instructions than statements; they might be said actualy to do things.
- Finally, each fact must be asserted in the database as a `meta-fact', using the assertz/1 predicate (which puts the fact at the beginning of the database) or the assertz/1 predicate (which puts the fact at the end of the database), e.g.
assertz(mother(sue,john)).
assertz(mother(sue,anne)).
But note - if the database is formulated in a file, then the
assertz(mother(sue,john)). assertion predicate is omitted, and
the contents of the entire file are asserted by the
consult(<filename>). predicate.
The file can also contain an `empty predicate' which automatically starts
a database lookup procedure.
Practical tasks:
- Enter Prolog on whatever machine you happen to be using. I will be illustrating the points using sicstus on a machine in the Bielefeld computer center called `dee'. For instance:
dee /home/gibbon: sicstusENTER
- A message such as the following will appear:
SICStus 3 #3: Tue Dec 17 15:08:48 MET 1996
| ?-
- After the ?- prompt, type halt. and press the RETURN/ENTER key (not forgetting the period/dot/full-stop!):
| ?- halt.ENTER
- This will bring you back to the UNIX command line.
- Now enter `sicstus' again, and assert two facts in the Prolog database by entering the following statements exactly in this form (no capitals!:
assertz(mother(sue,john)).
assertz(mother(sue,anne)).
- Then query the database (ENTER after each query, of course):
mother(sue,john).
mother(sue,john).
mother(anne,john).
What answers did you get?
Check the answer (4.1) after testing. Type some more queries like these and note the answers.
- At this point, you will have executed an interpreter for the programming language Prolog by typing `sicstus', and you will have instructed the interpreter to interpret a Prolog statement, namely `halt.'
- Do all this again ... but, in order to get used to unforeseen situations, when you see the sicstus prompt, type the following (don't worry yet...):
- exit.
- This is a test.
- halt (this time with no dot)
- At this point you will have the following mess on your screen:
| ?- exit.
{EXISTENCE ERROR: exit: procedure user:exit/0 does not exist}
| ?- This is a test.
{SYNTAX ERROR: in lines 16-17}
** operator expected after expression **
?- This is a
** here **
test .
| ?- halt
- Now type a dot `.' (and RETURN, of course), which Prolog requires to finish this incomplete statement, and you will leave Prolog again and find yourself on the UNIX command line.
- You will find a number of Prolog introductions and handbooks in the bibliography, for instance [4], which has been the standard Prolog introduction for many years, [8] on Prolog in computational linguistics, [3] on Prolog in Artificial Intelligence, and [18] for more advanced students of Prolog.
- TASK: Try to explain these error messages.
- Now look for introductions to Prolog on the web,
and try to find one which meets your own level of knowledge. Maybe one of these -
in Dundee,
Furtwangen,
Czech Republic,
or an online manual for
Sicstus.
Next: Responses
Up: Dafydd Gibbon: Introduction to
Previous: Syllable network
Dafydd Gibbon
Fri Nov 28 02:24:58 MET 1997