Skip to content

Commit

Permalink
Remove redundant variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Dec 30, 2016
1 parent 43295f3 commit 943c922
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion chatterbot/chatterbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ))
Expand Down
15 changes: 12 additions & 3 deletions chatterbot/conversation/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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)

0 comments on commit 943c922

Please sign in to comment.