% File: theory.pl (TRALE)
:- multifile '~~>'/2.
:- multifile '##'/2.
%:- multifile 'trace'/1.
:- multifile if/2.

:- [trale_home(tree_extensions)].

signature(signature).

%%% LEXICON

ppro_lex(Case,Per,Num,Gen) macro
(word, synsem:(category:(head:case:Case,
                         subcat:e_list),
               content:index:(person:Per,
                              number:Num,
			      gender:Gen))).

i ~~>  (@ppro_lex(nom,first,sing,_),
        synsem:(content:index:X,
                context:(backgr:[(speaker_rel,arg1:X)]))).

me ~~> (@ppro_lex((acc;dat),first,sing,_),
        synsem:(content:index:X,
                context:(backgr:[(speaker_rel,arg1:X)]))).

she ~~> (@ppro_lex(nom,third,sing,fem),
         synsem:(content:index:X,
 		 context:(backgr:[(female_rel,arg1:X)]))).

her ~~> (@ppro_lex((acc;dat),third,sing,fem),
         synsem:(content:index:X,
 		 context:(backgr:[(female_rel,arg1:X)]))).

the ~~>  synsem:category: (head:det,
                           subcat:e_list).

computer ~~>  synsem:(category: (head:noun,
                                  subcat: [(category: (head:det,
                                                      subcat:[]))]),
                       content:(index: (person:third,
                                        number:sing,
                                        gender:fem))).

milk ~~>  synsem:(category:(head:noun,
                             subcat:e_list),
                    content:(index:(person:third,
                                    number:sing))).

verb_lex(Subcat,Content) macro
(word, synsem:(category:(head:vform:bse,
			 subcat:Subcat),
	       content:Content)).

np_y(Case,Content) macro
(category:head:case:Case,
 content:Content).

walk ~~>  @verb_lex( [@np_y(nom,index:X)],
		     (walk_rel,
	              arg1:X) ).

love ~~>  @verb_lex( [@np_y(acc,index:Y),
                      @np_y(nom,index:X)],
                     (love_rel,
                      arg1:X,
                      arg2:Y) ).

give ~~> @verb_lex( [@np_y(dat,index:Z),
                     @np_y(acc,index:Y),
                     @np_y(nom,index:X)],
                    (give_rel,
                     arg1:X,
                     arg2:Y,
                     arg3:Z)).

think  ~~> @verb_lex( [(category:(head:vform:fin,
                                  subcat:[]),
                        content:Y),
                        @np_y(nom,index:X)],
                      (think_rel,
                       arg1:X,
                       arg2:Y) ).

to  ~~> (synsem:(category:(head:prep,
			   subcat:[@np_y(dat,Content)]),
		 content:Content)).

%%% PHRASE STRUCTURE RULES

head_comp_rule ##
(phrase, dtr1:Comp, dtr2:Head)
===>
cat> (Head, synsem:category:(head:prep ; subcat:tl:ne_list)),
cat> Comp.

subj_head_rule ##
(phrase, dtr1:Comp, dtr2:Head,
         synsem:category:subcat:[])
===>
cat> Comp,
cat> (Head, synsem:category:head:(vform:fin ; noun)).


%%% PRINCIPLES

% Semantics Principle
phrase *> (synsem:content:C, dtr2:synsem:content:C).

% HEAD Feature Principle
phrase *> (synsem:category:head:H, dtr2:synsem:category:head:H).

% SUBCAT Principle
phrase *> (synsem:category:subcat:Rest,
           dtr1:synsem:First,
           dtr2:synsem:category:subcat:[First|Rest]).

% Alternative SUBCAT Principle
%phrase *> (synsem:category:subcat:PhrSubcat,
%           dtr1:synsem:Synsem,
%           dtr2:synsem:category:subcat:HeadSubcat)
%goal
%   append([Synsem],PhrSubcat,HeadSubcat).

phrase *> (dtr1:synsem:category:subcat:[]).


%%% LEXICAL RULES

plural_lr ##
(synsem:(category:(head:(Head,noun),
		   subcat:[(Det,category:head:det)]),
	 content:index:SingInd))
  **>
(word, synsem:(category:(head:Head,
	        	 subcat:([Det] ; e_list)),
	       content:index:PlurInd))
if
  sg_to_pl(SingInd,PlurInd)
morphs
  X becomes (X,s).

first_sg_lr ##
(synsem:(category:(head:vform:bse,
		   subcat:Subcat),
	 content:Content,
	 context:Context))
**>
(synsem:(category:(head:vform:fin,
		   subcat:Subcat),
	 content:Content,
	 context:Context))
if check_subj(first,sing,Subcat)
morphs
X becomes X.

third_sg_lr ##
(synsem:(category:(head:vform:bse,
		   subcat:Subcat),
	 content:Content,
	 context:Context))
**>
(synsem:(category:(head:vform:fin,
		   subcat:Subcat),
	 content:Content,
	 context:Context))
if check_subj(third,sing,Subcat)
morphs
X becomes (X,s).

dat_alt_lr ##
@verb_lex( [@np_y(dat,index:Z),
	    @np_y(acc,index:Y)|Rest],
	   Content )
**>
@verb_lex( [@np_y(acc,index:Y),
	    (category:(head:prep,
		       subcat:[]),
             content:index:Z)|Rest],
	   Content )
morphs
  X becomes X.

%%% DEFINITE CLAUSES

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

check_subj(Person,Number,
	   [content:index:(person:Person,number:Number)])
if true.

check_subj(Person,Number,[_|Tail]) if
check_subj(Person,Number,Tail).

% relates singular INDEX to plural INDEX
sg_to_pl((person:Person, number:sing, gender:Gender),
	 (person:Person, number:plur, gender:Gender))
if true.


