%% eliza(+Stimuli, -Response) is det. % @param Stimuli is a list of atoms (words). % @author Richard A. O'Keefe (The Craft of Prolog) eliza(Stimuli, Response) :- template(InternalStimuli, InternalResponse), match(InternalStimuli, Stimuli), match(InternalResponse, Response), !. template([s([i,am]),s(X)], [s([why,are,you]),s(X),w('?')]). template([w(i),s(X),w(you)], [s([why,do,you]),s(X),w(me),w('?')]). match([],[]). match([Item|Items],[Word|Words]) :- match(Item, Items, Word, Words). match(w(Word), Items, Word, Words) :- match(Items, Words). match(s([Word|Seg]), Items, Word, Words0) :- append(Seg, Words1, Words0), match(Items, Words1). /** ?- eliza([i, am, very, hungry], Response). ?- eliza([i, love, you], Response). */