% file: xgrammar
% author: Edward P. Stabler, Jr.
% examples: s([every,man,reads,the,book]).
%           s([who,reads,every,book]).
%  	    s([what,the,man,likes]).
%           s([what,the,man,who,likes,reads,the,book]).  (island violation)
%
% Notes: H0 and H (HOLD, Hole) are lists such that H0 is the list of unplaced
% wh-words found earlier in the string, and H is the list of wh-words that 
% still need to be placed somewhere later in the string.
% as set up now, has Ed's rendition of Pereira's Complex NP Constraint

s(S) :- s(S,[],[],[]).
s(S) :- cp(S,[],[],[]).

cp([who|S0],S,H0,H) :-
    s(S0,S,[who|H0],H).
cp([what|S0],S,H0,H) :-
    s(S0,S,[what|H0],H).

s(S0,S,H0,H) :-
    np(S0,S1,H0,H1),
    vp(S1,S,H1,H).

vp(S0,S,H0,H) :-
    v(S0,S1,H0,H1),
    np(S1,S,H1,H).

v([reads|S],S,H,H).
v([likes|S],S,H,H).

np(S0,S,H0,H) :-
    det(S0,S1,H0,H1),
    noun(S1,S,H1,H).
np(S0,S,H0,H) :-
    det(S0,S1,H0,H1),
    noun(S1,S2,H1,H2),
    rel(S2,S,H2,H).
np(S,S,[what|H],H).
np(S,S,[who|H],H).

det([the|S],S,H,H).
det([every|S],S,H,H).
det([some|S],S,H,H).
det([no|S],S,H,H).

noun([woman|S],S,H,H).
noun([man|S],S,H,H).
noun([book|S],S,H,H).

% use these instead of the next two rules if Ss with island violations
% are to be generated
% rel([who|S0],S,H0,H) :-
%    s(S0,S,[who|H0],H).
% rel([that|S0],S,H0,H) :-
%    s(S0,S,[that|H0],H).
    
% the following two rules block complex NP constraint violations
rel([who|S0],S,H0,H) :-
    s(S0,S,[who,'*'|H0],['*'|H]).
rel([that|S0],S,H0,H) :-
    s(S0,S,[that,'*'|H0],['*'|H]).


