Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace conversation folder with a single file #1154

Merged
merged 1 commit into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from .response import Response


class StatementMixin(object):
"""
This class has shared methods used to
Expand Down Expand Up @@ -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 '<Response text:%s>' % (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
8 changes: 0 additions & 8 deletions chatterbot/conversation/__init__.py

This file was deleted.

43 changes: 0 additions & 43 deletions chatterbot/conversation/response.py

This file was deleted.

4 changes: 2 additions & 2 deletions chatterbot/ext/django_chatterbot/abstract_models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chatterbot/ext/sqlalchemy_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions chatterbot/storage/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
'chatterbot.output',
'chatterbot.storage',
'chatterbot.logic',
'chatterbot.conversation',
'chatterbot.ext',
'chatterbot.ext.sqlalchemy_app',
'chatterbot.ext.django_chatterbot',
Expand Down