how do i make the database to record (into list form)
everything that is typed to it via readline? i put a
load save file( upon exit it should save to disk) in
the main code page. what would the code look like for
such a thing?
here is code to chatbot/db it crashes whenever it
doesnt match list. wont delete or add data during
program run. i also want to to remember each current
user and be able to switch users and remember each
one. how do i do that and what is wrong?
................................................
[] -> database;
load 'mydatabase.p';
define converse();
vars list,answer,name;
[hello] =>
[what is your name?] =>
readline() -> name;
[pleased to meet you ^^name] =>
[well - what do you want to talk about?] =>
repeat forever
readline() -> list;
quitif(list = [bye]);
storedata('mydatabase.p');
answer(list) =>
endrepeat;
[goodbye ^^name - talk to you another time.] =>
enddefine;
;;; check the facts (word [thing] - meaning) in the
database. if not there(add it)
define interpret(list) -> response;
vars thing,whatis,meaning;
if list matches [??thing is ??meaning] then
verify(thing, meaning) -> response;
elseif list matches [what is ??thing] then
whatis(thing) -> response;
else [please inform me ^^name] ->response;
endif;
enddefine;
define whatis(thing) -> response;
vars info;
if present([^^thing ??info]) then
[^^thing ^^info] -> response;
elseif present([^^thing ??info]) then
[a ^^thing is a ^^info] -> response;
else[i dont know what that is.] -> response;
endif;
enddefine;
define verify(thing, meaning) -> response;
vars verify,info;
if present([^^thing ^^meaning]) then
[i am aware of that] -> response;
elseif present([^^thing ??info]) then
[that ^^info] -> response;
else add([^^thing is ^^meaning]);
[i have made a note of that.] -> response;
endif;
enddefine;
define forget(list) -> response;
vars thing,meaning;
remove([^^thing is ^^meaning]);
[i have removed that info from my knowledge base.] ->
response;
enddefine;
define answer(list) -> response;
vars response;
if list matches [bye] then [bye - i will talk to you
again sometime.]
elseif list matches [hello ==] then
[hello, how are you?] -> response;
elseif list matches [what are you?] then [i am a
chatbot. i converse in a limited syntax of natural
language.] -> response;
elseif list matches [thank ==] then [you are
welcome...] -> response;
elseif list matches [thanks] then [dont mention it.]
-> response;
elseif list matches [how are you ==] then [i am fine.
and you?] -> response;
elseif list matches [is your name bot?] then [yes.] ->
response;
elseif list matches [is your name ==] then [my name is
bot.] -> response;
elseif list matches [do you like ==] then [i am not
programmed to like or dislike ^^name.] -> response;
elseif list matches [i want == ] then [ok...] ->
response;
elseif list matches [what == my name ==] then [your
name is ^^name.] -> response;
elseif list matches [== fine ==] then [that is fine.]
-> response;
elseif list matches [what is your name ==] then [my
name is dile.] -> response;
elseif list matches [who are you?] then [i am bot.] ->
response;
elseif list matches [who are you] then [i am bot.] ->
response;
elseif list matches [who am i?] then [you are ^^name.]
-> response;
elseif list matches [who am i] then [you are ^^name.]
-> response;
elseif list matches [show == database] then database
-> response; ;;;==> -> response;
elseif list matches [what is ^^thing] then [^^thing is
^^meaning.] -> response;
elseif list matches [forget ^^thing is ^^meaning] then
[deleting from my database] -> response;
elseif list matches [==] then [] -> response;
else [i dont understand.] -> response;
endif;
enddefine;
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
|