/* Test sentences for LFG-semantics via Constraints paper.
Authors: Dalrymple, Lamping, Pereira, Saraswat
Copyright: (C) Xerox Corporation, AT&T 1993
File: test5.pl
Last Modified: Sat May 15 11:00:52 1993

*/

all_queries :-
  test(Sentence, A, Parse),
  format("~n~p:", [Sentence]),
  lj(A, [Parse]),
  format("~n    ~p.", [Parse]), 
  fail.
all_queries.

query(Sentence, Parse) :- 
  test(Sentence, A, Parse),
  lj(A, [Parse]).

/* ------ LEXICON and Thematic Principles --------------- */

noun(Noun, Target, Target:Noun).
common_noun(Noun, Source, Target, (Source: \Var -* Target: Phrase)):-
    Phrase =..[Noun, Var].

agent_theme(Verb, Source, Target, 
             (agent:(Source, \X) -*  (theme:(Source, \Y) -* Target:Phrase))):-
       Phrase =.. [Verb, X, Y].

map_to_agent_theme(Agent, Theme, Target,
       (Agent : \B -* (Theme : \C -* 
         (agent:(Target, B), theme:(Target,C))))
      ).

map_to_permitter_agent_theme(Permitter, Agent, Theme, Target,
       (Permitter: \A -* (Agent : \B -* (Theme : \C -* 
         (permitter:(Target, A), agent:(Target, B), theme:(Target,C)))))
      ).

modifier(Modifier, Subject, (Subject: \P -* Subject: Phrase)):-
    Phrase =.. [Modifier, P].

let(Let_er, Let_ee, 
    (permitter: (Let_er, \P) -* (Let_ee: \Q -*  Let_ee: let(P,Q)))).

quantifier(Quant, Restr_src, Scope_src, Restr_target, Meaning, Y, Z,
      (Y^(Restr_src:Y, (Restr_target : (\R @ Y) -* 1)),
       Z^(Scope_src:Z, (Meaning : (\S @ Z) -* Meaning:Phrase)))) :-
  Phrase =.. [Quant, V, R@V, S@V].

transitive_verb(Verb, Subj, Obj, Target,
       (Subj: \X -* (Obj: \Q -*  Target: Phrase))) :-
     Phrase =.. [Verb, X, Q].

/* --------------------------------------------- */
test('Bill kissed Hillary', 
      (Bill, Hillary, Kiss, Agent_theme),  f4:_) :-
   noun(bill, f2, Bill),
   noun(hillary, f3, Hillary),
   agent_theme(kiss, f1, f4, Kiss),
   map_to_agent_theme(f2, f3, f1, Agent_theme).

test('Bill obviously kissed Hillary',
      (Bill, Obviously, Kissed, Hillary, Agent_theme),
      f4:_) :-
   noun(bill, f2, Bill),
   modifier(obviously, f4, Obviously),
   agent_theme(kiss, f1, f4, Kissed),
   map_to_agent_theme(f2, f3, f1, Agent_theme),
   noun(hillary, f3, Hillary).


test('Hillary let Bill write a letter',
       (Hillary, Let, Bill, Write, Letter, Permitter_agent_theme),
      f5:_):-
    noun(hillary, f3, Hillary),
    noun(bill, f2, Bill),
    noun(letter, f4, Letter),
    let(f1, f5, Let),
    agent_theme(write, f1, f5, Write),
    map_to_permitter_agent_theme(f2, f3, f4, f1, Permitter_agent_theme).

%% Mary, you should convert this to using thematic principles.

test('Bill kissed a girl',
      (Bill, Kiss,  A, Girl),
      f1:_):-
  noun(bill, f3, Bill), 
  transitive_verb(kiss, f3, f4, f1, Kiss),
  quantifier(a, f7, f4, f6, f1, q1, q2, A),
  common_noun(girl, f7, f6, Girl).

test('Bill kissed a clever girl',
      (Bill, Kiss, A,  Clever, Girl),
      f1:_) :-
  noun(bill, f3, Bill), 
  transitive_verb(kiss, f3, f4, f1, Kiss),
  quantifier(a, f7, f4, f6, f1, q1, q2, A),
  modifier(clever, f6, Clever),
  common_noun(girl, f7, f6, Girl).

test('Every man kissed a girl',
      (Every, Man, Kiss, A, Girl), 
      f1:_):- 
   quantifier(every, f2, f3, f8, f1, q1, q2, Every),
   common_noun(man, f2, f8, Man),
   transitive_verb(kiss, f3, f4, f1, Kiss),
   quantifier(a, f7, f4, f6, f1, q3, q4, A),
   common_noun(girl, f7, f6, Girl).

test('Every man saw a friend of his',
      (Every,
% man 
       (f2: \Man -* f8: man(Man)),
       Saw, A, 
%friend of
       (f7: \Friend -* (f9: \SomeOne -* f6: friend_of(Friend,SomeOne))),
% his
       (f3: \X -* (f3:X, f9:X))
      ),
      f1:_) :-
   quantifier(every, f2, f3, f8, f1, q1, q2, Every),
   transitive_verb(saw, f3, f4, f1, Saw),
   quantifier(a, f7, f4, f6, f1, q3, q4, A).

