/* Test sentences for the papers 
    (1) LFG-semantics via Constraints 
    (2) A deductive account of quantification in LFG

Authors: Dalrymple, Lamping, Pereira, Saraswat
Copyright: (C) Xerox Corporation, AT&T 1993
File: test6.pl
Last Modified: Sat May 15 22:33:50 1993

This version contains quantifiers in the nested implication
style.

*/
:- prolog_flag(compiling, _, fastcode).
all_queries :-
  statistics(runtime, _P),
  test(Sentence, A, Parse),
  format("~n~p:", [Sentence]),
  lj(A, [Parse]),
  format("~n    ~p.", [Parse]), 
  fail.
all_queries :- statistics(runtime, Q), format("~n Time: ~p.", [Q]).

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

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

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

relational_noun(Noun, Arg1, Arg2, Target, P1$(var(Arg1): P1 -* P2$(Arg2: P2 -* Target:Phrase))):-
    Phrase =..[Noun, P1, P2].

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

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

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

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

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

quantifier(Quant, Scope_src, Restr_target, Meaning, Y, Z, 
           R$S$((Z$(Scope_src:Z -* Meaning: (S @ Z)))
                    -* (Y$(var(Scope_src): Y -* Restr_target: (R@Y)))
                    -* Meaning: Phrase)) :-
  Phrase =.. [Quant, V, R@V, S@V].

transitive_verb(Verb, Subj, Target,
       X$Q$(agent(Subj): X -* (theme(Subj): Q -*  Target: Phrase))) :-
     Phrase =.. [Verb, X, Q].

his(Source, Target, X$(Source: X -* (Source:X, Target:X))).

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

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

test('Bill let Hillary draft plans',
       (Bill, Let, Hillary, Draft, Plans, Permitter_agent_theme),
      f5:_):-
    noun(hillary, f3, Hillary),
    noun(bill, f2, Bill),
    noun(plans, f4, Plans),
    let(f1, f5, Let),
    agent_theme(draft, f1, f5, Draft),
    map_to_permitter_agent_theme(f2, f3, f4, f1, Permitter_agent_theme).

test('Bill convinced every voter', (Bill, Convinced, Every, Voter, Map), f1:_) :-
  noun(bill, f3, Bill), 
  transitive_verb(convinced, f2, f1, Convinced),
  quantifier(every, f4, f5, f1, var1, var2, Every),
  common_noun(voter, f4, f5, Voter),
  map_to_agent_theme(f3, f4, f2, Map).  

test('Bill convinced every clever voter', (Bill, Convinced, Every, Clever, Voter, Map), f1:_) :-
  noun(bill, f3, Bill), 
  transitive_verb(convinced, f2, f1, Convinced),
  quantifier(every, f4, f5, f1, var1, var2, Every),
  common_noun(voter, f4, f5, Voter),
  modifier(clever, f5, Clever),
  map_to_agent_theme(f3, f4, f2, Map).  

test('Every candidate appointed a manager', (Every, Candidate, Appointed, A, Manager, Map), f1:_):- 
   quantifier(every, f3, f4, f1, var1, var2, Every),
   common_noun(candidate, f3, f4, Candidate),
   transitive_verb(appointed, f2, f1, Appointed),
   quantifier(a, f5, f6, f1, var3, var4, A),
   common_noun(manager, f5, f6, Manager),
   map_to_agent_theme(f3, f5, f2, Map).

test('Every candidate appointed an admirer of his', 
      (Every, Candidate, Appointed, An, Admirer_of, His, Map), f1:_) :-
   quantifier(every, f2, f3, f1, var1, var2, Every),
   common_noun(candidate, f2, f3,  Candidate),
   transitive_verb(appointed, f7, f1, Appointed),
   quantifier(an, f4, f5, f1, var3, var4, An),
   relational_noun(admirer_of, f4, f6, f5, Admirer_of),
   his(f2, f6, His),
   map_to_agent_theme(f2, f4, f7, Map).



