8.5 Practical Session
The purpose of Practical Session 8 is to help you get familiar with DCGs that make use of additional arguments and goals.
First some keyboard exercises:
- Trace some examples using the DCG which uses extra arguments to handle the subject/object distinction, the DCG which produces parses, and the DCG which uses extra goals to separate lexicon and rules. Make sure you fully understand the way all three DCGs work.
- Carry out traces on the DCG for a n b n c n given in the text (the one that gave the Count variable the values 0 , succ(0) , succ(succ(0)) , and so on). Try cases where the three blocks of a s, b s, and c s are indeed of the same length as well as queries where this is not the case.
Now for some programming. We suggest the following mini-project, which draws on all you have learned so far. Incidentally, in the Practical Session at the end of Chapter 12 we will be asking to extend this work even further, so do take this project seriously.
- First, bring together all the things we have learned about DCGs for English into one DCG. In particular, in the text we saw how to use extra arguments to deal with the subject/object distinction, and in the exercises you were asked to use additional arguments to deal with the singular/plural distinction. Write a DCG which handles both. Moreover, write the DCG in such a way that it will produce parse trees, and makes use of a separate lexicon.
- Once you have done this, extend the DCG so that noun phrases can be modified by adjectives and simple prepositional phrases (that is, it should be able to handle noun phrases such as “the small frightened woman on the table” or “the big fat cow under the shower”). Then, further extend it so that the distinction between first, second, and third person pronouns is correctly handled (both in subject and object form).