1/* @(#)slots.pl	24.1 2/23/88 */
    2
    3/* 
    4	Copyright 1986, Fernando C.N. Pereira and David H.D. Warren,
    5
    6			   All Rights Reserved
    7*/
    8i_sentence(q(S),question([],P)) :-
    9   i_s(S,P,[],0).
   10i_sentence(whq(X,S),question([X],P)) :-
   11   i_s(S,P,[],0).
   12i_sentence(imp(s(_,Verb,VArgs,VMods)),imp(V,Args)) :-
   13   i_verb(Verb,V,_,active,pos,Slots0,[],transparent),
   14   i_verb_args(VArgs,[],[],Slots0,Slots,Args,Args0,Up,-0),
   15   conc(Up,VMods,Mods),
   16   i_verb_mods(Mods,_,[],Slots,Args0,Up,+0).
   17
   18i_np(there,Y,quant(void,X,~true,~true,[],Y),[],_,_,XA,XA).
   19i_np(NP,Y,Q,Up,Id0,Index,XA0,XA) :-
   20   i_np_head(NP,Y,Q,Det,Det0,X,Pred,QMods,Slots0,Id0),
   21   held_arg(XA0,XA,Slots0,Slots,Id0,Id),
   22   i_np_rest(NP,Det,Det0,X,Pred,QMods,Slots,Up,Id,Index).
   23
   24i_np_head(np(_,Kernel,_),Y,
   25      quant(Det,T,Head,Pred0,QMods,Y),
   26      Det,Det0,X,Pred,QMods,Slots,Id) :-
   27   i_np_head0(Kernel,X,T,Det0,Head,Pred0,Pred,Slots),
   28   Type-_=Y, Type-_=T.
   29
   30i_np_rest(np(_,_,Mods),Det,Det0,X,Pred,QMods,Slots,Up,Id,Index) :-
   31   index_args(Det0,Index,Id,Det,IndexA),
   32   i_np_mods(Mods,X,Slots,Pred,QMods,Up,Id,IndexA).
   33
   34held_arg(held_arg(Case,-Id,X),[],S0,S,Id,+Id) :-
   35   in_slot(S0,Case,X,Id,S,_).
   36held_arg(XA,XA,S,S,Id,Id).
   37
   38i_np_head0(np_head(Det,Adjs,Noun),X,T,Det,Head0,Pred0,Pred,Slots) :-
   39   i_adjs(Adjs,X,T,X,Head0,Head,Pred0,Pred),
   40   i_noun(Noun,X,Head,Slots).
   41i_np_head0(np_head(int_det(V),Adjs,Noun),
   42      Type-X,Type-X,Det,~true,Pred,Pred,
   43      [slot(prep(of),Type,X,_,comparator)]) :-
   44   comparator(Noun,Type,V,Adjs,Det).
   45i_np_head0(np_head(quant(Op0,N),Adjs,Noun),
   46      Type-X,Type-X,void,~P,Pred,Pred,[]) :-
   47   measure(Noun,Type,Adjs,Units),
   48   conversion(N,Op0,Type,V,Op),
   49   measure_op(Op,X,V--Units,P).
   50i_np_head0(name(Name),
   51      Type-Name,Type-Name,id,~true,Pred,Pred,[]) :-
   52   name_template(Name,Type).
   53i_np_head0(wh(X),X,X,id,~true,Pred,Pred,[]).
   54
   55i_np_mods(Mods,_,[],~true,[],Mods,_,_).
   56i_np_mods([Mod|Mods],X,Slots0,Pred0,QMods0,Up,Id,Index) :-
   57   i_np_mod(Mod,X,Slots0,Slots,
   58            Pred0,Pred,QMods0,QMods,Up0,-Id,Index),
   59   conc(Up0,Mods,Mods0),
   60   i_np_mods(Mods0,X,Slots,Pred,QMods,Up,+Id,Index).
   61i_np_mods(Mods,_,[Slot|Slots],~true,QMods,Mods,Id,_) :-
   62   i_voids([Slot|Slots],QMods,Id).
   63
   64i_voids([],[],_).
   65i_voids([Slot|Slots],[quant(void,X,~true,~true,[],_)|QMods],Id) :-
   66   nominal_slot(Slot,X,-Id), !,
   67   i_voids(Slots,QMods,+Id).
   68i_voids([_|Slots],QMods,Id) :-
   69   i_voids(Slots,QMods,Id).
   70
   71i_rel(rel(X,S),X,P&Pred,Pred,QMods,QMods,Up,Id) :-
   72   i_s(S,P,Up,Id).
   73i_rel(reduced_rel(X,S),X,Pred,Pred,[A|QMods],QMods,Up,Id) :-
   74   i_s(S,A,Up,Id).
   75i_rel(conj(Conj,Left,Right),X,
   76      conj(Conj,LPred,LQMods,RPred,RQMods)&Pred,Pred,
   77      QMods,QMods,Up,Id) :-
   78   i_rel(Left,X,LPred,~true,LQMods,[],[],-Id),
   79   i_rel(Right,X,RPred,~true,RQMods,[],Up,+Id).
   80
   81i_np_mod(pp(Prep,NP),
   82      X,Slots0,Slots,Pred,Pred,[QMod|QMods],QMods,Up,Id0,Index0) :-
   83   i_np_head(NP,Y,Q,LDet,LDet0,LX,LPred,LQMods,LSlots0,Id0),
   84   i_bind(Prep,Slots0,Slots1,X,Y,Id0,Function,P,PSlots,XArg),
   85   conc(PSlots,Slots1,Slots),
   86   i_np_modify(Function,P,Q,QMod,Index0,Index),
   87   held_arg(XArg,[],LSlots0,LSlots,Id0,Id),
   88   i_np_rest(NP,LDet,LDet0,LX,LPred,LQMods,LSlots,Up,Id,Index).
   89i_np_mod(Mod,X,Slots,Slots,Pred0,Pred,QMods0,QMods,Up,Id,_) :-
   90   i_rel(Mod,X,Pred0,Pred,QMods0,QMods,Up,Id).
   91
   92i_noun(Noun,Type-X,P,Slots) :-
   93   noun_template(Noun,Type,X,P,Slots).
   94
   95i_bind(Prep,Slots0,Slots,_,X,Id,arg,P,[],[]) :-
   96   in_slot(Slots0,Case,X,Id,Slots,P),
   97   deepen_case(Prep,Case).
   98i_bind(prep(Prep),Slots,Slots,X,Y,_,adjoin,~P,PSlots,XArg) :-
   99   i_adjoin(Prep,X,Y,PSlots,XArg,P).
  100
  101i_np_modify(adjoin,P,N,N&P,_,unit).
  102i_np_modify(arg,F,N,N,Index0,Index) :-
  103   index_slot(F,Index0,Index).
  104
  105in_slot([Slot|Slots],Case,X,Id,Slots,F) :-
  106   slot_match(Slot,Case,X,Id,F).
  107in_slot([Slot|Slots0],Case,X,Id,[Slot|Slots],F) :-
  108   in_slot(Slots0,Case,X,Id,Slots,F).
  109
  110slot_match(slot(Case,Type,X,Id,F),Case,Type-X,Id,F).
  111
  112i_adjs([],X,T,T,Head,Head,Pred,Pred).
  113i_adjs([Adj|Adjs],X,T,T0,Head0,Head,Pred0,Pred) :-
  114   i_adj(Adj,X,T,T1,Head0,Head1,Pred0,Pred1),
  115   i_adjs(Adjs,X,T1,T0,Head1,Head,Pred1,Pred).
  116
  117i_adj(adj(Adj),Type-X,T,T,Head,Head,~P&Pred,Pred) :-
  118   restriction(Adj,Type,X,P).
  119i_adj(adj(Adj),TypeX-X,TypeV-V,_,
  120   aggr(F,V,[X],Head,Pred),Head,~true,Pred) :-
  121   aggr_adj(Adj,TypeV,TypeX,F).
  122i_adj(sup(Op0,adj(Adj)),Type-X,Type-V,_,
  123      aggr(F,V,[Y,X],Head,~P&Pred),Head,~true,Pred) :-
  124   chat_sign(Adj,Sign),
  125   inverse(Op0,Sign,Op),
  126   i_sup_op(Op,F),
  127   attribute(Adj,Type,X,_,Y,P).
  128i_adj(adj(Adj),TypeX-X,T,T,_,
  129      Head,Head,quant(void,TypeX-Y,~P,~Q&Pred,[],_),Pred) :-
  130   attribute(Adj,TypeX,X,_,Y,P),
  131   standard(Adj,TypeX,Y,Q).
  132
  133i_s(s(Subj,Verb,VArgs,VMods),Pred,Up,Id) :-
  134   i_verb(Verb,P,Tense,Voice,Neg,Slots0,XA0,Meta),
  135   i_subj(Voice,Subj,Slots0,Slots1,QSubj,SUp,-(-Id)),
  136   conc(SUp,VArgs,TArgs),
  137   i_verb_args(TArgs,XA0,XA,Slots1,Slots,Args0,Args,Up0,+(-Id)),
  138   conc(Up0,VMods,Mods),
  139   i_verb_mods(Mods,Tense,XA,Slots,Args,Up,+Id),
  140   reshape_pred(Meta,QSubj,Neg,P,Args0,Pred).
  141
  142i_verb(verb(Root,Voice,Tense,Aspect,Neg),
  143      P,Tense,Voice,Det,Slots,XArg,Meta) :-
  144   verb_template(Root,P,Slots,XArg,Meta),
  145   i_neg(Neg,Det).
  146
  147reshape_pred(transparent,S,N,P,A,pred(S,N,P,A)).
  148reshape_pred(have,Subj,Neg,Verb0,
  149      [quant(Det,X,Head0,Pred,QArgs,Y)|MRest],
  150      pred(Subj,Neg,Verb,[quant(Det,X,Head,Pred,QArgs,Y)|MRest])) :-
  151   have_pred(Head0,Verb0,Head,Verb).
  152
  153have_pred(~Head,Verb,~true,(Head,Verb)).
  154have_pred(Head,Verb,Head,Verb) :-
  155   meta_head(Head).
  156
  157meta_head(apply(_,_)).
  158meta_head(aggr(_,_,_,_,_)).
  159
  160i_neg(pos,id).
  161i_neg(neg,not).
  162
  163i_subj(Voice,Subj,Slots0,Slots,Quant,Up,Id) :-
  164   subj_case(Voice,Case),
  165   verb_slot(arg(Case,Subj),[],[],Slots0,Slots,[Quant],[],Up,Id).
  166
  167i_verb_args(VArgs,XA0,XA,Slots0,Slots,Args0,Args,Up,Id) :-
  168   fill_verb(VArgs,XA0,XA,Slots0,Slots,Args0,Args,Up,Id).
  169
  170subj_case(active,subj).
  171subj_case(passive,s_subj).
  172
  173fill_verb([],XA,XA,Slots,Slots,Args,Args,[],_).
  174fill_verb([Node|Nodes0],XA0,XA,Slots0,Slots,Args0,Args,Up,Id) :-
  175   verb_slot(Node,XA0,XA1,Slots0,Slots1,Args0,Args1,Up0,-Id),
  176   conc(Up0,Nodes0,Nodes),
  177   fill_verb(Nodes,XA1,XA,Slots1,Slots,Args1,Args,Up,+Id).
  178
  179verb_slot(pp(Prep,NP),
  180      XArg0,XArg,Slots0,Slots,[Q|Args],Args,Up,Id) :-
  181   i_np(NP,X,Q,Up,Id,unit,XArg0,XArg),
  182   in_slot(Slots0,Case,X,Id,Slots,_),
  183   deepen_case(Prep,Case).
  184verb_slot(void,XA,XA,Slots,Slots,Args,Args,[],_) :-
  185   in_slot(Slots,pred,_,_,_,_).
  186verb_slot(pp(prep(Prep),NP),
  187      TXArg,TXArg,Slots0,Slots,[Q& ~P|Args],Args,Up,Id0) :-
  188   in_slot(Slots0,pred,X,Id0,Slots1,_),
  189   i_adjoin(Prep,X,Y,PSlots,XArg,P),
  190   i_np_head(NP,Y,Q,LDet,LDet0,LX,LPred,LQMods,LSlots0,Id0),
  191   held_arg(XArg,[],LSlots0,LSlots,Id0,Id),
  192   i_np_rest(NP,LDet,LDet0,LX,LPred,LQMods,LSlots,Up,Id,free),
  193   conc(PSlots,Slots1,Slots).
  194verb_slot(arg(SCase,NP),
  195      XArg0,XArg,Slots0,Slots,[Q|Args],Args,Up,Id) :-
  196   i_np(NP,X,Q,Up,Id,unit,XArg0,XArg),
  197   in_slot(Slots0,Case,X,Id,Slots,_),
  198   deepen_case(SCase,Case).
  199verb_slot(adverb(Adv),XA,XA,Slots0,Slots,[~P|Args],Args,[],Id) :-
  200   adv_template(Adv,Case,X,P),
  201   in_slot(Slots0,Case,X,Id,Slots,_).
  202verb_slot(arg(pred,AP),XA,XA,Slots0,Slots,Args0,Args,Up,Id) :-
  203   in_slot(Slots0,pred,X,Id,Slots,_),
  204   i_pred(AP,X,Args0,Args,Up,Id).
  205
  206i_pred(conj(Conj,Left,Right),X,
  207      [conj(Conj,~true,LQMods,~true,RQMods)|QMods],
  208      QMods,Up,Id) :-
  209   i_pred(Left,X,LQMods,[],[],-Id),
  210   i_pred(Right,X,RQMods,[],Up,+Id).
  211i_pred(AP,T,[~Head&Pred|As],As,[],_) :-
  212   i_adj(AP,T,_,_,Head,true,Pred,~true).
  213i_pred(value(adj(Adj),wh(TypeY-Y)),Type-X,[~H|As],As,[],_) :-
  214   attribute(Adj,Type,X,TypeY,Y,H).
  215i_pred(comp(Op0,adj(Adj),NP),X,[P1 & P2 & ~P3,Q|As],As,Up,Id) :-
  216   i_np(NP,Y,Q,Up,Id,unit,[],[]),
  217   chat_sign(Adj,Sign),
  218   i_measure(X,Adj,Type,U,P1),
  219   i_measure(Y,Adj,Type,V,P2),
  220   inverse(Op0,Sign,Op),
  221   measure_op(Op,U,V,P3).
  222i_pred(pp(prep(Prep),NP),X,[~H,Q|As],As,Up,Id) :-
  223   i_np(NP,Y,Q,Up,Id,unit,[],[]),
  224   adjunction(Prep,X,Y,H).
  225
  226i_adjoin(with,TS-S,TV-Y,[slot(prep(of),TV,Z,_,free)],
  227	held_arg(poss,-Id,TS-S),
  228	Y=Z).
  229i_adjoin(Prep,X,Y,[],[],P) :-
  230   adjunction(Prep,X,Y,P).
  231
  232i_measure(Type-X,Adj,Type,X,~true) :-
  233   units(Adj,Type).
  234i_measure(TypeX-X,Adj,TypeY,Y,quant(void,TypeY-Y,~P,~true,[],_)) :-
  235   attribute(Adj,TypeX,X,TypeY,Y,P).
  236
  237i_verb_mods(Mods,_,XA,Slots0,Args0,Up,Id) :-
  238   fill_verb(Mods,XA,[],Slots0,Slots,Args0,Args,Up,-Id),
  239   i_voids(Slots,Args,+Id).
  240
  241nominal_slot(slot(Kind,Type,X,Id,_),Type-X,Id) :-
  242   nominal_kind(Kind).
  243
  244nominal_kind(prep(_)).
  245nominal_kind(poss).
  246nominal_kind(subj).
  247nominal_kind(dir).
  248nominal_kind(ind).
  249
  250i_sup_op(least,min).
  251i_sup_op(most,max).
  252
  253conversion(wh(Type-X),same,Type,X,id).
  254conversion(nb(N),Op,_,N,Op).
  255
  256measure_op(id,X,X,true).
  257measure_op(same,X,Y,X=Y).
  258measure_op(less,X,Y,exceeds(Y,X)).
  259measure_op(not+less,X,Y,\+exceeds(Y,X)).
  260measure_op(more,X,Y,exceeds(X,Y)).
  261measure_op(not+more,X,Y,\+exceeds(X,Y)).
  262
  263inverse(most,-,least).
  264inverse(least,-,most).
  265inverse(same,-,same).
  266inverse(less,-,more).
  267inverse(more,-,less).
  268inverse(X,+,X).
  269
  270noun_template(Noun,TypeV,V,~P,
  271      [slot(poss,TypeO,O,Os,index)|Slots]) :-
  272   property(Noun,TypeV,V,TypeO,O,P,Slots,Os,_).
  273noun_template(Noun,TypeV,V,aggr(F,V,[],~true,~true),
  274   [slot(prep(of),TypeS,_,_,free)]) :-
  275   aggr_noun(Noun,TypeV,TypeS,F).
  276noun_template(Noun,Type,X,~P,Slots) :-
  277   thing(Noun,Type,X,P,Slots,_).
  278noun_template(Noun,TypeV,V,apply(F,P),
  279      [slot(prep(of),TypeX,X,_,apply)]) :-
  280   meta_noun(Noun,TypeV,V,TypeX,X,P,F).
  281
  282verb_template(have,Y=Z,
  283		[slot(subj,TypeS,S,-Id,free),
  284		 slot(dir,TypeV,Y,_,free),
  285		 slot(prep(of),TypeV,Z,_,free)],
  286		held_arg(poss,-(-(+Id)),TypeS-S), have).
  287verb_template(have,Y=Z,
  288	[slot(subj,TypeS,S,-(-(Id)),free),
  289	 slot(dir,TypeV,Y,_,free),
  290	 slot(prep(as),TypeV,Z,_,free)],
  291	held_arg(poss,-(-(-(+Id))),TypeS-S), have).
  292verb_template(Verb,Pred,
  293      [slot(subj,TypeS,S,_,free)|Slots],[],transparent) :-
  294   verb_type(Verb,_+Kind),
  295   verb_kind(Kind,Verb,TypeS,S,Pred,Slots).
  296
  297verb_kind(be,_,TypeS,S,S=A,[slot(dir,TypeS,A,_,free)]).
  298verb_kind(be,_,TypeS,S,true,[slot(pred,TypeS,S,_,free)]).
  299verb_kind(intrans,Verb,TypeS,S,Pred,Slots) :-
  300   intrans(Verb,TypeS,S,Pred,Slots,_).
  301verb_kind(trans,Verb,TypeS,S,Pred,
  302      [slot(dir,TypeD,D,SlotD,free)|Slots]) :-
  303   trans(Verb,TypeS,S,TypeD,D,Pred,Slots,SlotD,_).
  304verb_kind(ditrans,Verb,TypeS,S,Pred,
  305      [slot(dir,TypeD,D,SlotD,free),
  306       slot(ind,TypeI,I,SlotI,free)|Slots]) :-
  307   ditrans(Verb,TypeS,S,TypeD,D,TypeI,I,Pred,Slots,SlotD,SlotI,_).
  308
  309deepen_case(prep(at),time).
  310deepen_case(s_subj,dir).
  311deepen_case(s_subj,ind).
  312deepen_case(prep(by),subj).
  313deepen_case(prep(to),ind).
  314deepen_case(prep(of),poss).
  315deepen_case(X,X).
  316
  317% ================================================================
  318% Determiner Indexing Table
  319
  320index_slot(index,I,I).
  321index_slot(free,_,unit).
  322index_slot(apply,_,apply).
  323index_slot(comparator,_,comparator).
  324
  325index_args(det(the(plu)),unit,I,set(I),index(I)) :- !.
  326index_args(int_det(X),index(I),_,int_det(I,X),unit) :- !.
  327index_args(generic,apply,_,lambda,unit) :-!.
  328index_args(D,comparator,_,id,unit) :-
  329 ( indexable(D); D=generic), !.
  330index_args(D,unit,_,D,unit) :- !.
  331index_args(det(D),I,_,I,I) :-
  332   indexable(D),
  333   my_index(I), !.
  334index_args(D,I,_,D,I).
  335
  336indexable(the(plu)).
  337indexable(all).
  338
  339my_index(index(I)).
  340
  341% ================================================================
  342% Utilities
  343
  344conc([],L,L).
  345conc([X|L1],L2,[X|L3]) :-
  346   conc(L1,L2,L3)