Path: aipna!edcastle!ukc!mcsun!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!munnari.oz.au!mel.dit.csiro.au!latcs1!jacob From: jacob@latcs1.oz.au (Jacob L. Cybulski) Newsgroups: comp.ai Subject: Re: Eliza-like Fun Message-ID: <9500@latcs1.oz.au> Date: 7 Feb 91 03:35:23 GMT References: <1163@corwin.CCS.Northeastern.EDU> Organization: Comp Sci, La Trobe Uni, Australia Lines: 54 If you want to have fun with ELIZA-like program in prolog, here is a full implementation of it (actually my students were required to write it for the CL exam). Enjoy. Jacob L. Cybulski Amdahl Australian Intelligent Tools Programme Department of Computer Science La Trobe University Bundoora, Vic 3083, Australia Phone: +613 479 1270 Fax: +613 470 4915 Telex: AA 33143 EMail: jacob@latcs1.oz.au /* ToyEliza - by Jacob L. Cybulski */ unify([W | Rest], [[W | Phrase] | Pattern]) :- unify(Rest, [Phrase | Pattern]). unify(Words, [[] | Pattern]) :- unify(Words, Pattern). unify([], []). qa(InPhrase, OutPhrase) :- pattern(InPattern, OutPattern), unify(InPhrase, InPattern), unify(OutPhrase, OutPattern). /* Sample data base, probably you will have to disable "if" operator */ pattern([X, [alike], Y], [[in, what, way]]). pattern([X, [alike], Y], [[what, resemlance, do, you, see]]). pattern([X, [are, you], Y], [[would, you, prefer, it, if, i, were, not], Y]). pattern([X, [are], Y], [[what, if, they, were, not], Y]). pattern([X, [always], Y], [[can, you, think, of, a, specific, example]]). pattern([X, [always], Y], [[when]]). pattern([X, [always], Y], [[really, always]]). pattern([[what], X], [[why, do, you, ask]]). pattern([[what], X], [[does, that, interest, you]]). pattern([[my], X], [[your], X]). /* Possible questions and answers : 2?- qa([i, am, alike, you], A). A = [in, what, way] 3?- qa([they, are, stupid], A). A = [what, if, they, were, not, stupid] 4?- qa([why, are, you, so, nasty], A). A = [would, you, prefer, it, if, i, were, not, so, nasty] */