[Previous] [Up] [Next]
Go backward to Agreement in Context Free Grammar Rules
Go up to Extending DCGs: Agreement
Go forward to Exercises

Prolog Implementation

To implement agreement in the DCG format, we need to adapt the rules so that they can pass on the agreement information. To allow a Prolog procedure access to additional information, we make it available by increasing the arity of the predicate so as to introduce a new argument which can hold it. With a normal Prolog procedure, this would be a trivial matter, but DCG rules are a bit special--they are not Prolog rules, they only become rules when the DCG interpreter rewrites them. However, the interpreter is flexible enough that you can add extra arguments just as in normal Prolog rules. It simply rewrites the rules by putting two additional arguments for the difference list on at the end. To extend the grammar discussed in section Definite Clause Grammars to handle subject--verb agreement, we can rewrite it as follows:
s --> np(Num),vp(Num).
np(Num) --> det(Num), n(Num). 
np(sing) --> pn. 
np(plu) --> n(plu).
vp(Num) --> verb(Num), np. 
vp(Num) --> verb(Num). 
We could put a feature for number on the proper noun part of the np(sing) --> pn rule too, but it is not necessary, if all proper nouns are singular (think about why this is).

We then have to change the dictionary rules to include the number information as well:

det(sing) --> [every]. 
det(sing) --> [a]. 
det(_Num) --> [the]. 
verb(sing) --> [chases]. 
verb(plu) --> [chase]. 
verb(sing) --> [miaows]. 
verb(plu) --> [miaow]. 
n(sing) --> [dog]. 
n(plu) --> [dogs]. 
n(sing) --> [cat]. 
n(plu) --> [cats]. 
pn --> [fido]. 
pn --> [tigger].
Note that the number information is irrelevant in the case of the determiner the, which can be used with both singular and plural nouns. This is why the argument position is filled with an anonymous variable. This grammar gives the correct number agreement for the sentences in examples 1--4 above:
| ?- s([the,cat,miaows],[]).
| ?- s([the,cat,miaow],[]).
| ?- s([the,cats,miaows],[]).
| ?- s([the,cats,miaow],[]).


[Previous] [Up] [Next]