Skip to content

Commit

Permalink
Add conversations for training statements
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Mar 4, 2018
1 parent 69e8834 commit 01b1153
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions chatterbot/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def __init__(self, storage, **kwargs):
self.chatbot = kwargs.get('chatbot')
self.storage = storage
self.logger = logging.getLogger(__name__)

self.show_training_progress = kwargs.get('show_training_progress', True)

self.training_conversation_id = self.storage.create_conversation()

def get_preprocessed_statement(self, input_statement):
"""
Preprocess the input statement.
Expand Down Expand Up @@ -113,9 +116,13 @@ def train(self, conversation):
statement.add_response(
Response(previous_statement_text)
)
self.storage.add_to_conversation(
self.training_conversation_id,
statement,
Statement(text=previous_statement_text)
)

previous_statement_text = statement.text
self.storage.update(statement)


class ChatterBotCorpusTrainer(Trainer):
Expand Down Expand Up @@ -163,9 +170,15 @@ def train(self, *corpus_paths):
statement.add_response(
Response(previous_statement_text)
)
self.storage.add_to_conversation(
self.training_conversation_id,
statement,
Response(text=previous_statement_text)
)
else:
self.storage.update(statement)

previous_statement_text = statement.text
self.storage.update(statement)


class TwitterTrainer(Trainer):
Expand Down Expand Up @@ -421,6 +434,4 @@ def train(self):
statement.add_response(
Response(previous_statement_text)
)

previous_statement_text = statement.text
self.storage.update(statement)

0 comments on commit 01b1153

Please sign in to comment.