Problems Using a Code Program

Does it work on your machines? I do not know how to use it - I get errors every time. Please tell me how to use it ....

Link to the source: http://ai-programming.com/prolog_bot_tutorial.htm

the code:

% Program Name: chatterbot1
% Description: this is a very basic example of a chatterbot program
%
% Author: Gonzales Cenelia
% Date: 7 august 2009
%
response_database([
    ['I HEARD YOU!'],
    ['SO, YOU ARE TALKING TO ME.'],
    ['CONTINUE, IM LISTENING.'],
    ['VERY INTERESTING CONVERSATION.'],
    ['TELL ME MORE...']]).

select(0, [H|T], H).
select(N, [H|T], L) :- N > 0, N1 is N - 1, select(N1, T, L).

quit_session(X):- X = 'bye', 
    nl, write('IT WAS NICE TALKING TO YOU USER, SEE YOU NEXT TIME!').

write_string([H|T]):- write(H).

chatterbot1:- 
    repeat,
    nl, write('>'),
    read_string(Input),
    response_database(ListOfResponse),
    IndexOfResponse is integer(random * 5),
    select(IndexOfResponse, ListOfResponse, Response),
    write_string(Response),
    quit_session(Input).

I tried to write several ways, maybe I don’t know how to do it right:

1? - hi.

ERROR: toplevel: Undefined procedure: hi / 0 (DWIM could not have the correct target)

2? - [hi].

ERROR: source_sink `hi 'does not exist.

3? - 'hi'.

ERROR: toplevel: Undefined procedure: hi / 0 (DWIM could not have the correct target)

4? - ['hi'].

ERROR: source_sink `hi 'does not exist.

+3
source share
3 answers

The main problem is that your code is on the Prolog dialog, which is slightly different from the SWI Prolog you use. You can try something like this:

response_database([
    ['I HEARD YOU!'],
    ['SO, YOU ARE TALKING TO ME.'],
    ['CONTINUE, IM LISTENING.'],
    ['VERY INTERESTING CONVERSATION.'],
    ['TELL ME MORE...']]).

select(0, [H|_], H).
select(N, [_|T], L) :- N > 0, N1 is N - 1, select(N1, T, L).

quit_session(X):- X = 'bye',
    nl, write('IT WAS NICE TALKING TO YOU USER, SEE YOU NEXT TIME!').

write_string([H|_]):- write(H).

chatterbot1:-
    repeat,
    nl, write('>'),
    read(Input),
    response_database(ListOfResponse),
    IndexOfResponse is integer(random(5)),
    select(IndexOfResponse, ListOfResponse, Response),
    write(Response),
    quit_session(Input).

, , , , :

chatterbot1.

- . -

hi.

. , .

+3

. :

chatterbot1.

:

>

.

0

First you need to compile the program, and then run chatterbot1. sort of:

>[the program name].
>chatterbot1.

btw read_string / 1 is not the default predicate in my prolog dialect (swi-prolog), so I cannot check it.
dunno about yours

0
source

All Articles