% A compositional program to
% build a logical form

% An example of query
%?- s(Semantics, [the, patron, ordered, a, meal], []).
%	Semantics = the(_4,patron(_4),a(_32,meal(_32),ordered(_4,_32)))


% The rules embedding compositional semantics
s(Semantics) --> np((X^Rest)^Semantics), vp(X^Rest).
np((X^Rest)^SemDet) -->
	determiner((X^NP)^(X^Rest)^SemDet),
	noun(X^NP).								
vp(Subject^Verb) --> verb(Subject^Verb).	
vp(Subject^Predicate) -->
	verb(Object^Subject^Verb),
	np((Object^Verb)^Predicate).

noun(X^waiter(X)) --> [waiter].				
noun(X^patron(X)) --> [patron].				
noun(X^meal(X)) --> [meal].					
verb(X^rushed(X)) --> [rushed].					
verb(Y^X^ordered(X, Y)) --> [ordered].			
verb(Y^X^brought(X, Y)) --> [brought].			
determiner((X^NP)^(X^Rest)^a(X, NP, Rest)) -->
		[a].		
determiner((X^NP)^(X^Rest)^the(X, NP, Rest)) -->
		[the].
determiner((X^NP)^(X^Rest)^all(X, NP, Rest)) -->
		[every].
determiner((X^NP)^(X^Rest)^all(X, NP, Rest)) -->
		[all].


% The database
meal(cassoulet).
meal(pyttipanna).

patron('Pierre').
patron('Sven').
%patron('Klas').

ordered('Pierre', cassoulet).
ordered('Sven', pyttipanna).



% The determiners
all(X, Property1, Property2) :-
	\+
	(Property1,
	\+ Property2),
	Property1,
	!.

a(X, Property1, Property2) :-
	Property1,
	Property2.

