% declare signature file name:
signature(signature).

% Load automatic specification of phonology and parse tree output
% as part of the feature structures themselves:
:- tree_extensions.
:- multifile if/2.
phon_feat(phon).
dtrs_feat(parser_dtrs).

% Define some properties of (grisu) output:
% don't show:
%hidden_feat(parser_dtrs).         % shown by the tree

% order of output:
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 ##
(phrase,
 synsem:loc:cat:val:(subj:e_list,
                     comps:e_list),
 dtrs:(hs_struc,
            hdtr:Hdtr,
            ndtr:Ndtr))
   ===>
cat> (Ndtr, synsem:Synsem),
cat> (Hdtr, synsem:loc:cat:val:(subj:[Synsem],
                                comps:e_list)).


% Head Complement Rule

head_complement_rule ##
(phrase,
 synsem:(loc:cat:val:(subj:Subj,
                     comps:List)),
 dtrs:(hc_struc,
            hdtr:Hdtr,
            ndtr:Ndtr))
   ===>
cat> (Hdtr, synsem:loc:cat:val:(subj:Subj,
                                comps:[Synsem|List])),
cat> (Ndtr, synsem:Synsem).


% Head Adjunct Rule

head_adjunct_rule ##
(phrase,
 synsem:loc:cat:val:(subj:List,
                      comps:e_list),
 dtrs:(ha_struc,
            hdtr:Hdtr,
            ndtr:Ndtr))
   ===>
cat> (Hdtr, synsem:(Synsem,
                   loc:cat:val:(subj:List,
                                comps:e_list))),
cat> (Ndtr, synsem:loc:cat:(head:mod:Synsem,
                            val:(subj:e_list,    % exercise: comment out
                                comps:e_list))). % and let students find it


% Subject Aux Inversion Rule

subject_aux_inversion_rule ##
(phrase,
 synsem:(loc:cat:val:(subj:e_list,
		  comps:List)),
 dtrs:(sai_struc,
            hdtr:Hdtr,
            ndtr:Ndtr))
   ===>
cat> (Hdtr, word, 
      synsem:loc:cat:(head:inv:plus,
                      val:(subj:[Synsem],
                           comps:List))),
cat> (Ndtr, synsem:Synsem).


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

% Head Feature Principle

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

% Semantics Principle

phrase *> ((synsem:loc:cont:Content,
	dtrs:((hs_struc;hc_struc;sai_struc),
	         hdtr:synsem:loc:cont:Content);
            (synsem:loc:cont:Content,
	 dtrs:(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,
 dtrs:(hs_struc;hc_struc;sai_struc))
  *> dtrs: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,
 dtrs:(hdtr:synsem:loc:cat:(head:vform:fin,
                                 val:subj:[Synsem]),
            ndtr:synsem:(Synsem,
                         loc:cat:head:noun)))
*> (dtrs:ndtr:synsem:loc:cat:head:case:nom).

(phrase,
 dtrs:(hc_struc,
            ndtr:synsem:loc:cat:head:noun))
*> (dtrs: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 ~~> (synsem:loc:(cat:head:(noun,
			    pred:minus),
		    cont:index:(ref,
                                num:sg,
		                pers:third,
                                gen:masc)),
            arg_st:e_list).

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

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

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

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

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

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

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

you ~~> (synsem:loc:(cat:head:(noun,
			  pred:minus),
		    cont:index:(ref,
                               pers:second)),
            arg_st:e_list).

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

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



% VERBS

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 ~~>  (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 ~~>  (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 ~~>  (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 ~~>  (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 ~~>  (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 ~~>  (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 ~~>  (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 ~~>  (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 ~~>  (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 ~~> (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, synsem:loc:cat:head:(prep,
                                   pform:to)).

to ~~> (word,
        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 ~~> (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 ~~> (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))]).



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




