% shrink.pl: A simple shell for an Eliza-like dialogue program.

run:-
        write('Welcome to my sofa'),
        nl, nl,
        repeat,
        getsentence(Sent),
        once(pick_response(Sent, Response)),
        write_list(Response), nl,
        Response = [goodbye].

%---------------------------------------------------------------------------
getsentence(Words) :-
        get0(Ch),
        getrest(Ch, Words).

getrest(10, []) :- !.
getrest(32, Words) :-
        !,
        getsentence(Words).
getrest(Ch, [W|Ws]) :-
        getword(Ch, Chs, Next),
        name(W, Chs),
        getrest(Next, Ws).

getword(10, [], 10) :- !.
getword(32, [], 32) :- !.
getword(Ch, [Ch|Chs],Next) :-
        get0(Ch1),
        getword(Ch1,Chs,Next).

%---------------------------------------------------------------------------
response([bye],[goodbye]).
response([hello], [how,can,i,help,you]).
response([i, am | X],[please, tell, me, Wword, you, are | X1]) :-
        getWword(Wword),
        spitback(X,X1).
response([i,have|X],[how,long,have,you,had|X1]) :-
        spitback(X,X1).
response([i,feel|_],[i,sometimes,feel,the,same,way]).
response([because|_],[is,that,really,the,reason]).
response([],[please,say,something]).
response([yes|X],[how,can,you,be,so,sure |X1]) :-
        spitback(X,X1).
response([yes|[X|Xs]],[you,seem,certain,that |X1]) :-
        spitback([X|Xs],X1).
response([you, are|X],[oh,yeah,i,am|X1]) :-
        spitback(X,X1).
response([Verb|X],[oy,yoi,yoi,you,want,that,i,should,go,and,Verb|X1]) :-
        verb(Verb),
        spitback(X,X1).
response([Wword|_],[you,tell,me,Wword]) :-
        wWord(Wword).
response([Dword,you|X],[perhaps,i,Dword|X1]) :-
        dWord(Dword),
        spitback(X,X1).
response([do,you,think|_],[i,think,you,should,answer,that,yourself]).
response(Sent,[for,dream,analysis,see,freud]) :-
        member(dream,Sent).
response(Sent,[all,is,fair,in,love,and,war]) :-
        member(love,Sent).
response(Sent,[dont,be,so,negative]) :-
        member(no,Sent).
response(Sent,[be,more,decisive]) :-
        member(maybe,Sent).
response([am,i|X], [do, you,think,you,are|X]).
response(Sent, [tell, me, more, about, your, W]) :-
        append(_,[my, W|Ws], Sent), 
        member(me, Ws).
response(Sent,Sent1) :-
        member(i,Sent),
        spitback(Sent,Sent1).

verb(go). verb(have). verb(be). verb(try). verb(eat). verb(take).
verb(help). verb(make). verb(get). verb(jump). verb(write). verb(type).
verb(fill). verb(put). verb(turn). verb(compute). verb(calculate).
verb(think). verb(drink). verb(blink). verb(crash). verb(crunch). verb(add).

dWord(do). dWord(can). dWord(should). dWord(would).

wWord(why). wWord(where). wWord(when). wWord(what).

punt([please,go,on]).
punt([tell,me,more]).
punt([i,see]).
punt([what,does,that,indicate]).
punt([but,why,be,concerned,about,it]).
punt([just,tell,me,how,you,feel]).   

%---------------------------------------------------------------------------
%  Change These Predicates
%---------------------------------------------------------------------------
pick_response(Sent, R) :- response(Sent, R).
pick_response(_, R) :- punt(R).

%---------------------------------------------------------------------------
spitback(X,X).

%---------------------------------------------------------------------------
write_list(X) :-
        write(X), nl.

%---------------------------------------------------------------------------
getWword(W) :-
        wWord(W).

%---------------------------------------------------------------------------
