[Previous] [Up]
Go backward to Escape To Prolog
Go up to Escape to Prolog in DCGs and Using Univ

Univ

There is still a small problem with

vp(Agr,Tense) --> v(Agr,Tense,Type), np(_Num), np(_Num),
            {member(Type,[ditrans,2np])}.
because, as you may recall, we did not give the type of give as ditrans, but as ditrans(to). Now, the following will not work, because Prolog does not allow variables that range over functors.
vp(Agr,Tense) --> v(Agr,Tense,Type(_)), np(_Num), np(_Num),
            {member(Type,[ditrans,2np])}.
If you wrote this code, the interpreter would not load the file because there is a varriable functor, and moreover Type(Prep) would not have matched 2np anyway, as it does not have an argument.

What we need to do here is to analyse the functor expression further. We want to be able to say things such consider the functor, or the first argument for instance. There is a built-in operator which lets you do just this: =.. (which is read as "univ"--its name probably derives from a time when it was written as a predicate of that name). Univ is an infix operator (more about operators in unit Advanced Prolog).

X =.. Y.
is true if X is a term consisting either of an atom or of a functor with arguments and Y is a list whose head is the functor of X, and the other elements are the arguments of X in order:
| ?- predicate(argt1,argt2) =.. List.
 
List = [predicate,argt1,argt2] ? 
 
yes
| ?- Predicate =.. [predicate,argt1,argt2].
 
Predicate = predicate(argt1,argt2) ? 
 
yes
We can use univ to make identify the functor of the subcategorisation specification:
vp(Agr,Tense) --> v(Agr,Tense,Type), np(_Num), np(_Num),
            {Type =.. [Subcat|Rest],
             member(Subcat,[ditrans,2np])}.
If the DCG interpreter which rewrites DCG-rules into Prolog goals is written in Prolog, then univ is the type of predicate we need to append the extra two arguments corresponding to the difference list which appear in the Prolog rules. The procedure below is not the actual code, but it will give you an idea of how it can be done:
 
dcg_to_prolog(DCGTerm,StringIn,StringOut,PrologGoal):-
        DCGTerm =.. [P|A],
        conc(A,[StringIn,StringOut],NewA),
        PrologGoal =.. [P|NewA].

<a.von.klopp@bangor.ac.uk>

[Previous] [Up]