Skip to content

Commit

Permalink
Removed context from console client, it added nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
keiffster committed Sep 18, 2017
1 parent 101aac0 commit a320a9e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 168 deletions.
1 change: 1 addition & 0 deletions bots/y-bot/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ bot:
prompt: ">>>"
initial_question: Hi, how can I help you today?
default_response: Sorry, I don't have an answer for that!
default_response_srai: YDEFAULTRESPONSE
empty_string_srai: YEMPTY
exit_response: So long, and thanks for the fish!

Expand Down
29 changes: 9 additions & 20 deletions src/programy/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,10 @@ def check_spelling_and_retry(self, clientid, each_sentence):
return response
return None

def ask_question(self, clientid: str, text: str, srai=False, bot_question_context=None):
def ask_question(self, clientid: str, text: str, srai=False):

if logging.getLogger().isEnabledFor(logging.DEBUG): logging.debug("Question (%s): %s", clientid, text)

if bot_question_context is not None:
bot_question_context.clientid = clientid
bot_question_context.srai = srai
bot_question_context.raw_question = text

if srai is False:
pre_processed = self.brain.pre_process_question(self, clientid, text)
if logging.getLogger().isEnabledFor(logging.DEBUG): logging.debug("Pre Processed (%s): %s", clientid, pre_processed)
Expand All @@ -191,9 +186,6 @@ def ask_question(self, clientid: str, text: str, srai=False, bot_question_contex
if pre_processed is None or len(pre_processed) == 0:
pre_processed = self._configuration.empty_string

if bot_question_context is not None:
bot_question_context.preprocessed_question = pre_processed

if srai is False:
question = Question.create_from_text(pre_processed)
else:
Expand All @@ -215,14 +207,10 @@ def ask_question(self, clientid: str, text: str, srai=False, bot_question_contex
self.check_max_recursion()
self.check_max_timeout()

brain_context_question = None
if bot_question_context is not None:
brain_context_question = bot_question_context.next_brain_question_context()

if srai is False:
self.check_spelling_before(each_sentence)

response = self.brain.ask_question(self, clientid, each_sentence, srai=srai, brain_question_context=brain_context_question)
response = self.brain.ask_question(self, clientid, each_sentence, srai=srai)

if response is None and srai is False:
response = self.check_spelling_and_retry(clientid, each_sentence)
Expand All @@ -234,15 +222,16 @@ def ask_question(self, clientid: str, text: str, srai=False, bot_question_contex
if srai is False:
answer = self.brain.post_process_response(self, clientid, response).strip()
if len(answer) == 0:
answer = self.default_response
answer = self.get_default_response()
else:
answer = response

answers.append(answer)
if logging.getLogger().isEnabledFor(logging.DEBUG): logging.debug("Processed Response (%s): %s", clientid, answer)
else:
each_sentence.response = self.default_response
answers.append(self.default_response)
default_response = self.get_default_response()
each_sentence.response = default_response
answers.append(default_response)

sentence_no += 1

Expand All @@ -253,13 +242,13 @@ def ask_question(self, clientid: str, text: str, srai=False, bot_question_contex

response = ". ".join([sentence for sentence in answers if sentence is not None])

if bot_question_context is not None:
bot_question_context.final_response = response

self.log_question_and_answer(clientid, text, response )

return response

def get_default_response(self):
return self.default_response

def log_question_and_answer(self, clientid, question, answer):

filename = self.brain.configuration.files.aiml_files.conversation
Expand Down
24 changes: 1 addition & 23 deletions src/programy/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,7 @@ def post_process_response(self, bot, clientid, response: str):
def dump_tree(self):
self._aiml_parser.pattern_parser.root.dump(tabs="")

def ask_question(self, bot, clientid, sentence, srai=False, brain_question_context=None):

if brain_question_context is not None:
brain_question_context.clientid = clientid
brain_question_context.srai = srai
brain_question_context.sentence = sentence
def ask_question(self, bot, clientid, sentence, srai=False):

if self.authentication is not None:
if self.authentication.authenticate(clientid) is False:
Expand All @@ -438,9 +433,6 @@ def ask_question(self, bot, clientid, sentence, srai=False, brain_question_conte
else:
if logging.getLogger().isEnabledFor(logging.INFO): logging.info("Topic pattern = [%s]", topic_pattern)

if brain_question_context is not None:
brain_question_context.topic = topic_pattern

try:
that_question = conversation.previous_nth_question(1)
that_sentence = that_question.current_sentence()
Expand All @@ -458,35 +450,21 @@ def ask_question(self, bot, clientid, sentence, srai=False, brain_question_conte
if logging.getLogger().isEnabledFor(logging.INFO): logging.info("No That pattern default to [*]")
that_pattern = "*"

if brain_question_context is not None:
brain_question_context.that = that_pattern

match_context = self._aiml_parser.match_sentence(bot, clientid,
sentence,
topic_pattern=topic_pattern,
that_pattern=that_pattern)

if match_context is not None:

if brain_question_context is not None:
brain_question_context.match_context = match_context

template_node = match_context.template_node()
if logging.getLogger().isEnabledFor(logging.DEBUG): logging.debug("AIML Parser evaluating template [%s]", template_node.to_string())
response = template_node.template.resolve(bot, clientid)

if brain_question_context is not None:
brain_question_context.raw_response = response

if "<oob>" in response:
response, oob = self.strip_oob(response)
if oob is not None:
oob_response = self.process_oob(bot, clientid, oob)

if brain_question_context is not None:
brain_question_context.raw_response = response
brain_question_context.oob_response = oob_response

response = response + " " + oob_response

return response
Expand Down
18 changes: 5 additions & 13 deletions src/programy/clients/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from programy.clients.client import BotClient
from programy.config.sections.client.console import ConsoleConfiguration
from programy.context import BotQuestionContext

class ConsoleBotClient(BotClient):

Expand All @@ -34,10 +33,10 @@ def get_client_configuration(self):
return ConsoleConfiguration()

def add_client_arguments(self, parser):
parser.add_argument('--context', dest='context', action='store_true', help='displays additional conversation context')
return

def parse_args(self, arguments, parsed_args):
arguments.context = parsed_args.context
return

def get_question(self, input_func=input):
ask = "%s "%self.bot.prompt
Expand All @@ -54,24 +53,17 @@ def display_unknown_response(self, question):
def display_response(self, response, output_func=print):
output_func(response)

def ask_question(self, question, context):
return self.bot.ask_question(self.clientid, question, bot_question_context=context)
def ask_question(self, question):
return self.bot.ask_question(self.clientid, question)

def process_question_answer(self):
question = self.get_question()

context = None
if self.arguments.context is True:
context = BotQuestionContext()

response = self.ask_question(question, context)
response = self.ask_question(question)

if response is None:
self.display_unknown_response(question)
else:
if context is not None:
context.display(output_func=print)

self.display_response(response)
self.log_response(question, response)

Expand Down
55 changes: 0 additions & 55 deletions src/programy/context.py

This file was deleted.

2 changes: 1 addition & 1 deletion test/programytest/clients/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def display_response(self, response, output_func=print):
super (MockConsoleBotClient, self).display_response(response, output_func)
self.response += response

def ask_question(self, question, context):
def ask_question(self, question):
return self.question

def process_question_answer(self):
Expand Down
56 changes: 0 additions & 56 deletions test/programytest/test_context.py

This file was deleted.

0 comments on commit a320a9e

Please sign in to comment.