How to use the chatterbot.utils function in ChatterBot

To help you get started, we’ve selected a few ChatterBot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gunthercox / ChatterBot / tests / base_case.py View on Github external
def setUp(self):

        # Make sure that test requirements are downloaded
        utils.download_nltk_stopwords()
        utils.download_nltk_wordnet()
        utils.download_nltk_averaged_perceptron_tagger()

        self.chatbot = ChatBot('Test Bot', **self.get_kwargs())
github gunthercox / ChatterBot / tests / benchmarks.py View on Github external
])

except ServerSelectionTimeoutError:
    print('Not running Mongo DB benchmarking')


STATEMENT_LIST = utils.generate_strings(10)

for config in CONFIGURATIONS:
    configuration = BASE_CONFIGURATION.copy()
    configuration.update(config)

    chatbot = ChatBot('Benchmark', **configuration)
    chatbot.train(STATEMENT_LIST)

    durration = utils.get_response_time(chatbot)

    print(configuration['description'])
    print('Durration was {} seconds'.format(durration))
github gunthercox / ChatterBot / tests / benchmarks.py View on Github external
'logic_adapters': [
                {
                    'import_path': 'chatterbot.logic.BestMatch',
                    'statement_comparison_function': 'chatterbot.comparisons.synset_distance',
                    'response_selection_method': 'chatterbot.response_selection.get_first_response'
                }
            ],
            'storage_adapter': 'chatterbot.storage.MongoDatabaseAdapter'
        }
    ])

except ServerSelectionTimeoutError:
    print('Not running Mongo DB benchmarking')


STATEMENT_LIST = utils.generate_strings(10)

for config in CONFIGURATIONS:
    configuration = BASE_CONFIGURATION.copy()
    configuration.update(config)

    chatbot = ChatBot('Benchmark', **configuration)
    chatbot.train(STATEMENT_LIST)

    durration = utils.get_response_time(chatbot)

    print(configuration['description'])
    print('Durration was {} seconds'.format(durration))
github gunthercox / ChatterBot / tests / base_case.py View on Github external
def setUp(self):

        # Make sure that test requirements are downloaded
        utils.download_nltk_stopwords()
        utils.download_nltk_wordnet()
        utils.download_nltk_averaged_perceptron_tagger()

        self.chatbot = ChatBot('Test Bot', **self.get_kwargs())
github gunthercox / ChatterBot / tests / test_benchmarks.py View on Github external
def assert_response_duration_is_less_than(self, maximum_duration, strict=False):
        """
        Assert that the response time did not exceed the maximum allowed amount.

        :param strict: If set to true, test will fail if the maximum duration is exceeded.
        """
        from sys import stdout

        duration = utils.get_response_time(self.chatbot)

        stdout.write('\nBENCHMARK: Duration was %f seconds\n' % duration)

        failure_message = (
            '{duration} was greater than the maximum allowed '
            'response time of {maximum_duration}'.format(
                duration=duration,
                maximum_duration=maximum_duration
            )
        )

        if strict and duration > maximum_duration:
            raise AssertionError(failure_message)
        elif duration > maximum_duration:
            warn(failure_message)
github gunthercox / ChatterBot / tests / test_utils.py View on Github external
def test_import_module(self):
        datetime = utils.import_module('datetime.datetime')
        self.assertTrue(hasattr(datetime, 'now'))
github PySimpleGUI / PySimpleGUI / DemoPrograms / Demo_Chatterbot_With_TTS.py View on Github external
tts = gTTS(text=text, lang='en',slow=False)
    tts.save('speech{}.mp3'.format(i%2))
    # playback the speech
    mixer.music.load('speech{}.mp3'.format(i%2))
    mixer.music.play()
    # wait for playback to end
    while mixer.music.get_busy():
        time.sleep(.1)
    mixer.stop()
    i += 1

i = 0
mixer.init()

# redefine the chatbot text based progress bar with a graphical one
chatterbot.utils.print_progress_bar = print_progress_bar

chatbot = ChatBot('Ron Obvious', trainer='chatterbot.trainers.ChatterBotCorpusTrainer')

# Train based on the english corpus
chatbot.train("chatterbot.corpus.english")

################# GUI #################

layout = [[sg.Output(size=(80, 20))],
          [sg.MLine(size=(70, 5), enter_submits=True),
           sg.Button('SEND', bind_return_key=True), sg.Button('EXIT')]]

window = sg.Window('Chat Window', layout, default_element_size=(30, 2))

# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
while True:
github gunthercox / ChatterBot / chatterbot / chatterbot.py View on Github external
for adapter in logic_adapters:
            utils.validate_adapter_class(adapter, LogicAdapter)
            logic_adapter = utils.initialize_class(adapter, self, **kwargs)
            self.logic_adapters.append(logic_adapter)

        preprocessors = kwargs.get(
            'preprocessors', [
                'chatterbot.preprocessors.clean_whitespace'
            ]
        )

        self.preprocessors = []

        for preprocessor in preprocessors:
            self.preprocessors.append(utils.import_module(preprocessor))

        self.logger = kwargs.get('logger', logging.getLogger(__name__))

        # Allow the bot to save input it receives so that it can learn
        self.read_only = kwargs.get('read_only', False)
github gunthercox / ChatterBot / chatterbot / trainers.py View on Github external
data_file_paths = []

        # Get the paths to each file the bot will be trained with
        for corpus_path in corpus_paths:
            data_file_paths.extend(list_corpus_files(corpus_path))

        for corpus, categories, file_path in load_corpus(*data_file_paths):

            statements_to_create = []

            # Train the chat bot with each statement and response pair
            for conversation_count, conversation in enumerate(corpus):

                if self.show_training_progress:
                    utils.print_progress_bar(
                        'Training ' + str(os.path.basename(file_path)),
                        conversation_count + 1,
                        len(corpus)
                    )

                previous_statement_text = None
                previous_statement_search_text = ''

                for text in conversation:

                    statement_search_text = self.chatbot.storage.tagger.get_bigram_pair_string(text)

                    statement = Statement(
                        text=text,
                        search_text=statement_search_text,
                        in_response_to=previous_statement_text,
github gunthercox / ChatterBot / chatterbot / logic / multi_adapter.py View on Github external
def add_adapter(self, adapter, **kwargs):
        """
        Appends a logic adapter to the list of logic adapters being used.

        :param adapter: The logic adapter to be added.
        :type adapter: `LogicAdapter`
        """
        utils.validate_adapter_class(adapter, LogicAdapter)
        adapter = utils.initialize_class(adapter, **kwargs)
        self.adapters.append(adapter)