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.
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.
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.
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
精彩评论