% % ELIZA reconstruction adapted from Sterling & Shapiro 1986, page 232 % ?- reconsult('library.pl'). eliza :- read_in(Input), eliza(Input), !. % eliza([bye]) :- reply([goodbye,i,hope,i,have,helped,you]). eliza(Input1) :- pattern(Stimulus,Response), match(Stimulus,Dictionary,Input1), match(Response,Dictionary,Output1), reply(Output1), read_in(Input2), !, eliza(Input2). % match([N|Pattern],Dictionary,Target) :- integer(NP), lookup(N,Dictionary,LeftTarget), append(LeftTarget,RightTarget,Target), match(Pattern,Dictionary,RightTarget). match([Word|Pattern],Dictionary,[Word|Target]) :- atom(Word), match(Pattern,Dictionary,Target). match([],Dictionary,[]). % lookup(Key,[(Key,Value)|Dictionary],Value). lookup(Key1,[(Key2,Value2)|Dictionary],Value1) :- Key1 /= Key2, lookup(Key1,Dictionary,Value1). % reply([Word|Words]) :- write(Word), write(' '), reply(Words). reply([]) :- nl. % pattern([i,am,1],[how,long,have,you,been,1,?]). pattern([1,you,2,me],[what,makes,you,think,i,2,you,?]). pattern([i,like,1],[does,anyone,else,in,your,family,like,1,?]). pattern([i,feel,1],[do,you,often,feel,that,way,?]). pattern([1,X,2],[can,you,tell,me,more,about,X,?]) :- important(X). pattern([1],[please,go,on]). % important(father). important(sister). important(mother). important(brother). important(son). important(daughter).