%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  File:  grammar5.pl
%
%  Course:  HPSG Grammars in ALE
%
%  Purpose:  1. Adds the Head Feature Principle
%            2. Specifies all valency features in all rules
%            3. Adds the "spr" feature to categories
%            4. Alters the NP macro
%            5. Changes the type declarations to make "subst"
%               and "func" subtypes of head and provides
%               suitable subtype definitions
%            6. Adds NBar macro
%            7. Includes entries for "book" and "the"
%            8. Adds the specifier-head rule
%
%  Parses:    kim likes the book
%             kim gives sandy the book
%
% No parses:  same as before
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%**********************  Type Hierarchy

bot cons bot.

bot sub [sign,list,cat,head,vform,boolean].

sign sub []
   intro [cat:cat].

cat sub []
   intro [head:head,
          subj:list,
          comps:list,
          spr:list].
                                
head sub [subst,func].

subst sub [noun,verb].

func sub [mark,det]
  intro [spec:sign].

det sub [].
mark sub [].
noun sub [].

verb sub []
  intro [vform:vform,
         aux:boolean,
         inv:boolean].

vform sub [fin,bse].

fin sub [].
bse sub [].

boolean sub [yes,no].

yes sub [].
no sub [].

list sub [e_list,ne_list].

ne_list sub []
   intro [hd:bot,
	  tl:list].

e_list sub [].

%%%**********************  Macros

np macro
  cat:(head:noun,                 %  Define "np" as a macro
       subj:[],
       comps:[],
       spr:[]).

detp macro
  cat:(head:det,
       subj:[],
       comps:[],
       spr:[]).

s macro
  cat:(head:verb,
       subj:[],
       comps:[],
       spr:[]).

vp macro
  cat:(head:verb,
       subj:[_],
       comps:[]).

nbar macro
  cat:(head:noun,
       subj:[],
       comps:[],
       spr:[_]).

%%%**********************  Lexical Entries

sandy ---> @ np.        %  Macro definitions used in lexical entries.

kim ---> @ np.          %  New entries for "kim", "books", etc

books ---> @ np.

snored ---> cat:(head:(verb,
                       vform:fin,
                       aux:no,
                       inv:no),
                 subj:[@ np],
                 comps:[]). 

snore ---> cat:(head:(verb,
                      vform:bse,
                      aux:no,
                      inv:no),
                subj:[@ np],
                comps:[]). 

likes ---> cat:(head:(verb,
                      vform:fin,
                      aux:no,
                      inv:no),
                subj:[@ np],
                comps:[@ np]).

like ---> cat:(head:(verb,
                     vform:bse,
                     aux:no,
                     inv:no),
               subj:[@ np],
               comps:[@ np]).

gives ---> cat:(head:(verb,
                      vform:fin,
                      aux:no,
                      inv:no),
                subj:[@ np],
                comps:[@ np,@ np]).

give ---> cat:(head:(verb,
                     vform:bse,
                     aux:no,
                     inv:no),
               subj:[@ np],
               comps:[@ np,@ np]).

believes ---> cat:(head:(verb,
                         vform:fin,
                         aux:no,
                         inv:no),
                   subj:[@ np],
                   comps:[@ s]).

believe ---> cat:(head:(verb,
                        vform:bse,
                        aux:no,
                        inv:no),
                  subj:[@ np],
                  comps:[@ s]).

does ---> (cat:(head:(verb,
                      vform:fin,
                      aux:yes),
                comps:[(@ vp,
                        cat:(subj:Subj,
                             head:vform:bse))],
                subj:Subj)).

can ---> (cat:(head:(verb,
                     vform:fin,
                     aux:yes),
               comps:[(@ vp,
                       cat:(subj:Subj,
                            head:vform:bse))],
                subj:Subj)).

book ---> (@ nbar,
           cat:spr:[@ detp]).

the ---> cat:(head:spec:(@ nbar),
              spr:[],
              subj:[],
              comps:[]).

%%%**********************  Grammmar Rules

subject_head rule
(Mother, cat:(subj:[],
              comps:[],
              spr:Spr))
===>
cat> (SubjDtr),  
cat> (HeadDtr, cat:(subj:[SubjDtr],
                    comps:[],
                    spr:Spr)),
goal> head_feature_principle(Mother,HeadDtr).

head_complement rule            % head-complement rule added
(Mother, cat:(comps:[],
              subj:Subj,
              spr:Spr))
===>
cat> (HeadDtr, cat:(comps:Comps,
                    subj:Subj,
                    spr:Spr)),
cats> (Comps,ne_list),
goal> head_feature_principle(Mother,HeadDtr).

specifier_head rule
(Mother,cat:(subj:[],
             spr:[],
             comps:[]))
===>
cat> (SpecDtr,cat:(subj:[],
                   spr:[],
                   comps:[],
                   head:spec:HeadDtr)),
cat> (HeadDtr,cat:(subj:[],
                   spr:[SpecDtr],
                   comps:[])),
goal> (head_feature_principle(Mother,HeadDtr)).

head_subject_complement rule
(Mother, cat:(subj:[],
              comps:[],
              spr:Spr))
===>
cat> (HeadDtr, cat:(subj:[SubjDtr],
                    comps:Comps,
                    spr:Spr,
                    head:inv:yes)),
cat> SubjDtr,
cats> (Comps, ne_list),
goal> head_feature_principle(Mother,HeadDtr).


%%%**********************  Principles

head_feature_principle(cat:head:Head, cat:head:Head) if true.

%%%**********************  Definite Constraints (used in next exercise)

sign_to_synsem(synsem:Synsem,Synsem) if
     true.

list_sign_to_synsem([],[]) if
     true.

list_sign_to_synsem([H|T],[S|R]) if
     sign_to_synsem(H,S),
     list_sign_to_synsem(T,R). 


%%%**********************  End of File

