% Grammar 4c
% ==========

% specifications for the GRALE output display
hidden_feat(dtr1).
hidden_feat(dtr2).

% specify signature file
signature(signature).


% lexical entries

i ---> (word,
        phon:[(a_ i)],
	synsem:(category:(head:case:nom,
                             subcat:e_list),
                   content:(index: (X,(person:first,
                                       number:sing))),
                   context:(backgr:[(speaker_rel,arg1:X)]))).

me ---> (word,
         phon:[(a_ me)],
	 synsem:(category:(head:case:(acc;dat),
                              subcat:e_list),
                    content:(index: (X,(person:first,
                                        number:sing))),
                    context:(backgr:[(speaker_rel,arg1:X)]))).

she ---> (word,
          phon:[(a_ she)],
	  synsem:(category:(head:case:nom,
                             subcat:e_list),
                   content:(index: (X,(person:third,
                                       number:sing,
                                       gender:fem))),
                   context:(backgr:[(female_rel,arg1:X)]))).

her ---> (word,
          phon:[(a_ her)],
	  synsem:(category:(head:case:(acc;dat),
                              subcat:e_list),
                    content:(index: (X,(person:third,
                                        number:sing,
                                        gender:fem))),
                    context:(backgr:[(female_rel,arg1:X)]))).

milk ---> (word,
           phon:[(a_ milk)],
	   synsem:(category:(head:noun,
                             subcat:e_list),
                    content:(index:(person:third,
                                    number:sing)),
		    context:backgr:[])).

walk --->  (word,
            phon:[(a_ walk)],
	    synsem:(category:(head:vform:fin,
                              subcat:[(category:(head:case:nom),
                                       content:index:(X,
                                                      person:first,
                                                      number:sing)
                                                      )]),
                    content:(walk_rel,
                             arg1:X),
		    context:backgr:[])).

walks --->  (word,
             phon:[(a_ walks)],
	     synsem:(category:(head:vform:fin,
                              subcat:[(category:(head:case:nom),
                                       content:index:(X,
                                                      person:third,
                                                      number:sing)
                                                      )]),
                    content:(walk_rel,
                             arg1:X),
		    context:backgr:[])).

love ---> (word,
           phon:[(a_ love)],
	   synsem:(category:(head:vform:fin,
                              subcat:[(category:(head:case:nom),
                                       content:index: (X,
                                                       person:first,
                                                       number:sing)),
                                      (category:(head:case:acc),
                                       content:index: Y)]),
                    content:(love_rel,
                             arg1:X,
                             arg2:Y),
		    context:backgr:[])).

loves  ---> (word,
             phon:[(a_ loves)],
	     synsem:(category:(head:vform:fin,
                              subcat:[(category:(head:case:nom),
                                       content:index: (X,
                                                       person:third,
                                                       number:sing)),
                                      (category:(head:case:acc),
                                       content:index: Y)]),
                    content:(love_rel,
                             arg1:X,
                             arg2:Y),
		    context:backgr:[])).

give ---> (word,
           phon:[(a_ give)],
	   synsem:(category:(head:vform:fin,
                              subcat:[(category:(head:case:nom),
                                       content:index: (X,
                                                       person:first,
                                                       number:sing)),
                                      (category:(head:case:acc),
                                       content:index: Y),
                                      (category:(head:case:dat),
                                       content:index: Z)]),
                    content:(give_rel,
                             arg1:X,
                             arg2:Y,
                             arg3:Z),
		    context:backgr:[])).

gives --->  (word,
             phon:[(a_ gives)],
	     synsem:(category:(head:vform:fin,
                              subcat:[(category:(head:case:nom),
                                       content:index: (X,
                                                       person:third,
                                                       number:sing)),
                                      (category:(head:case:acc),
                                       content:index: Y),
                                      (category:(head:case:dat),
                                       content:index: Z)]),
                     content:(give_rel,
                             arg1:X,
                             arg2:Y,
                             arg3:Z),
		     context:backgr:[])).

think  --->  (word,
              phon:[(a_ think)],
	      synsem:(category:(head:vform:fin,
                               subcat:[(category:(head:case:nom),
                                       content:index: (X,
                                                       person:first,
                                                       number:sing)),
                                       (category:(head:vform:fin,
						 subcat:[]),
                                       content: Y)]),
                    content:(think_rel,
                             arg1:X,
                             arg2:Y),
		    context:backgr:[])).

thinks --->  (word,
              phon:[(a_ thinks)],
	      synsem:(category:(head:vform:fin,
                               subcat:[(category:(head:case:nom),
                                       content:index: (X,
                                                       person:third,
                                                       number:sing)),
                                       (category:(head:vform:fin,
						 subcat:[]),
                                       content: Y)]),
                    content:(think_rel,
                             arg1:X,
                             arg2:Y),
		    context:backgr:[])).


% phrase structure rules
subject_head_rule rule
(phrase,
 phon:MotherPhon,
 synsem:category:subcat:[],
 dtr1:Subj, dtr2:Head)
   ===>
cat> (Subj, phon:SubjPhon),
cat> (Head, phon:HeadPhon),
goal> phon_append(SubjPhon,HeadPhon,MotherPhon).

head_complement_rule rule
(phrase,
 phon:MotherPhon,
 synsem:category:subcat:ne_list,
 dtr1:Comp, dtr2:Head)
   ===>
cat> (Head, phon:HeadPhon),
cat> (Comp, phon:CompPhon),
goal> phon_append(HeadPhon,CompPhon,MotherPhon).


% Principles

% Semantics Principle
phrase *> (synsem:content:C,
	   dtr2:synsem:content:C).

% Head Feature Principle
phrase *> (synsem:category:head:H,
	   dtr2:synsem:category:head:H).

% Subcategorization Principle (alternate version)
phrase *> (%Phrase,
	   synsem:category:subcat:PhrSubcat,
           dtr1:synsem:Synsem,
           dtr2:synsem:category:subcat:HeadSubcat)
goal
   append(PhrSubcat,[Synsem],HeadSubcat).


% Goal definitions

phon_append([],[],[]) if !, true.
phon_append([],[H|T1],[H|T2]) if phon_append([],T1,T2).
phon_append([H|T1],L,[H|T2]) if phon_append(T1,L,T2).


append(X,Y,Z) if
   when(  ( X=(e_list;ne_list)
                ),
            undelayed_append(X,Y,Z)).

undelayed_append(L,[],L) if true.
undelayed_append([],(L,ne_list),L) if true.
undelayed_append([H|T1],(L,ne_list),[H|T2]) if
  append(T1,L,T2).

