diff --git a/chatterbot/conversation/statement.py b/chatterbot/conversation.py similarity index 83% rename from chatterbot/conversation/statement.py rename to chatterbot/conversation.py index dd3e5ca7a..58d2c8142 100644 --- a/chatterbot/conversation/statement.py +++ b/chatterbot/conversation.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -from .response import Response - - class StatementMixin(object): """ This class has shared methods used to @@ -186,3 +182,48 @@ def __init__(self, value='Received an unexpected value type.'): def __str__(self): return repr(self.value) + + +class Response(object): + """ + A response represents an entity which response to a statement. + """ + + def __init__(self, text, **kwargs): + from datetime import datetime + import dateutil.parser as date_parser + + self.text = text + self.created_at = kwargs.get('created_at', datetime.now()) + self.occurrence = kwargs.get('occurrence', 1) + + if not isinstance(self.created_at, datetime): + self.created_at = date_parser.parse(self.created_at) + + def __str__(self): + return self.text + + def __repr__(self): + return '' % (self.text) + + def __hash__(self): + return hash(self.text) + + def __eq__(self, other): + if not other: + return False + + if isinstance(other, Response): + return self.text == other.text + + return self.text == other + + def serialize(self): + data = {} + + data['text'] = self.text + data['created_at'] = self.created_at.isoformat() + + data['occurrence'] = self.occurrence + + return data diff --git a/chatterbot/conversation/__init__.py b/chatterbot/conversation/__init__.py deleted file mode 100644 index bd0e70491..000000000 --- a/chatterbot/conversation/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from .statement import Statement -from .response import Response - - -__all__ = ( - 'Statement', - 'Response' -) diff --git a/chatterbot/conversation/response.py b/chatterbot/conversation/response.py deleted file mode 100644 index 981d4dea3..000000000 --- a/chatterbot/conversation/response.py +++ /dev/null @@ -1,43 +0,0 @@ -class Response(object): - """ - A response represents an entity which response to a statement. - """ - - def __init__(self, text, **kwargs): - from datetime import datetime - import dateutil.parser as date_parser - - self.text = text - self.created_at = kwargs.get('created_at', datetime.now()) - self.occurrence = kwargs.get('occurrence', 1) - - if not isinstance(self.created_at, datetime): - self.created_at = date_parser.parse(self.created_at) - - def __str__(self): - return self.text - - def __repr__(self): - return '' % (self.text) - - def __hash__(self): - return hash(self.text) - - def __eq__(self, other): - if not other: - return False - - if isinstance(other, Response): - return self.text == other.text - - return self.text == other - - def serialize(self): - data = {} - - data['text'] = self.text - data['created_at'] = self.created_at.isoformat() - - data['occurrence'] = self.occurrence - - return data diff --git a/chatterbot/ext/django_chatterbot/abstract_models.py b/chatterbot/ext/django_chatterbot/abstract_models.py index 2cbcebe28..9d9985676 100644 --- a/chatterbot/ext/django_chatterbot/abstract_models.py +++ b/chatterbot/ext/django_chatterbot/abstract_models.py @@ -1,4 +1,4 @@ -from chatterbot.conversation.statement import StatementMixin +from chatterbot.conversation import StatementMixin from chatterbot import constants from django.db import models from django.apps import apps @@ -129,7 +129,7 @@ def get_response_count(self, statement): as a response to the current statement. :param statement: The statement object to get the count for. - :type statement: chatterbot.conversation.statement.Statement + :type statement: chatterbot.conversation.Statement :returns: Return the number of times the statement has been used as a response. :rtype: int diff --git a/chatterbot/ext/sqlalchemy_app/models.py b/chatterbot/ext/sqlalchemy_app/models.py index 8be09f86e..de07cec15 100644 --- a/chatterbot/ext/sqlalchemy_app/models.py +++ b/chatterbot/ext/sqlalchemy_app/models.py @@ -3,7 +3,7 @@ from sqlalchemy.sql import func from sqlalchemy.ext.declarative import declared_attr, declarative_base from chatterbot.ext.sqlalchemy_app.types import UnicodeString -from chatterbot.conversation.statement import StatementMixin +from chatterbot.conversation import StatementMixin class ModelBase(object): diff --git a/chatterbot/storage/mongodb.py b/chatterbot/storage/mongodb.py index 9c6e332d8..744d672e6 100644 --- a/chatterbot/storage/mongodb.py +++ b/chatterbot/storage/mongodb.py @@ -116,7 +116,7 @@ def get_statement_model(self): """ Return the class for the statement model. """ - from chatterbot.conversation.statement import Statement + from chatterbot.conversation import Statement # Create a storage-aware statement statement = Statement @@ -128,7 +128,7 @@ def get_response_model(self): """ Return the class for the response model. """ - from chatterbot.conversation.response import Response + from chatterbot.conversation import Response # Create a storage-aware response response = Response diff --git a/setup.py b/setup.py index c1b9ac824..7ff6c20f1 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,6 @@ 'chatterbot.output', 'chatterbot.storage', 'chatterbot.logic', - 'chatterbot.conversation', 'chatterbot.ext', 'chatterbot.ext.sqlalchemy_app', 'chatterbot.ext.django_chatterbot',