Skip to content

Commit

Permalink
Log response now processes less data.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed May 21, 2015
1 parent 4bd7cd8 commit 292b3a6
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions chatterbot/chatterbot.py
Expand Up @@ -86,27 +86,21 @@ def train(self, conversation):
if not values:
values = {}

count = self.update_occurrence_count(values)
timestamp = self.timestamp()
values["occurrence"] = self.update_occurrence_count(values)
values["date"] = self.timestamp()

previous_statement = self.get_last_statement()
response_list = self.update_response_list(statement, previous_statement)
values["in_response_to"] = self.update_response_list(statement, previous_statement)

self.storage.update(statement, date=timestamp, occurrence=count, in_response_to=response_list)
self.storage.update(statement, **values)

def update_log(self, data):
statement = list(data.keys())[0]
values = data[statement]
def update_log(self, **kwargs):

count = self.update_occurrence_count(values)
username = values["name"]
timestamp = values["date"]

previous_statement = self.get_last_statement()
response_list = self.update_response_list(statement, previous_statement)
statement = list(kwargs.keys())[0]
values = kwargs[statement]

# Update the database with the changes
self.storage.update(statement, name=username, date=timestamp, occurrence=count, in_response_to=response_list)
self.storage.update(statement, **values)

# TODO, change user_name and input_text into a single dict
def get_response_data(self, user_name, input_text):
Expand All @@ -121,17 +115,25 @@ def get_response_data(self, user_name, input_text):
# If the input is blank, return a random statement
response = self.storage.get_random()

user = {
input_text: {
"name": user_name,
"date": self.timestamp()
}
}
statement = list(response.keys())[0]
values = response[statement]

previous_statement = self.get_last_statement()
response_list = self.update_response_list(statement, previous_statement)

count = self.update_occurrence_count(values)

values["name"] = user_name
values["date"] = self.timestamp()
values["occurrence"] = count
values["in_response_to"] = response_list

self.recent_statements.append(list(response.keys())[0])

return {
user_name: user,
user_name: {
input_text: values
},
"bot": response
}

Expand All @@ -143,6 +145,6 @@ def get_response(self, input_text, user_name="user"):

# Update the database before selecting a response if logging is enabled
if self.log:
self.update_log(response[user_name])
self.update_log(**response[user_name])

return list(response["bot"].keys())[0]

0 comments on commit 292b3a6

Please sign in to comment.