Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lorem Ipsum to Predefined Responses #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,35 @@ 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)
self.answer_question(answer, text)

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?",
Expand All @@ -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:
Expand All @@ -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()