all_query(Sentence) :-
  query(Sentence, Parse), 
  format("~n ~p.", [Parse]), 
  fail.
all_query(_Sentence).

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

test('Bill kissed Hillary',
      (f2: bill, 
       f3: hillary,
       (agent: (f1, \X) -* (theme:(f1, \Y) -*  f4: kiss(X,Y))),
       (f2: \A -* (f3 : \B -* (agent:(f1, A), theme:(f1, B))))
      ),
      f4:_).

  %
test('Bill obviously kissed Hillary',
       (f2: bill, 
       f3: hillary,
       (agent: (f1, \X) -* (theme:(f1, \Y) -*  f4: kiss(X,Y))),
       (f4: \P -* f4 : obviously(P)),
       (f2: \A -* (f3 : \B -* (agent:(f1, A), theme:(f1, B))))
      ),
      f4:_).

   % Hillary let Bill write a letter.  
test('Hillary let Bill write a letter',
       (f2: bill, 
       f3: hillary,
       f4: letter,
       (agent: (f1, \X) -* (theme:(f1, \Y) -*  f5: write(X,Y))),
       (permitter: (f1, \P) -* (f5: \Q -*  f5: let(P,Q))),
       (f2: \A -* (f3 : \B -* (f4 : \C -* (permitter:(f1, A), agent:(f1, B), theme:(f1,C)))))
      ),
      f5:_).

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

test('Bill kissed a girl',
      (f3: bill, 
       (f3: \X -* (f4: \Q -*  f1: kiss(X,Q))),
       Y^(f7:Y, f4:Y, (f6: (\R @ Y)) -* (f1: (\S @ Y) -* f1: a(z, R@z, S@z))),
       (f7: \Girl -* f6: girl(Girl))
      ),
      f1:_).

test('Bill kissed a clever girl',
      (f3: bill, 
       (f3: \X -* (f4: \Q -*  f1: kiss(X,Q))),
       Y^(f7:Y, f4:Y, (f6: (\R @ Y)) -* (f1: (\S @ Y) -* f1: a(z, R@z, S@z))),
       (f6: \Pred -* f6: clever(Pred)),
       (f7: \Girl -* f6: girl(Girl))
      ),
      f1:_).

test('Every man kissed a girl',
      (Q^(f2:Q, f3:Q, (f8: (\R1 @ Q)) -* (f1: (\S1 @ Q) -* f1: every(y, R1@y, S1@y))),
       (f2: \Man -* f8: man(Man)),
       (f3: \X -* (f4: \Q1 -*  f1: kiss(X,Q1))),
       Y^(f7:Y, f4:Y, (f6: (\R @ Y)) -* (f1: (\S @ Y) -* f1: a(z, R@z, S@z))),
       (f7: \Girl -* f6: girl(Girl))
      ),
      f1:_).


test('Every man saw a friend of his',
% every
      (q^(f2:q, f3:q, (f8: (\R1 @ q)) -* (f1: (\S1 @ q) -* f1: every(y, R1@y, S1@y))),
% man and antecedent of his
       (f2: \Man -* (f8: man(Man), f9: Man)),
%saw
       (f3: \X -* (f4: \Q1 -*  f1: see(X,Q1))),
%a
       yy^(f7:yy, f4:yy, (f6: (\R @ yy)) -* (f1: (\S @ yy) -* f1: a(z, R@z, S@z))),
%friend of
       (f7: \Friend -* (f9: \SomeOne -* f6: friend_of(Friend,SomeOne)))
      ),
      f1:_).

