How would I code it to record A User/Chatbot conversation?

So far, I have it working so that you type something in, press enter, and the chatbot responds with whatever random statement. My sources are in a notepad.txt. Here it is as listed below:

14 what is your name:Whatever you want to call me...#Why do you want to know?#What makes you so curious?#Does it really matter?#Hmm. You first.#My name is, uh... Let's save that for later.#You first bud.#Why are you asking me this?#My name is Chatbot. hi what is your name:Whatever you want to call me...#Why do you want to know?#What makes you so curious?#Does it really matter?#Hmm. You first.#My name is, uh... Let's save that for later.#You first bud.#Why are you asking me this?#My name is Chatbot. hi:Hi there.#Hello. How are you?#Hi.#Hello.#Hey.#Hello there.#Hi. How are you? hello:Hi there.#Hello. How are you?#Hi.#Hello.#Hey.#Hello there.#Hi. How are you? hey:Hi there.#Hello. How are you?#Hi.#Hello.#Hey.#Hello there.#Hi. How are you? how are you:I'm doing fine.#I'm doing well and you?#Why do you want to know how I am doing?#I'm doing fine. How are you?#Eh, I've been better. hi how are you:I'm doing fine.#I'm doing well and you?#Why do you want to know how I am doing?#I'm doing fine. How are you?#Eh, I've been better. who are you:I'm an awesome guy.#I think that you know who I am.#Why are you asking?#No. Who are YOU?#Um. You first... hey who are you:I'm an awesome guy.#I think that you know who I am.#Why are you asking?#No. Who are YOU?#Um. You first... my name is:Oh, nice to meet you! Its a pleasure to meet you.#Nice to meet you bud. are you intelligent:Yes, of course.#What do you think?#Actually, I'm very intelligent.#Obviously. are you real:Does that question really matter to you?#What do you mean by that?#I'm as real as I can be.#Think about your question for a minute...#Are you seriously going to ask me that?#Why are you asking me this?#Haha, very funny...#No. Are you REAL?!#Of course I'm real. because why:Because!!#Because!! That's why!!#Stop talking please.#I don't know.#I don't really know. what do you like to do:I like to play video games.#I like to go outside.#I like to hang out sometimes.#You first. 26 who:Who what?#Can you be a little more descriptive? what:I didn't say anything.#Nothing?...#Nothing. why:Why what?#Why not?#Because.#Because. That's why.#Can you be a little more descriptive? where:Where what?#Over there.#Can you be a little more descriptive? when:When what?#Right now.#In 5 minutes.#In 10 minutes.#In 20 minutes.#In 30 minutes.#In one hour.#In two hours.#Tomorrow.#Today.#Next week.#This weekend.#Next month.#This week.#This month.#Next year.#This year.#Can you be a little more descriptive? how:How what?#Can you be a little more descriptive? stop:Sorry.#Sorry, I didn't mean to offend you.#I apologize.#Forgive me, I apologize.#I'm sorry. please:No.#No!.#Fine.#Fine!#I don't want to.#Okay.#Sorry, but I can't.#I'm sorry, but I can't. wondering:Oh Okay.#That makes sense.#Why were you wondering?#And, why were you wondering?#That's not a good reason. yes:Oh Okay.#I see.#That makes sense.#That makes perfect sense.#I agree.#I disagree.#Well, I disagree.#Why do you say that? yeah:Oh Okay.#I see.#That makes sense.#That makes perfect sense.#I agree.#I disagree.#Well, I disagree.#Why do you say that? yep:Oh Okay.#I see.#That makes sense.#That makes perfect sense.#I agree.#I disagree.#Well, I disagree.#Why do you say that? yup:Oh Okay.#I see.#That makes sense.#That makes perfect sense.#I agree.#I disagree.#Well, I disagree.#Why do you say that? no:Oh Okay.#I see.#That makes sense.#That makes perfect sense.#I agree.#I disagree.#Why do you say that? nope:Oh Okay.#I see.#That makes sense.#That makes perfect sense.#I agree.#I disagree.#Why do you say that? nah:Oh Okay.#I see.#That makes sense.#That makes perfect sense.#I agree.#I disagree.#Why do you say that? you:Oh.#Okay.#Okay?#What are you even talking about? okay:Right.#Mhm.#Exactly.#Yeah.#Yep.#Yup. good:That's good to hear.#That's good.#Awesome.#Great.#Great to hear. awesome:That's good to hear.#That's good.#Awesome.#Great.#Great to hear. great:That's good to hear.#That's good.#Awesome.#Great.#Great to hear. bad:That's not good.#Oh, sorry to hear.#Sorry to hear that.#Oh...#Is there anything I can do? horrible:That's not good.#Oh, sorry to hear.#Sorry to hear that.#Oh...#Is there anything I can do? terrible:That's not good.#Oh, sorry to hear.#Sorry to hear that.#Oh...#Is there anything I can do? i:Oh. That's cool.#Okay.#I see. sorry:Apology accepted.#It's alright I guess.#No worries.#It's alright bud.#I don't you didn't mean to.#You're not sorry.#If you were sorry, then you wouldn't have done it. 3 ?:Yes.#No.#Maybe.#Probably.#Possibly.#Of course.#No way...#I don't know.#I don't really know...#Sorry, but I'm not answering that.#I don't have the answer to that.#Why are you asking me this? !:Wow...#Really?#I didn't know that.#Are you serious?#Okay, calm down. It's not that exciting...#Please stop shouting!!#Great...#My ears hurt. Please stop shouting.

error:I don't understand.#Sorry, I don't really understand.#Try using correct grammar.

I would like to know how I can have the conversation recorded. Here is the code I have listed below so far:

StringDict exactMatch = new StringDict(); StringDict keywordMatch = new StringDict(); StringDict randomMatch = new StringDict(); String [] lines; String input = ""; String answer = ""; String [] conversation = new String [12]; boolean validInput = false;

void setup(){ size(700, 400); textSize(20); int count, lineno; lines = loadStrings("ChatBot.txt"); count = int(lines[0]); lineno = 1; load_Match(exactMatch, lineno, lineno + count); lineno = count + lineno + 1; count = int(lines[lineno - 1]); load_Match(keywordMatch, lineno, lineno + count); lineno = count + lineno + 1; count = int(lines[lineno - 1]); load_Match(randomMatch, lineno, lineno + count); }

void load_Match(StringDict dict, int start, int end){ String [] phrases; for (int i = start; i < end; i++){ phrases = split(lines[i], ':'); if (phrases.length == 2) { dict.set(phrases[0], phrases[1]); } } }

String get_exactMatch(String input){ String responses = exactMatch.get(input.toLowerCase()); if (responses == null) return null; String [] choice = split(responses, '#'); return choice[int(random(choice.length))]; }

String get_keywordMatch(String input){ String [] words = split(input, ' '); for (int i = 0; i < words.length; i++){ String responses = keywordMatch.get(words[i].toLowerCase()); if (responses != null){ String [] choice = split(responses, '#'); return choice[int(random(choice.length))]; } } return null; }

String get_randomMatch(String input){ String responses; if (input.charAt(input.length() - 1) == '?') responses = randomMatch.get("?"); else if (input.charAt(input.length() - 1) == '!') responses = randomMatch.get("!"); else responses = randomMatch.get("error"); if (responses != null){ String [] choice = split(responses, '#'); return choice[int(random(choice.length))]; } return null; }

void keyTyped(){ if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') || (key == ' ') || (key == ',') || (key == '!') || (key == '?') || (key == '.') || (key >= '0' && key <= '9')){ input = input + key; } if (key == BACKSPACE || key == DELETE){ if (input.length() > 0) input = input.substring(0, input.length() - 1); } if (key == ENTER){ validInput = true; } else validInput = false; }

void draw(){ background(#6051F2); fill(255); text(mouseX + " , " + mouseY, 30, 30); text("User: ", 30, 100); text("Chatbot: ", 30, 200); rect(150, 60, 500, 50); rect(150, 160, 500, 50); if (validInput){ answer = get_exactMatch(input); if (answer == null){ answer = get_keywordMatch(input); } if (answer == null){ answer = get_randomMatch(input); } validInput = false; } //text(prime, 300, 200); rectMode(CORNER); fill(#6051F2); textSize(15); text(input, 160, 90); text(answer, 160, 190); }


Answers

Sign In or Register to comment.