rename to chatterbot

pull/1/head
Bobloy 7 years ago
parent 6697ed3b92
commit 5d2a13f2a3

@ -5,8 +5,8 @@ import discord
from discord.ext import commands from discord.ext import commands
from redbot.core import Config from redbot.core import Config
from .source import ChatBot from .chatterbot import ChatBot
from .source.trainers import ListTrainer from .chatterbot.trainers import ListTrainer
class Chatter: class Chatter:
@ -23,7 +23,11 @@ class Chatter:
"days": 1 "days": 1
} }
self.chatbot = ChatBot("ChatterBot") self.chatbot = ChatBot(
"ChatterBot",
storage_adapter='chatterbot.storage.SQLStorageAdapter',
database='./database.sqlite3'
)
self.chatbot.set_trainer(ListTrainer) self.chatbot.set_trainer(ListTrainer)
self.config.register_global(**default_global) self.config.register_global(**default_global)

@ -3,7 +3,7 @@ ChatterBot is a machine learning, conversational dialog engine.
""" """
from .chatterbot import ChatBot from .chatterbot import ChatBot
__version__ = '0.8.4' __version__ = '0.8.5'
__author__ = 'Gunther Cox' __author__ = 'Gunther Cox'
__email__ = 'gunthercx@gmail.com' __email__ = 'gunthercx@gmail.com'
__url__ = 'https://github.com/gunthercox/ChatterBot' __url__ = 'https://github.com/gunthercox/ChatterBot'

@ -16,7 +16,7 @@ class Adapter(object):
""" """
Gives the adapter access to an instance of the ChatBot class. Gives the adapter access to an instance of the ChatBot class.
:param chatbot: A chat bot instanse. :param chatbot: A chat bot instance.
:type chatbot: ChatBot :type chatbot: ChatBot
""" """
self.chatbot = chatbot self.chatbot = chatbot

@ -20,15 +20,15 @@ class ChatBot(object):
self.default_session = None self.default_session = None
storage_adapter = kwargs.get('storage_adapter', 'chatter.source.storage.SQLStorageAdapter') storage_adapter = kwargs.get('storage_adapter', 'chatterbot.storage.SQLStorageAdapter')
logic_adapters = kwargs.get('logic_adapters', [ logic_adapters = kwargs.get('logic_adapters', [
'chatter.source.logic.BestMatch' 'chatterbot.logic.BestMatch'
]) ])
input_adapter = kwargs.get('input_adapter', 'chatter.source.input.VariableInputTypeAdapter') input_adapter = kwargs.get('input_adapter', 'chatterbot.input.VariableInputTypeAdapter')
output_adapter = kwargs.get('output_adapter', 'chatter.source.output.OutputAdapter') output_adapter = kwargs.get('output_adapter', 'chatterbot.output.OutputAdapter')
# Check that each adapter is a valid subclass of it's respective parent # Check that each adapter is a valid subclass of it's respective parent
utils.validate_adapter_class(storage_adapter, StorageAdapter) utils.validate_adapter_class(storage_adapter, StorageAdapter)
@ -45,7 +45,7 @@ class ChatBot(object):
# Add required system logic adapter # Add required system logic adapter
self.logic.system_adapters.append( self.logic.system_adapters.append(
utils.initialize_class('chatter.source.logic.NoKnowledgeAdapter', **kwargs) utils.initialize_class('chatterbot.logic.NoKnowledgeAdapter', **kwargs)
) )
for adapter in logic_adapters: for adapter in logic_adapters:
@ -59,7 +59,7 @@ class ChatBot(object):
preprocessors = kwargs.get( preprocessors = kwargs.get(
'preprocessors', [ 'preprocessors', [
'chatter.source.preprocessors.clean_whitespace' 'chatterbot.preprocessors.clean_whitespace'
] ]
) )
@ -69,7 +69,7 @@ class ChatBot(object):
self.preprocessors.append(utils.import_module(preprocessor)) self.preprocessors.append(utils.import_module(preprocessor))
# Use specified trainer or fall back to the default # Use specified trainer or fall back to the default
trainer = kwargs.get('trainer', 'chatter.source.trainers.Trainer') trainer = kwargs.get('trainer', 'chatterbot.trainers.Trainer')
TrainerClass = utils.import_module(trainer) TrainerClass = utils.import_module(trainer)
self.trainer = TrainerClass(self.storage, **kwargs) self.trainer = TrainerClass(self.storage, **kwargs)
self.training_data = kwargs.get('training_data') self.training_data = kwargs.get('training_data')

@ -130,7 +130,7 @@ class SynsetDistance(Comparator):
""" """
from nltk.corpus import wordnet from nltk.corpus import wordnet
from nltk import word_tokenize from nltk import word_tokenize
from . import utils from chatterbot import utils
import itertools import itertools
tokens1 = word_tokenize(statement.text.lower()) tokens1 = word_tokenize(statement.text.lower())

@ -0,0 +1,3 @@
default_app_config = (
'chatterbot.ext.django_chatterbot.apps.DjangoChatterBotConfig'
)

@ -1,5 +1,5 @@
from ...conversation import StatementMixin from chatterbot.conversation import StatementMixin
from ... import constants from chatterbot import constants
from django.db import models from django.db import models
from django.apps import apps from django.apps import apps
from django.utils import timezone from django.utils import timezone

@ -1,5 +1,5 @@
from django.contrib import admin from django.contrib import admin
from .models import ( from chatterbot.ext.django_chatterbot.models import (
Statement, Response, Conversation, Tag Statement, Response, Conversation, Tag
) )

@ -3,6 +3,6 @@ from django.apps import AppConfig
class DjangoChatterBotConfig(AppConfig): class DjangoChatterBotConfig(AppConfig):
name = 'chatter.source.ext.django_chatterbot' name = 'chatterbot.ext.django_chatterbot'
label = 'django_chatterbot' label = 'django_chatterbot'
verbose_name = 'Django ChatterBot' verbose_name = 'Django ChatterBot'

@ -2,8 +2,8 @@
These factories are used to generate fake data for testing. These factories are used to generate fake data for testing.
""" """
import factory import factory
from . import models from chatterbot.ext.django_chatterbot import models
from ... import constants from chatterbot import constants
from factory.django import DjangoModelFactory from factory.django import DjangoModelFactory

@ -11,8 +11,8 @@ class Command(BaseCommand):
can_import_settings = True can_import_settings = True
def handle(self, *args, **options): def handle(self, *args, **options):
from ..... import ChatBot from chatterbot import ChatBot
from ... import settings from chatterbot.ext.django_chatterbot import settings
chatterbot = ChatBot(**settings.CHATTERBOT) chatterbot = ChatBot(**settings.CHATTERBOT)

@ -1,4 +1,4 @@
from .abstract_models import ( from chatterbot.ext.django_chatterbot.abstract_models import (
AbstractBaseConversation, AbstractBaseResponse, AbstractBaseConversation, AbstractBaseResponse,
AbstractBaseStatement, AbstractBaseTag AbstractBaseStatement, AbstractBaseTag
) )

@ -2,16 +2,16 @@
Default ChatterBot settings for Django. Default ChatterBot settings for Django.
""" """
from django.conf import settings from django.conf import settings
from ... import constants from chatterbot import constants
CHATTERBOT_SETTINGS = getattr(settings, 'CHATTERBOT', {}) CHATTERBOT_SETTINGS = getattr(settings, 'CHATTERBOT', {})
CHATTERBOT_DEFAULTS = { CHATTERBOT_DEFAULTS = {
'name': 'ChatterBot', 'name': 'ChatterBot',
'storage_adapter': 'chatter.source.storage.DjangoStorageAdapter', 'storage_adapter': 'chatterbot.storage.DjangoStorageAdapter',
'input_adapter': 'chatter.source.input.VariableInputTypeAdapter', 'input_adapter': 'chatterbot.input.VariableInputTypeAdapter',
'output_adapter': 'chatter.source.output.OutputAdapter', 'output_adapter': 'chatterbot.output.OutputAdapter',
'django_app_name': constants.DEFAULT_DJANGO_APP_NAME 'django_app_name': constants.DEFAULT_DJANGO_APP_NAME
} }

@ -1,8 +1,8 @@
import json import json
from django.views.generic import View from django.views.generic import View
from django.http import JsonResponse from django.http import JsonResponse
from ... import ChatBot from chatterbot import ChatBot
from . import settings from chatterbot.ext.django_chatterbot import settings
class ChatterBotViewMixin(object): class ChatterBotViewMixin(object):
@ -28,7 +28,7 @@ class ChatterBotViewMixin(object):
Return the conversation for the session if one exists. Return the conversation for the session if one exists.
Create a new conversation if one does not exist. Create a new conversation if one does not exist.
""" """
from .models import Conversation, Response from chatterbot.ext.django_chatterbot.models import Conversation, Response
class Obj(object): class Obj(object):
def __init__(self): def __init__(self):

@ -3,9 +3,9 @@ from sqlalchemy.orm import relationship
from sqlalchemy.sql import func from sqlalchemy.sql import func
from sqlalchemy.ext.declarative import declared_attr, declarative_base from sqlalchemy.ext.declarative import declared_attr, declarative_base
from ...constants import TAG_NAME_MAX_LENGTH, STATEMENT_TEXT_MAX_LENGTH from chatterbot.constants import TAG_NAME_MAX_LENGTH, STATEMENT_TEXT_MAX_LENGTH
from .types import UnicodeString from chatterbot.ext.sqlalchemy_app.types import UnicodeString
from ...conversation import StatementMixin from chatterbot.conversation import StatementMixin
class ModelBase(object): class ModelBase(object):
@ -73,8 +73,8 @@ class Statement(Base, StatementMixin):
return [tag.name for tag in self.tags] return [tag.name for tag in self.tags]
def get_statement(self): def get_statement(self):
from ...conversation import Statement as StatementObject from chatterbot.conversation import Statement as StatementObject
from ...conversation import Response as ResponseObject from chatterbot.conversation import Response as ResponseObject
statement = StatementObject( statement = StatementObject(
self.text, self.text,

@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from time import sleep from time import sleep
from . import InputAdapter from chatterbot.input import InputAdapter
from ..conversation import Statement from chatterbot.conversation import Statement
class Gitter(InputAdapter): class Gitter(InputAdapter):

@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from time import sleep from time import sleep
from . import InputAdapter from chatterbot.input import InputAdapter
from ..conversation import Statement from chatterbot.conversation import Statement
class HipChat(InputAdapter): class HipChat(InputAdapter):

@ -1,5 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from ..adapters import Adapter from chatterbot.adapters import Adapter
class InputAdapter(Adapter): class InputAdapter(Adapter):

@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime import datetime
from . import InputAdapter from chatterbot.input import InputAdapter
from ..conversation import Statement from chatterbot.conversation import Statement
class Mailgun(InputAdapter): class Mailgun(InputAdapter):

@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from time import sleep from time import sleep
from . import InputAdapter from chatterbot.input import InputAdapter
from ..conversation import Statement from chatterbot.conversation import Statement
class Microsoft(InputAdapter): class Microsoft(InputAdapter):

@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from . import InputAdapter from chatterbot.input import InputAdapter
from ..conversation import Statement from chatterbot.conversation import Statement
from ..utils import input_function from chatterbot.utils import input_function
class TerminalAdapter(InputAdapter): class TerminalAdapter(InputAdapter):

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from . import InputAdapter from chatterbot.input import InputAdapter
from ..conversation import Statement from chatterbot.conversation import Statement
class VariableInputTypeAdapter(InputAdapter): class VariableInputTypeAdapter(InputAdapter):

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from ..adapters import Adapter from chatterbot.adapters import Adapter
from ..utils import import_module from chatterbot.utils import import_module
class LogicAdapter(Adapter): class LogicAdapter(Adapter):
@ -17,8 +17,8 @@ class LogicAdapter(Adapter):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LogicAdapter, self).__init__(**kwargs) super(LogicAdapter, self).__init__(**kwargs)
from ..comparisons import levenshtein_distance from chatterbot.comparisons import levenshtein_distance
from ..response_selection import get_first_response from chatterbot.response_selection import get_first_response
# Import string module parameters # Import string module parameters
if 'statement_comparison_function' in kwargs: if 'statement_comparison_function' in kwargs:

@ -1,5 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from ..conversation import Statement from chatterbot.conversation import Statement
from .best_match import BestMatch from .best_match import BestMatch

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from . import LogicAdapter from chatterbot.logic import LogicAdapter
from ..conversation import Statement from chatterbot.conversation import Statement
class MathematicalEvaluation(LogicAdapter): class MathematicalEvaluation(LogicAdapter):

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from collections import Counter from collections import Counter
from .. import utils from chatterbot import utils
from .logic_adapter import LogicAdapter from .logic_adapter import LogicAdapter
@ -13,7 +13,7 @@ class MultiLogicAdapter(LogicAdapter):
""" """
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super(MultiLogicAdapter, self).__init__(**kwargs)
# Logic adapters added by the chat bot # Logic adapters added by the chat bot
self.adapters = [] self.adapters = []

@ -15,7 +15,7 @@ class SpecificResponseAdapter(LogicAdapter):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(SpecificResponseAdapter, self).__init__(**kwargs) super(SpecificResponseAdapter, self).__init__(**kwargs)
from ..conversation import Statement from chatterbot.conversation import Statement
self.input_text = kwargs.get('input_text') self.input_text = kwargs.get('input_text')

@ -79,7 +79,7 @@ class TimeLogicAdapter(LogicAdapter):
return features return features
def process(self, statement): def process(self, statement):
from ..conversation import Statement from chatterbot.conversation import Statement
now = datetime.now() now = datetime.now()

@ -1,4 +1,4 @@
from ..adapters import Adapter from chatterbot.adapters import Adapter
class OutputAdapter(Adapter): class OutputAdapter(Adapter):

@ -1,5 +1,5 @@
from . import StorageAdapter from chatterbot.storage import StorageAdapter
from .. import constants from chatterbot import constants
class DjangoStorageAdapter(StorageAdapter): class DjangoStorageAdapter(StorageAdapter):

@ -1,4 +1,4 @@
from . import StorageAdapter from chatterbot.storage import StorageAdapter
class Query(object): class Query(object):
@ -116,7 +116,7 @@ class MongoDatabaseAdapter(StorageAdapter):
""" """
Return the class for the statement model. Return the class for the statement model.
""" """
from ..conversation import Statement from chatterbot.conversation import Statement
# Create a storage-aware statement # Create a storage-aware statement
statement = Statement statement = Statement
@ -128,7 +128,7 @@ class MongoDatabaseAdapter(StorageAdapter):
""" """
Return the class for the response model. Return the class for the response model.
""" """
from ..conversation import Response from chatterbot.conversation import Response
# Create a storage-aware response # Create a storage-aware response
response = Response response = Response

@ -1,8 +1,8 @@
from . import StorageAdapter from chatterbot.storage import StorageAdapter
def get_response_table(response): def get_response_table(response):
from ..ext.sqlalchemy_app.models import Response from chatterbot.ext.sqlalchemy_app.models import Response
return Response(text=response.text, occurrence=response.occurrence) return Response(text=response.text, occurrence=response.occurrence)
@ -86,28 +86,28 @@ class SQLStorageAdapter(StorageAdapter):
""" """
Return the statement model. Return the statement model.
""" """
from ..ext.sqlalchemy_app.models import Statement from chatterbot.ext.sqlalchemy_app.models import Statement
return Statement return Statement
def get_response_model(self): def get_response_model(self):
""" """
Return the response model. Return the response model.
""" """
from ..ext.sqlalchemy_app.models import Response from chatterbot.ext.sqlalchemy_app.models import Response
return Response return Response
def get_conversation_model(self): def get_conversation_model(self):
""" """
Return the conversation model. Return the conversation model.
""" """
from ..ext.sqlalchemy_app.models import Conversation from chatterbot.ext.sqlalchemy_app.models import Conversation
return Conversation return Conversation
def get_tag_model(self): def get_tag_model(self):
""" """
Return the conversation model. Return the conversation model.
""" """
from ..ext.sqlalchemy_app.models import Tag from chatterbot.ext.sqlalchemy_app.models import Tag
return Tag return Tag
def count(self): def count(self):
@ -379,14 +379,14 @@ class SQLStorageAdapter(StorageAdapter):
""" """
Drop the database attached to a given adapter. Drop the database attached to a given adapter.
""" """
from ..ext.sqlalchemy_app.models import Base from chatterbot.ext.sqlalchemy_app.models import Base
Base.metadata.drop_all(self.engine) Base.metadata.drop_all(self.engine)
def create(self): def create(self):
""" """
Populate the database with the tables. Populate the database with the tables.
""" """
from ..ext.sqlalchemy_app.models import Base from chatterbot.ext.sqlalchemy_app.models import Base
Base.metadata.create_all(self.engine) Base.metadata.create_all(self.engine)
def _session_finish(self, session, statement_text=None): def _session_finish(self, session, statement_text=None):

@ -1,3 +0,0 @@
default_app_config = (
'chatter.source.ext.django_chatterbot.apps.DjangoChatterBotConfig'
)
Loading…
Cancel
Save