3
votes

Does it work on your machines? I don't know how to use it- i get errors every time. Tell me please how to use it....

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

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 have tried some ways to write, maybe i dont know how correctly do it thats errors:

1 ?- hi.

ERROR: toplevel: Undefined procedure: hi/0 (DWIM could not correct goal)

2 ?- [hi].

ERROR: source_sink `hi' does not exist true.

3 ?- 'hi'.

ERROR: toplevel: Undefined procedure: hi/0 (DWIM could not correct goal)

4 ?- ['hi'].

ERROR: source_sink `hi' does not exist true.

3
@Bart: Done, do you see what's wrong by my or code side?Tom

3 Answers

3
votes

The main issue is that your code is in a Prolog dialect that's slightly different from SWI Prolog, which you're using. 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).

As said by the others, make sure you compile the code and then run it like:

chatterbot1.

Then it will ask you for some input. Type something like

hi.

And see a response. Let me know if it works.

0
votes

Before chatting, you need to start the program. For this you type:

chatterbot1.

Then you should see the prompt of the program:

>

Now you can chat with the program.

0
votes

you should first compile the program and then run chatterbot1. something like:

>[the program's name].
>chatterbot1.

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