Merge pull request #13 from bobloy/chatter_fixes

Chatter fixes
pull/15/head
bobloy 7 years ago committed by GitHub
commit 02081d4256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,9 +1,11 @@
import asyncio import asyncio
import pathlib
from datetime import datetime, timedelta from datetime import datetime, timedelta
import discord import discord
from redbot.core import Config from redbot.core import Config
from redbot.core import commands from redbot.core import commands
from redbot.core.data_manager import cog_data_path
from chatter.chatterbot import ChatBot from chatter.chatterbot import ChatBot
from chatter.chatterbot.trainers import ListTrainer from chatter.chatterbot.trainers import ListTrainer
@ -22,11 +24,13 @@ class Chatter:
"whitelist": None, "whitelist": None,
"days": 1 "days": 1
} }
path: pathlib.Path = cog_data_path(self)
data_path = path / ("database.sqlite3")
self.chatbot = ChatBot( self.chatbot = ChatBot(
"ChatterBot", "ChatterBot",
storage_adapter='chatter.chatterbot.storage.SQLStorageAdapter', storage_adapter='chatter.chatterbot.storage.SQLStorageAdapter',
database='./database.sqlite3' database=str(data_path)
) )
self.chatbot.set_trainer(ListTrainer) self.chatbot.set_trainer(ListTrainer)

@ -2,10 +2,7 @@ from __future__ import unicode_literals
import logging import logging
from . import utils from chatter.chatterbot import utils
from .input import InputAdapter
from .output import OutputAdapter
from .storage import StorageAdapter
class ChatBot(object): class ChatBot(object):
@ -14,7 +11,7 @@ class ChatBot(object):
""" """
def __init__(self, name, **kwargs): def __init__(self, name, **kwargs):
from .logic import MultiLogicAdapter from chatter.chatterbot.logic import MultiLogicAdapter
self.name = name self.name = name
kwargs['name'] = name kwargs['name'] = name
@ -33,9 +30,9 @@ class ChatBot(object):
output_adapter = kwargs.get('output_adapter', 'chatter.chatterbot.output.OutputAdapter') output_adapter = kwargs.get('output_adapter', 'chatter.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)
utils.validate_adapter_class(input_adapter, InputAdapter) # utils.validate_adapter_class(input_adapter, InputAdapter)
utils.validate_adapter_class(output_adapter, OutputAdapter) # utils.validate_adapter_class(output_adapter, OutputAdapter)
self.logic = MultiLogicAdapter(**kwargs) self.logic = MultiLogicAdapter(**kwargs)
self.storage = utils.initialize_class(storage_adapter, **kwargs) self.storage = utils.initialize_class(storage_adapter, **kwargs)
@ -139,7 +136,7 @@ class ChatBot(object):
""" """
Learn that the statement provided is a valid response. Learn that the statement provided is a valid response.
""" """
from .conversation import Response from chatter.chatterbot.conversation import Response
if previous_statement: if previous_statement:
statement.add_response( statement.add_response(

@ -92,7 +92,7 @@ class SynsetDistance(Comparator):
""" """
Download required NLTK corpora if they have not already been downloaded. Download required NLTK corpora if they have not already been downloaded.
""" """
from .utils import nltk_download_corpus from chatter.chatterbot.utils import nltk_download_corpus
nltk_download_corpus('corpora/wordnet') nltk_download_corpus('corpora/wordnet')
@ -100,7 +100,7 @@ class SynsetDistance(Comparator):
""" """
Download required NLTK corpora if they have not already been downloaded. Download required NLTK corpora if they have not already been downloaded.
""" """
from .utils import nltk_download_corpus from chatter.chatterbot.utils import nltk_download_corpus
nltk_download_corpus('tokenizers/punkt') nltk_download_corpus('tokenizers/punkt')
@ -108,7 +108,7 @@ class SynsetDistance(Comparator):
""" """
Download required NLTK corpora if they have not already been downloaded. Download required NLTK corpora if they have not already been downloaded.
""" """
from .utils import nltk_download_corpus from chatter.chatterbot.utils import nltk_download_corpus
nltk_download_corpus('corpora/stopwords') nltk_download_corpus('corpora/stopwords')
@ -177,7 +177,7 @@ class SentimentComparison(Comparator):
Download the NLTK vader lexicon for sentiment analysis Download the NLTK vader lexicon for sentiment analysis
that is required for this algorithm to run. that is required for this algorithm to run.
""" """
from .utils import nltk_download_corpus from chatter.chatterbot.utils import nltk_download_corpus
nltk_download_corpus('sentiment/vader_lexicon') nltk_download_corpus('sentiment/vader_lexicon')
@ -252,7 +252,7 @@ class JaccardSimilarity(Comparator):
Download the NLTK wordnet corpora that is required for this algorithm Download the NLTK wordnet corpora that is required for this algorithm
to run only if the corpora has not already been downloaded. to run only if the corpora has not already been downloaded.
""" """
from .utils import nltk_download_corpus from chatter.chatterbot.utils import nltk_download_corpus
nltk_download_corpus('corpora/wordnet') nltk_download_corpus('corpora/wordnet')

@ -1,5 +1,5 @@
from .best_match import BestMatch
from .logic_adapter import LogicAdapter from .logic_adapter import LogicAdapter
from .best_match import BestMatch
from .low_confidence import LowConfidenceAdapter from .low_confidence import LowConfidenceAdapter
from .mathematical_evaluation import MathematicalEvaluation from .mathematical_evaluation import MathematicalEvaluation
from .multi_adapter import MultiLogicAdapter from .multi_adapter import MultiLogicAdapter

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .logic_adapter import LogicAdapter from chatter.chatterbot.logic import LogicAdapter
class BestMatch(LogicAdapter): class BestMatch(LogicAdapter):

@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from chatter.chatterbot.conversation import Statement from chatter.chatterbot.conversation import Statement
from .best_match import BestMatch from chatter.chatterbot.logic import BestMatch
class LowConfidenceAdapter(BestMatch): class LowConfidenceAdapter(BestMatch):

@ -3,7 +3,7 @@ from __future__ import unicode_literals
from collections import Counter from collections import Counter
from chatter.chatterbot import utils from chatter.chatterbot import utils
from .logic_adapter import LogicAdapter from chatter.chatterbot.logic import LogicAdapter
class MultiLogicAdapter(LogicAdapter): class MultiLogicAdapter(LogicAdapter):

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .logic_adapter import LogicAdapter from chatter.chatterbot.logic import LogicAdapter
class NoKnowledgeAdapter(LogicAdapter): class NoKnowledgeAdapter(LogicAdapter):

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .logic_adapter import LogicAdapter from chatter.chatterbot.logic import LogicAdapter
class SpecificResponseAdapter(LogicAdapter): class SpecificResponseAdapter(LogicAdapter):

@ -2,7 +2,7 @@ from __future__ import unicode_literals
from datetime import datetime from datetime import datetime
from .logic_adapter import LogicAdapter from chatter.chatterbot.logic import LogicAdapter
class TimeLogicAdapter(LogicAdapter): class TimeLogicAdapter(LogicAdapter):

@ -1,8 +1,8 @@
from .output_adapter import OutputAdapter
from .gitter import Gitter from .gitter import Gitter
from .hipchat import HipChat from .hipchat import HipChat
from .mailgun import Mailgun from .mailgun import Mailgun
from .microsoft import Microsoft from .microsoft import Microsoft
from .output_adapter import OutputAdapter
from .terminal import TerminalAdapter from .terminal import TerminalAdapter
__all__ = ( __all__ = (

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .output_adapter import OutputAdapter from chatter.chatterbot.output import OutputAdapter
class Gitter(OutputAdapter): class Gitter(OutputAdapter):

@ -2,7 +2,7 @@ from __future__ import unicode_literals
import json import json
from .output_adapter import OutputAdapter from chatter.chatterbot.output import OutputAdapter
class HipChat(OutputAdapter): class HipChat(OutputAdapter):

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .output_adapter import OutputAdapter from chatter.chatterbot.output import OutputAdapter
class Mailgun(OutputAdapter): class Mailgun(OutputAdapter):

@ -2,7 +2,7 @@ from __future__ import unicode_literals
import json import json
from .output_adapter import OutputAdapter from chatter.chatterbot.output import OutputAdapter
class Microsoft(OutputAdapter): class Microsoft(OutputAdapter):

@ -1,6 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .output_adapter import OutputAdapter from chatter.chatterbot.output import OutputAdapter
class TerminalAdapter(OutputAdapter): class TerminalAdapter(OutputAdapter):

@ -2,8 +2,8 @@ import logging
import os import os
import sys import sys
from . import utils from chatter.chatterbot import utils
from .conversation import Statement, Response from chatter.chatterbot.conversation import Statement, Response
class Trainer(object): class Trainer(object):
@ -127,7 +127,7 @@ class ChatterBotCorpusTrainer(Trainer):
def __init__(self, storage, **kwargs): def __init__(self, storage, **kwargs):
super(ChatterBotCorpusTrainer, self).__init__(storage, **kwargs) super(ChatterBotCorpusTrainer, self).__init__(storage, **kwargs)
from .corpus import Corpus from chatter.chatterbot.corpus import Corpus
self.corpus = Corpus() self.corpus = Corpus()

@ -46,7 +46,7 @@ def validate_adapter_class(validate_class, adapter_class):
:raises: Adapter.InvalidAdapterTypeException :raises: Adapter.InvalidAdapterTypeException
""" """
from .adapters import Adapter from chatter.chatterbot.adapters import Adapter
# If a dictionary was passed in, check if it has an import_path attribute # If a dictionary was passed in, check if it has an import_path attribute
if isinstance(validate_class, dict): if isinstance(validate_class, dict):

Loading…
Cancel
Save