% Grammar 2
% =========

% Multifile declarations. 
% :- multifile '##'/2. 
% :- multifile '~~>'/2.
:- multifile if/2.

% load phonology and tree output
% :- [trale_home(tree_extensions)].

% specify signature file
signature(signature).

% lexical entries
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,
                            subcat:e_list),
                 content: (index: (X, (person:third,
                                       number:sing,
                                       gender:fem))),
                 context: (backgr:[(female_rel, arg1:X)]))).

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:[]))).

loves --->  (word,
	     phon:[(a_ loves)],
	     synsem: (category: (head:vform:fin,
                             subcat:[(category:head:case:acc,
                                      content:index: Y),
                                     (category:head:case:nom,
                                      content:index: (X,
                                                      person:third,
                                                      number:sing))]),
                 content: (love_rel,arg1:X,arg2:Y),
                 context: (backgr:[]))).


i ---> (word,
	phon:[(a_ i)],
	synsem:(category: (head:case:nom,
                            subcat:e_list),
                 content: (index:(person:first,
                                  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:[]))).
         
         
% phrase structure rules
subject_head_rule rule
(phrase, phon:MotherPhon,
         synsem:(category:(head:H,
                          subcat:[]),
                content:Content),
 dtr1:Subj, dtr2:Head,
 dtrs:[Subj,Head])
   ===>
cat> (Subj,
      phon:SubjPhon,
      synsem:Synsem),
cat> (Head,
      phon:HeadPhon,
      synsem:(category:(head:H,
			      subcat:[Synsem]),
		    content:Content)),
goal> append(SubjPhon,HeadPhon,MotherPhon).


head_complement_rule rule
(phrase, phon:MotherPhon,
         synsem:(category:(head:H,
                          subcat:(ne_list, Rest)),
                content:Content),
 dtr1:Comp, dtr2:Head,
 dtrs:[Head,Comp])
   ===>
cat> (Head,
      phon:HeadPhon,
      synsem:(category:(head:H,
			subcat:[First|Rest]),
              content:Content)),
cat> (Comp,
      phon:CompPhon,
      synsem:First),
goal> append(HeadPhon,CompPhon,MotherPhon).



%----------------------

append(X,Y,Z) if
   when(  ( X=(e_list;ne_list)
          ; Y=e_list
          ; Z=(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).



