% Multifile declarations.
% :- multifile if/2.


:- [trale_home(feature_ordering)].

% specify signature file
signature(signature).

% GRALE output specifications

% hidden_feat(daughters).    % shown by the tree

synsem <<< arg_st.
vform <<< aux.
vform <<< inv.
subj <<< comps.
liker <<< liked.
sayer <<< said.
giver <<< gift.
gift <<< given.
>>> phon.


%====================================================================

% Simulation of Parametric Sorts as Principles of Grammar

fun list_of_synsems(-).

list_of_synsems(X) if
   when( (X=(e_list;ne_list) ),
           und_list_of_synsems(X)).

und_list_of_synsems(X) if (X=e_list).
und_list_of_synsems(X) if (X=[(synsem)|Y]),list_of_synsems(Y).

% subj:list(synsem)
% comps:ist(synsem)

val *> (subj:list_of_synsems,
        comps:list_of_synsems).

% arg_st:list(synsem)
word *> arg_st:list_of_synsems.



%====================================================================
% Phrase Structure Rules, encoding the ID-Principle and the
%                                      Constituent Order Principle and
%                                      Subcategorization Principle


% Head Subject Rule

head_subject_rule rule
(phrase,
 synsem:loc:cat:val:(subj:e_list,
                     comps:e_list),
 daughters:(hs_struc,
            hdtr:Hdtr,
            ndtr:Ndtr),
 phon:MotherPhon)
   ===>
cat> (Ndtr, synsem:Synsem, phon:NdtrPhon),
cat> (Hdtr, synsem:loc:cat:val:(subj:[Synsem],
                                comps:e_list),
      phon:HdtrPhon),
goal> append(NdtrPhon,HdtrPhon,MotherPhon).


% Head Complement Rule

head_complement_rule rule
(phrase,
 synsem:(loc:cat:val:(subj:Subj,
                     comps:List)),
 daughters:(hc_struc,
            hdtr:Hdtr,
            ndtr:Ndtr),
 phon:MotherPhon)
   ===>
cat> (Hdtr, synsem:loc:cat:val:(subj:Subj,
                                comps:[Synsem|List]),
      phon:HdtrPhon),
cat> (Ndtr, synsem:Synsem, phon:NdtrPhon),
goal> append(HdtrPhon,NdtrPhon,MotherPhon).


% Head Adjunct Rule

head_adjunct_rule rule
(phrase,
 synsem:loc:cat:val:(subj:List,
                      comps:e_list),
 daughters:(ha_struc,
            hdtr:Hdtr,
            ndtr:Ndtr),
 phon:MotherPhon)
   ===>
cat> (Hdtr, synsem:(Synsem,
                   loc:cat:val:(subj:List,
                                comps:e_list)),
      phon:HdtrPhon),
cat> (Ndtr, synsem:loc:cat:(head:mod:Synsem,
                            val:(subj:e_list,
                                 comps:e_list)),
      phon:NdtrPhon),
goal> append(HdtrPhon,NdtrPhon,MotherPhon).


% Subject Aux Inversion Rule

subject_aux_inversion_rule rule
(phrase,
 synsem:(loc:cat:val:(subj:e_list,
                      comps:List)),
 daughters:(sai_struc,
            hdtr:Hdtr,
            ndtr:Ndtr),
 phon:MotherPhon)
   ===>
cat> (Hdtr, word, 
      synsem:loc:cat:(head:inv:plus,
                      val:(subj:[Synsem],
                           comps:List)),
      phon:HdtrPhon),
cat> (Ndtr, synsem:Synsem, phon:NdtrPhon),
goal> append(HdtrPhon,NdtrPhon,MotherPhon).


% Definite Clauses for append/3

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).


%====================================================================
% PRINCIPLES

% Head Feature Principle

phrase *> (synsem:loc:cat:head:Head,
           daughters:hdtr:synsem:loc:cat:head:Head).

% Semantics Principle

phrase *> ((synsem:loc:cont:Content,
          daughters:((hs_struc;hc_struc;sai_struc),
                     hdtr:synsem:loc:cont:Content);
          (synsem:loc:cont:Content,
          daughters:(ha_struc,
                     ndtr:synsem:loc:cont:Content)))).

% INV Principle

(synsem:loc:cat:head:inv:plus) *> (synsem:loc:cat:head:(vform:fin,
                                                        aux:plus)).

% MOD Principle

(phrase,
 daughters:(hs_struc;hc_struc;sai_struc))
  *> daughters:ndtr:synsem:loc:cat:head:mod:none.


% Argument Realization Principle

(word,
 synsem:loc:cat:head:pred:plus) *> (synsem:loc:cat:val:(subj:[Synsem],
                                                        comps:List),
                                    arg_st:[Synsem|List]).

(word,
 synsem:loc:cat:head:pred:minus) *> (synsem:loc:cat:val:(subj:e_list,
                                                        comps:List),
                                    arg_st:List).


% Structural Case Principle

Synsem^(phrase,
 daughters:(hdtr:synsem:loc:cat:(head:vform:fin,
                                 val:subj:[Synsem]),
            ndtr:synsem:(Synsem,
                         loc:cat:head:noun)))
*> (daughters:ndtr:synsem:loc:cat:head:case:nom).

(phrase,
 daughters:(hc_struc,
            ndtr:synsem:loc:cat:head:noun))
*> (daughters:ndtr:synsem:loc:cat:head:case:acc).


% Functional Preposition Principle

(word,
phon:ne_list,
synsem:loc:cat:head:(prep,
                     pform:non_lexical))
*>
(synsem:loc:(cat:(head:(mod:none,pred:minus)),
             cont:Cont),
arg_st:([(loc:(cat:val:(subj:[],comps:[]),
               cont:Cont))])
).


% Subject Principles

(val,subj:ne_list) *> subj:[_].

(head:verb,val:subj:e_list) *> head:vform:fin.


%====================================================================
% LEXICON

% NOUNS

peter ---> (phon:[(a_ peter)],
	    synsem:loc:(cat:head:(noun,
                                  pred:minus),
                        cont:index:(ref,
                                    num:sg,
                                    pers:third,
                                    gen:masc)),
            arg_st:e_list).

mary ---> (phon:[(a_ mary)],
	   synsem:loc:(cat:head:(noun,
                                  pred:minus),
                      cont:index:(ref,
                                  num:sg,
                                  pers:third,
                                  gen:fem)),
           arg_st:e_list).

he ---> (phon:[(a_ he)],
	 synsem:loc:(cat:head:(noun,
                              case:nom,
                              pred:minus),
                     cont:index:(ref,
                                 num:sg,
                                 pers:third,
                                 gen:masc)),
        arg_st:e_list).

she ---> (phon:[(a_ she)],
	  synsem:loc:(cat:head:(noun,
                                case:nom,
                                pred:minus),
                     cont:index:(ref,
                                 num:sg,
                                 pers:third,
                                 gen:fem)),
        arg_st:e_list).

it ---> (phon:[(a_ it)],
	 synsem:loc:(cat:head:(noun,
                                  pred:minus),
                    cont:index:(ref,
                                num:sg,
                                pers:third,
                                gen:neut)),
        arg_st:e_list).

it ---> (phon:[(a_ it)],
	 synsem:loc:(cat:head:(noun,
                              pred:minus),
                    cont:index:(it,
                                num:sg,
                                pers:third,
                                gen:neut)),
         arg_st:e_list).

him ---> (phon:[(a_ him)],
	  synsem:loc:(cat:head:(noun,
                               case:acc,
                               pred:minus),
                     cont:index:(ref,
                                num:sg,
                                pers:third,
                                gen:masc)),
          arg_st:e_list).

her ---> (phon:[(a_ her)],
	  synsem:loc:(cat:head:(noun,
                               case:acc,
                               pred:minus),
                     cont:index:(ref,
                                num:sg,
                                pers:third,
                                gen:fem)),
          arg_st:e_list).

you ---> (phon:[(a_ you)],
	  synsem:loc:(cat:head:(noun,
                               pred:minus),
                     cont:index:(ref,
                                 pers:second)),
          arg_st:e_list).

they ---> (phon:[(a_ they)],
	   synsem:loc:(cat:head:(noun,
                                case:nom,
                                pred:minus),
                       cont:index:(ref,
                                   pers:third,
                                   num:pl)),
           arg_st:e_list).

them ---> (phon:[(a_ them)],
	   synsem:loc:(cat:head:(noun,
                                case:acc,
                                pred:minus),
                       cont:index:(ref,
                                   pers:third,
                                   num:pl)),
            arg_st:e_list).



% VERBS

walk --->  (phon:[(a_ walk)],
	    synsem:loc:(cat:head:(verb,
                                 vform: base,
                                 pred: plus,
                                 aux: minus),
                        cont:(walk_rel,
                              walker:Index)),
            arg_st:[(loc:(cat:(head:noun,
                             val:(subj:e_list,
                                  comps:e_list)),
                          cont:index:Index))]).

walks --->  (phon:[(a_ walks)],
	     synsem:loc:(cat:(head:(verb,
                                 vform:fin,
                                 pred:plus,
                                 aux:minus),
                                 val:subj:[(loc:cont:(psoa;index:(pers:third,
                                                                  num:sg)))]),
                        cont:(walk_rel,
                              walker:Index)),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index))]).


rain --->  (phon:[(a_ rain)],
	    synsem:loc:(cat:head:(verb,
                                 vform: base,
                                 pred: plus,
                                 aux: minus),
                        cont:rain_rel),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:it))]).

rains --->  (phon:[(a_ rains)],
	     synsem:loc:(cat:(head:(verb,
                                  vform:fin,
                                  pred:plus,
                                  aux:minus),
                             val:subj:[(loc:cont:(psoa;index:(pers:third,
                                                              num:sg)))]),
                        cont:rain_rel),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:it))]).

like --->  (phon:[(a_ like)],
	    synsem:loc:(cat:head:(verb,
                                 vform: base,
                                 pred: plus,
                                 aux: minus),
                        cont:(like_rel,
                              liker:Index1,
                              liked:Index2)),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index1)),
                     (loc:(cat:(head:noun,
                                val:(subj:e_list,
                                     comps:e_list)),
                          cont:index:Index2))]).

likes --->  (phon:[(a_ likes)],
	     synsem:loc:(cat:(head:(verb,
                                   vform: fin,
                                   pred: plus,
                                   aux: minus),
                             val:subj:[(loc:cont:(psoa;index:(pers:third,
                                                              num:sg)))]),
                        cont:(like_rel,
                              liker:Index1,
                              liked:Index2)),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index1)),
                     (loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index2))]).


say --->  (phon:[(a_ say)],
	   synsem:loc:(cat:head:(verb,
                                vform: base,
                                pred: plus,
                                aux: minus),
                       cont:(say_rel,
                             sayer:Index,
                             said:Psoa)),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index)),
                     (loc:(cat:(head:(functional,
                                      vform:fin,
                                      marking:that),
                                val:(subj:e_list,
                                     comps:e_list)),
                            cont:Psoa))]).

says --->  (phon:[(a_ says)],
	    synsem:loc:(cat:(head:(verb,
                                  vform: fin,
                                  pred: plus,
                                  aux: minus),
                            val:subj:[(loc:cont:(psoa;index:(pers:third,
                                                             num:sg)))]),
                        cont:(say_rel,
                              sayer:Index,
                              said:Psoa)),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index)),
                     (loc:(cat:(head:(functional,
                                      vform:fin,
                                      marking:that),
                                val:(subj:e_list,
                                     comps:e_list)),
                           cont:Psoa))]).

give --->  (phon:[(a_ give)],
	    synsem:loc:(cat:head:(verb,
                                 vform: base,
                                 pred: plus,
                                 aux: minus),
                        cont:(give_rel,
                              giver:Index1,
                              gift:Index2,
                              given:Index3)),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index1)),
                     (loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                           cont:index:Index2)),
                     (loc:(cat:(head:(prep,
                                      pform:to),
                                val:(subj:e_list,
                                     comps:e_list)),
                           cont:index:Index3))]).


gives --->  (phon:[(a_ gives)],
	     synsem:loc:(cat:(head:(verb,
                                   vform:fin,
                                   pred:plus,
                                   aux:minus),
                                   val:subj:[(loc:cont:(psoa;index:(pers:third,
                                                                   num:sg)))]),
                        cont:(give_rel,
                              giver:Index1,
                              gift:Index2,
                              given:Index3)),
            arg_st:[(loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index1)),
                     (loc:(cat:(head:noun,
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index2)),
                     (loc:(cat:(head:(prep,
                                      pform:to),
                               val:(subj:e_list,
                                    comps:e_list)),
                          cont:index:Index3))]).


%%% AUXILIARIES

% LE of will (future auxiliary)

will ---> (phon:[(a_ will)],
	   synsem:loc:(cat:head:(verb,
                                vform:fin,
                                pred:plus,
                                aux:plus),
                      cont:(future_rel,
                            soa_arg:Cont)),
      arg_st:[(Synsem),(loc:(cat:(head:(verb,
                                        vform:base),
                                  val:(subj:[(Synsem)],
                                       comps:e_list)),
                                  cont:Cont))]).


% PREPOSITIONS

to ---> (word,
	 phon:[(a_ to)],
	 synsem:loc:cat:head:(prep,
                              pform:to)).

to ---> (phon:[(a_ to)],
        synsem:loc:(cat:head:(prep,
                               mod:(loc:(cat:(head:verb,
                                              val:(subj:ne_list,
                                                   comps:e_list)),
                                         cont:(Cont1))),
                               pred:minus,
                               pform:lexical),
                          cont:(direction_rel,
                                movement:Cont1,
                          goal:Cont2)),
        arg_st:[(loc:(cat:(head:noun,
                           val:(subj:e_list,
                                comps:e_list)),
                      cont:index:Cont2))]).


% ADVERBS

here ---> (phon:[(a_ here)],
	   synsem:loc:(cat:head:(adv,
                                pred:minus,
                                mod:loc:(cat:(head:verb,
                                              val:subj:ne_list),
                                         cont:Cont)),
                      cont:(here_rel,
                            located:Cont)),
        arg_st:[]).


% COMPLEMENTIZERS

that ---> (phon:[(a_ that)],
	   synsem:loc:(cat:head:(functional,
                                pred:minus,
                                vform:Vform,
                                mod:none,
                                marking:that),
                       cont:Cont),
          arg_st:[(loc:(cat:(head:(verb,
                                   vform:(Vform,fin)),
                             val:(subj:e_list,
                                  comps:e_list)),
                          cont:Cont))]).



%====================================================================




