Eliza program 
Author Message
 Eliza program

Hi evrybody,

I am looking for a prolog program called ELIZA. This program simulate a
job interview where the machine ask question to the user in order to
define its personality. Is anybody know an ftp site where this program is
available?
                                Thanks in advance.
                                                        Valery.



Wed, 20 May 1998 03:00:00 GMT  
 Eliza program

Quote:

>I am looking for a prolog program called ELIZA. This program simulate a
>job interview where the machine ask question to the user in order to
>define its personality. Is anybody know an ftp site where this program is
>available?

Here's a version of Eliza written in Mercury.
(This is one of the samples that we provide as part of the
Mercury distribution.)

%-----------------------------------------------------------------------------%
% Copyright (C) 1995 University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%

% File: eliza.m.
% Main author: bromage.

% Eliza, the famous psychotherapist.

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

:- module eliza.
:- interface.
:- import_module io.

:- pred main(io__state :: di, io__state :: uo) is det.

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

:- implementation.

:- import_module char, list, string, std_util, map, assoc_list, require.

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

        % Print the opening banner, initialise the response state,
        % run the main loop.

main -->
        io__write_string("\nHi!  I'm Eliza.  Please tell me your problem.\n"),
        { eliza__initial_state(State) },
        eliza__main_loop([], State),
        io__write_string("\nGoodbye.\n").

:- pred eliza__main_loop(list(string), eliza__state, io__state, io__state).
:- mode eliza__main_loop(in, in, di, uo) is det.
eliza__main_loop(Prev, StateIn) -->
        eliza__read_line(Line0, Ok),
        ( { Ok = yes } ->
            { eliza__parse(Line0, Line1) },
            ( { Line1 = [] } ->
                eliza__main_loop(Prev, StateIn)
            ;
                ( { Line1 = Prev } ->
                    eliza__generate_repeat(StateIn, StateOut)
                ;
                    eliza__generate_response(Line1, StateIn, StateOut)
                ),
            eliza__main_loop(Line1, StateOut)
            )
        ;
            { true }
        ).

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

        % Response state processing functions

        % The response state consists of two parts: a set of
        % (type - messages) pairs and a list of repeat messages.
        % The response messages are used in response to a context,
        % and the repeat messages are used in response to a repeated
        % input line.

:- type response_state == assoc_list(message_type, list(message)).
:- type repeat_state   == list(string).

:- type eliza__state ---> state(response_state, repeat_state).

        % Initialise the state by reading in the initial message
        % database.

:- pred eliza__initial_state(eliza__state :: out) is det.
eliza__initial_state(state(ResMsg,RepMsg)) :-
        repeat_messages(RepMsg),
        response_messages(ResMsg).

        % Get a repeat message, and then cycle the list so that
        % a new one will come up next time.

:- pred eliza__get_repeat(string, eliza__state, eliza__state).
:- mode eliza__get_repeat(out, in, out) is det.
eliza__get_repeat(MsgOut, state(Res, RepIn), state(Res, RepOut)) :-
        ( RepIn = [Msg | Rest] ->
            MsgOut = Msg,
            list__append(Rest, [Msg], RepOut)
        ;
            error("Error: No repeat messages.\n")
        ).

        % Get a response message, and then cycle the list so that
        % a new one will come up next time.

:- pred eliza__get_response(message_type, message, eliza__state, eliza__state).
:- mode eliza__get_response(in, out, in, out) is det.
eliza__get_response(Type, MsgOut, state(ResIn, Rep), state(ResOut, Rep)) :-
        eliza__get_response2(Type, MsgOut, ResIn, ResOut).

:- pred eliza__get_response2(message_type, message,
                response_state, response_state).
:- mode eliza__get_response2(in, out, in, out) is det.
eliza__get_response2(_Type, _MsgOut, [], []) :-
        error("Error: Cannot match message type.\n").
eliza__get_response2(Type, MsgOut,
                [Type2 - Msgs2 | RestIn],
                [Type2 - Msgs3 | RestOut]) :-
        ( Type = Type2 ->
            ( Msgs2 = [MsgOut1 | MsgOutRest] ->
                MsgOut = MsgOut1,
                RestOut = RestIn,
                list__append(MsgOutRest, [MsgOut], Msgs3)
            ;
                error("Error: Empty response list.\n")
            )
        ;
            Msgs2 = Msgs3,
            eliza__get_response2(Type, MsgOut, RestIn, RestOut)
        ).

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

        % Write a prompt, then read a line.

:- pred eliza__read_line(list(char), bool, io__state, io__state).
:- mode eliza__read_line(out, out, di, uo) is det.
eliza__read_line(Line, Ok) -->
        io__write_string("\n> "),
        io__input_stream(Stdin),
        io__read_line(Stdin, Result),
        io__write_string("\n"),
        ( { Result = ok(Line1) } ->
           { Ok = yes, Line = Line1 }
        ;
           { Ok = no, Line = [] }
        ).

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

        % These are the characters that we must strip from a
        % line during parsing.

:- pred eliza__is_punct(char).
:- mode eliza__is_punct(in) is semidet.
eliza__is_punct('.').
eliza__is_punct(',').
eliza__is_punct('!').
eliza__is_punct('?').

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

        % Parse the input string into words.  This is
        % achieved in three phases:
        %
        %     - Strip leading whitespace and intermediate
        %       punctuation symbols.
        %
        %     - Turn the resulting line into a list of words (each
        %       word stored as a list of characters).
        %
        %     - Turn each word into a string.

:- pred eliza__parse(list(char) :: in, list(string) :: out) is det.
eliza__parse -->
        eliza__strip,
        eliza__form_words,
        eliza__words_to_strings.

:- pred eliza__strip(list(char) :: in, list(char) :: out) is det.
eliza__strip([], []).
eliza__strip([X | Xs], Ys) :-
        ( char__is_whitespace(X) ->
            eliza__strip(Xs, Ys)
        ;
            eliza__strip2([X | Xs], Ys)
        ).

:- pred eliza__strip2(list(char) :: in, list(char) :: out) is det.
eliza__strip2([], []).
eliza__strip2([X | Xs], Ys) :-
        ( eliza__is_punct(X) ->
            eliza__strip2([' ' | Xs], Ys)
        ;
             eliza__strip2(Xs, Ys1),
            ( char__is_whitespace(X), Ys1 = [] ->
                Ys = []
            ;
                Ys = [X | Ys1]
            )
        ).

:- pred eliza__form_words(list(char), list(list(char))).
:- mode eliza__form_words(in, out) is det.
eliza__form_words([], []).
eliza__form_words([X | Xs], Ys) :-
        ( char__is_whitespace(X) ->
            eliza__form_words(Xs, Ys)
        ;
            eliza__form_word(Xs, [X], Word, Rest),
            eliza__form_words(Rest, Words),
            Ys = [Word | Words]
        ).

:- pred eliza__form_word(list(char), list(char), list(char), list(char)).
:- mode eliza__form_word(in, in, out, out) is det.
eliza__form_word([], Word1, Word2, []) :-
        list__reverse(Word1, Word2).
eliza__form_word([X | Xs], WordIn, WordOut, Rest) :-
        ( char__is_whitespace(X) ->
            list__reverse(WordIn, WordOut), Rest = Xs
        ;
            eliza__form_word(Xs, [X | WordIn], WordOut, Rest)
        ).

:- pred eliza__words_to_strings(list(list(char)), list(string)).
:- mode eliza__words_to_strings(in, out) is det.
eliza__words_to_strings([], []).
eliza__words_to_strings([X | Xs], [Y | Ys]) :-
        string__from_char_list(X, Y),
        eliza__words_to_strings(Xs, Ys).

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

        % Generate and display a repeat message

:- pred eliza__generate_repeat(eliza__state, eliza__state,
                io__state, io__state).
:- mode eliza__generate_repeat(in, out, di, uo) is det.
eliza__generate_repeat(StateIn, StateOut) -->
        { eliza__get_repeat(Msg, StateIn, StateOut) },
        io__write_string(Msg),
        io__write_string("\n").

        % Generate and display a repeat message

:- pred eliza__generate_response(list(string),
                eliza__state, eliza__state,
                io__state, io__state).
:- mode eliza__generate_response(in, in, out, di, uo) is det.
eliza__generate_response(Words, StateIn, StateOut) -->

        % Find out what sort of message we are dealing with.

        { eliza__find_handle(Words, MsgType, Rest) },
        { eliza__get_response(MsgType, Maybe - String, StateIn, StateOut) },
        io__write_string(String),

        % If we must parrot back part of the original message,
        % resolve conjugates, write that string and then add
        % a trailing punctuation mark.

        ( { Maybe = yes(C) } ->
            { eliza__perform_conjugate(Rest, Postfix) },
            eliza__write_strings(Postfix),
            io__write_char(C)
        ;
            { true }
        ),
        io__write_string("\n").

        % Write a list of strings to the output stream with
        % words thrown in between.

:- pred eliza__write_strings(list(string), io__state, io__state).
:- mode eliza__write_strings(in, di, uo) is det.
eliza__write_strings([]) --> { true }.
eliza__write_strings([X | Xs]) -->
        io__write_char(' '),
        io__write_string(X),
        eliza__write_strings(Xs).

:- pred eliza__match_prefix(list(string), list(string), list(string)).
:- mode eliza__match_prefix(in, in, out) is semidet.
eliza__match_prefix([], Ys, Ys).
eliza__match_prefix([X | Xs], [Y | Ys], Zs) :-
        string__to_upper(Y, X),
        eliza__match_prefix(Xs,Ys,Zs).

:- pred eliza__find_handle(list(string), message_type, list(string)).
:- mode eliza__find_handle(in, out, out) is det.
eliza__find_handle(In, MsgType, Out) :-
        response_handles(Handles),
        eliza__find_handle2(In, MsgType, Out, Handles).

:- pred eliza__find_handle2(list(string), message_type, list(string),
                assoc_list(list(string), message_type)).
:- mode eliza__find_handle2(in, out, out, in) is det.
eliza__find_handle2(In, no_key_message, In, []).
eliza__find_handle2(In, Type, Out, [Prefix - Type2 | Handles]) :-
        ( eliza__find_handle3(In, Prefix, Rest) ->
            Out = Rest, Type = Type2
        ;
            eliza__find_handle2(In, Type, Out, Handles)
        ).

:- ...

read more »



Sat, 30 May 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ELIZA Program in REXX

2. Eliza program in rexx?

3. Good Eliza program in Common Lisp?

4. Eliza in J, revised

5. ELIZA

6. LISP was: Eliza

7. Eliza

8. Pop11 Eliza speeds up

9. Pop-11 Eliza answers 1000 questions

10. pop11 eliza online at last

11. ELIZA EXEC

12. ELIZA

 

 
Powered by phpBB® Forum Software