From 943c922f3e80b0c4acce47257fd2cad2b248668a Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sat, 24 Dec 2016 11:44:57 -0500 Subject: [PATCH] Remove redundant variables --- chatterbot/chatterbot.py | 2 +- chatterbot/conversation/session.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/chatterbot/chatterbot.py b/chatterbot/chatterbot.py index b40f3c70a..52de0df66 100644 --- a/chatterbot/chatterbot.py +++ b/chatterbot/chatterbot.py @@ -100,7 +100,7 @@ def get_response(self, input_item, session_id=None): # Learn that the user's input was a valid response to the chat bot's previous output previous_statement = self.conversation_sessions.get( session_id - ).conversation.get_last_response_statement() + ).get_last_response_statement() self.learn_response(statement, previous_statement) self.conversation_sessions.update(session_id, (statement, response, )) diff --git a/chatterbot/conversation/session.py b/chatterbot/conversation/session.py index 2c2aeef18..322c856c8 100644 --- a/chatterbot/conversation/session.py +++ b/chatterbot/conversation/session.py @@ -25,10 +25,11 @@ def add(self, statement): statement.conversation_id = self.conversation_id self.storage.update(statement) + class Session(object): """ A single chat session. - TODO: Rename to Conversation + In the future this class will be renamed to `Conversation`. """ def __init__(self, storage): @@ -42,9 +43,18 @@ def __init__(self, storage): self.id = str(self.uuid) # The last 10 statement inputs and outputs - self.conversation = ResponseQueue(maxsize=10) self.statements = StatementManager(self.storage, self.id) + def get_last_response_statement(self): + """ + Return the last statement that was received. + """ + statements = self.statements.all() + if statements: + # Return the latest output statement (This should be ordering them by date to get the latest) + return statements[-1] + return None + class ConversationSessionManager(object): """ @@ -77,6 +87,5 @@ def update(self, session_id, conversance): """ session_id = str(session_id) if session_id in self.sessions: - self.sessions[session_id].conversation.append(conversance) for statement in conversance: self.sessions[session_id].statements.add(statement)