diff --git a/main.py b/main.py index 08ad077..6a62ee7 100644 --- a/main.py +++ b/main.py @@ -11,20 +11,19 @@ def __init__(self): "faq_page": "www.NotActuallyAnFAQ.com" } - print "Ask a question:" + print("Ask a question:") while(True): self.allow_question() def allow_question(self): - # Check for event stack potential_event = None if(len(self.event_stack)): potential_event = self.event_stack.pop() if potential_event: - text = raw_input("Response: ") + text = input("Response: ") potential_event.handle_response(text, self) else: - text = raw_input("Question: ") + text = input("Question: ") answer = self.pre_built_responses_or_none(text) if not answer: answer = find_most_similar(text) @@ -32,18 +31,15 @@ def allow_question(self): def answer_question(self, answer, text): if answer['score'] > self.settings['min_score']: - # set off event asking if the response question is what they were looking for - print "\nBest-fit question: %s (Score: %s)\nAnswer: %s\n" % (answer['question'], + print("\nBest-fit question: %s (Score: %s)\nAnswer: %s\n" % (answer['question'], answer['score'], - answer['answer']) + answer['answer'])) else: - print "Woops! I'm having trouble finding the answer to your question. " \ - "Would you like to see the list of questions that I am able to answer?\n" - # set off event for corpus dump + print("Woops! I'm having trouble finding the answer to your question. " \ + "Would you like to see the list of questions that I am able to answer?\n") self.event_stack.append(Event("corpus_dump", text)) def pre_built_responses_or_none(self, text): - # only return answer if exact match is found pre_built = [ { "Question": "Who made you?", @@ -64,14 +60,17 @@ def pre_built_responses_or_none(self, text): { "Question": "Thank you", "Answer": "Glad I could help!\n" + }, + { + "Question": "Lorem Ipsum", + "Answer": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" } ] for each_question in pre_built: if each_question['Question'].lower() in text.lower(): - print each_question['Answer'] + print(each_question['Answer']) return each_question - def dump_corpus(self): question_stack = [] for each_item in CORPUS: @@ -97,22 +96,21 @@ def corpus_dump(self, text, bot): if each_confirmation.lower() == each_word.lower(): corpus = bot.dump_corpus() corpus = ["-" + s for s in corpus] - print "%s%s%s" % ("\n", "\n".join(corpus), "\n") + print("%s%s%s" % ("\n", "\n".join(corpus), "\n")) return 0 for each_negation in self.NEGATIONS: for each_word in text.split(" "): if each_negation.lower() == each_word.lower(): - print "Feel free to ask another question or send an email to %s.\n" % bot.settings['help_email'] + print("Feel free to ask another question or send an email to %s.\n" % bot.settings['help_email']) bot.allow_question() return 0 - # base case, no confirmation or negation found - print "I'm having trouble understanding what you are saying. At the time, my ability is quite limited, " \ + print("I'm having trouble understanding what you are saying. At the time, my ability is quite limited, " \ "please refer to %s or email %s if I was not able to answer your question. " \ "For convenience, a google link has been generated below: \n%s\n" % (bot.settings['faq_page'], bot.settings['help_email'], "https://www.google.com/search?q=%s" % - ("+".join(self.original_text.split(" ")))) + ("+".join(self.original_text.split(" "))))) return 0 -Bot() +Bot() \ No newline at end of file