% Subcategorization, Number, Case
% Baumstruktur als Parserausgabe
% inkl. exemplarischer Lexikalischer Regel zur Pluralbildung bei Nomen


% Regeln
% ------

s(s(NP,VP)) --> np(NP,Number,nom), vp(VP,Number).

vp(vp(V),Number)         --> v(1, V, Number).
vp(vp(V,NP),Number)      --> v(2, V, Number), np(NP,_,acc).
vp(vp(V,NP1,NP2),Number) --> v(3, V, Number), np(NP1,_,acc), np(NP2,_,acc).
vp(vp(V,S),Number)       --> v(4, V, Number), s(S).


np(np(Pron),Number,Case)    --> pron(Pron,Number, Case).
np(np(D,N),Number,_Case)    --> d(Number,D), n(Number,N).



% Lexikon
% -------

% Nomen: Interfaceregel zum Lexikon

n(Num, n(N)) --> lookup(N), {noun(N, Num)}, [N].

% Nomen: Lexikon

noun(butler, singular).
noun(cat, singular).
noun(dog, singular).
noun(garden, singular).
noun(gardener, singular).
noun(mouse, singular).
noun(policeman, singular).

% Nomen: Lexikalische Regel zur Pluralbildung
% hier nicht ausgeschlossen: *policemans, *mouses

noun(Noun,plural) :-
	name(Noun,CharsL),
	append(BaseL,[115],CharsL),
	name(Noun_sing,BaseL),
	noun(Noun_sing,singular).

% 'irreguläre' Pluralformen

noun(mice, plural).
noun(policemen, plural).


% Einfaches DCG-Lexikon für übrige lexikalische Kategorien

d(_, d(the))       --> [the].
d(singular, d(a))  --> [a].
d(plural, d(d0))   --> [].

pron(pron(String), singular, nom) --> lookup(String), ([he]; [she]).
pron(pron(String), singular, acc) --> lookup(String), ([him]; [her]). 
pron(pron(they), plural, nom)     --> [they]. 
pron(pron(them), plural, acc)     --> [them]. 

v(1, v(S), singular) --> lookup(S), ([barks]; [sleeps]).
v(1, v(S), plural)   --> lookup(S), ([bark]; [sleep]).
v(1, v(S), _)        --> lookup(S), ([barked]; [slept]).
v(2, v(S), singular) --> lookup(S), ([chases]; [sees]).
v(2, v(S), plural)   --> lookup(S), ([chase]; [see]).
v(2, v(S), _)        --> lookup(S), ([chased]; [saw]).
v(3, v(S), singular) --> lookup(S), ([gives]; [sells]).
v(3, v(S), plural)   --> lookup(S), ([give]; [sell]).
v(3, v(S), _)        --> lookup(S), ([gave]; [sold]).
v(4, v(S), singular) --> lookup(S), ([says]; [thinks]).
v(4, v(S), plural)   --> lookup(S), ([say]; [think]).
v(4, v(S), _)        --> lookup(S), ([said]; [thought]).


lookup(A,[A|B],[A|B]).

append([X|Xs],Ys,[X|Zs]) :-
	append(Xs,Ys,Zs).
append([],Xs,Xs).


% --------------------------------------------------------

parse(List,Tree) :- s(Tree,List,[]).
