Search code examples
python-3.xchatterbot

Is it possible to pull answers from an sqlite3 database file with pythons ChatterBot module?


Is it possible to train a chatbot (using ChatterBot) with an existing database?

I have a relatively large sqlite3 db file with about 3GB worth of conversations. If it's at all possible to just pull answers from that database instead of converting it to json and then creating my own corpus I'd like to do so.

That said when I follow their tutorial.

from chatterbot import ChatBot

bot = ChatBot( "Terminal",
    storage_adapter="chatterbot.storage.SQLStorageAdapter",
    logic_adapters=[
    "chatterbot.logic.MathematicalEvaluation",
    "chatterbot.logic.TimeLogicAdapter",
    "chatterbot.logic.BestMatch"
    ],
    input_adapter="chatterbot.input.TerminalAdapter",
    output_adapter="chatterbot.output.TerminalAdapter",
    database="database.db"
   )

print("Type something to begin...")

while True:
    try:
        bot_input = bot.get_response(None)


    except (KeyboardInterrupt, EOFError, SystemExit):
        break

It doesn't pull its answers from that. It ignores it and uses its own training data.


Solution

  • It is possible, but you would need to write your own Trainer class to read your sqlite file's content so that the chat bot could be trained with it.

    Another way to do this would be to write a script to convert your sqlite data to a training corpus format so that you can train your bot with it using the existing methods.

    More information about the corpus format can be found here: http://chatterbot-corpus.readthedocs.io/en/latest/data.html