% Sean Brennan  <sbrennan@cs.unm.edu>
% Estonian Language Context-Sensitive Parser in Prolog

% Ignore non-latin orthography (,,,)
% N.B.: in Estonian, there are:
%	no articles
%	interrogatives (question words)
%	lots and lots of conjugations not covered here


utterance(X) :- sentence(X,[]).

sentence(Start, End) :-
    interrogative(Start, More), 
    nounphrase(More, Rest, Person, Number), 
    verbphrase(Rest, End, Person, Number).

sentence(Start, End) :-
    nounphrase(Start, Rest, Person, Number), 
    verbphrase(Rest, End, Person, Number).


% Because the person of a verb is indicated by conjugation, 
%	pronouns are optional
sentence(Start, End) :-
    interrogative(Start, Rest), 
    verbphrase(Rest, End, _, _).

sentence(Start, End) :-
    verbphrase(Start, End, _, _).


interrogative([Int|End], End) :-
    interrogator(Int).


nounphrase([Noun|End], End, Person, Number) :- 
    pronoun(Noun, Person, Number).

nounphrase([Noun|End], End, Person, Number) :- 
    noun(Noun, Person, Number).


verbphrase([Verb|End], End, Person, Number) :- 
    verb(Verb, Person, Number).

verbphrase([Verb, Rest|End], End, Person, Number) :- 
    verb(Verb, Person, Number),
    verb(Rest, infinitive, _).

verbphrase([Verb, Rest|End], End, Person, Number) :- 
    verb(Verb, Person, Number), 
    noun(Rest, genitive, _).


	% (yes/no interrogative) 
interrogator(kas).

	% how
interrogator(kuidas).

	% what
interrogator(mis).

	% who
interrogator(kes).

	% where
interrogator(kus).

	% when
interrogator(millal).


	% I
pronoun(mina, first, singular).
	% (abbreviation)
pronoun(ma, first, singular).

	% you
pronoun(sina, second, singular).
pronoun(sa, second, singular).

	% he/she
pronoun(tema, third, singular).
pronoun(ta, third, singular).

	% it
pronoun(see, third, singular).

	% we
pronoun(meie, first, plural).
pronoun(me, first, plural).

	% you
pronoun(teie, second, plural).
pronoun(te, second, plural).

	% they
pronoun(nemad, third, plural).
pronoun(nad, third, plural).


	% dog (and conjugations)
noun(koer, third, singular).
noun(koerad, third, plural).
noun(koera, genitive, singular).
noun(koeri, genitive, plural).

	% man
noun(mees, third, singular).
noun(mehed, third, plural).
noun(meest, genitive, singular).
noun(mehi, genitive, plural).

	% shoe
noun(king, third, singular).
noun(kingad, third, plural).
noun(kinga, genitive, singular).
noun(kingi, genitive, plural).

	% brother
noun(vend, third, singular).
noun(vennad, third, plural).
noun(venda, genitive, singular).
noun(vendi, genitive, plural).


	% to be
verb(olla, infinitive, none).
verb(olen, first, singular).
verb(oled, second, singular).
verb(on, third, singular).
verb(oleme, first, plural).
verb(olete, second, plural).
verb(on, third, plural).

	% to bite
verb(hammustama, infinitive, none).
verb(hammustan, first, singular).
verb(hammustad, second, singular).
verb(hammustab, third, singular).
verb(hammustame, first, plural).
verb(hammustate, second, plural).
verb(hammustavad, third, plural).

	% to go
verb(minna, infinitive, none).
verb(lahen, first, singular).
verb(lahed, second, singular).
verb(laheb, third, singular).
verb(laheme, first, plural).
verb(lahete, second, plural).
verb(lahevad, third, plural).

	% to want
verb(tahta, infinitive, none).
verb(tahan, first, singular).
verb(tahad, second, singular).
verb(tahab, third, singular).
verb(tahame, first, plural).
verb(tahate, second, plural).
verb(tahavad, third, plural).

	% to eat
verb(suua, infinitive, none).
verb(soon, first, singular).
verb(sood, second, singular).
verb(soob, third, singular).
verb(soome, first, plural).
verb(soote, second, plural).
verb(soovad, third, plural).



% Some examples:

%  Do you want to eat?
%?- utterance([kas, sa, tahad, suua]).
%
% Yes

%  Who is it?
%?- utterance([kes, on]).
%
% Yes

%  The man bites the dog.
%?- utterance([mees, hammustab, koera]).
%
% Yes

%  Where are you going?
%?- utterance([kus, teie, lahete]).
%
% Yes


%  The dog eats the shoe.
%?- utterance([koer, soob, kinga]).
%
% Yes


% Man we bite they are.
%?- utterance([mees, hammustame, olevad]).
%
% No
