How to use ChatterBot - 10 common examples

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 / storage / test_mongo_adapter.py View on Github external
def test_update_modifies_existing_statement(self):
        statement = Statement(text="New statement")
        self.adapter.update(statement)

        # Check the initial values
        results = list(self.adapter.filter(text=statement.text))

        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].in_response_to, None)

        # Update the statement value
        statement.in_response_to = "New response"

        self.adapter.update(statement)

        # Check that the values have changed
        results = list(self.adapter.filter(text=statement.text))
github gunthercox / ChatterBot / tests / test_comparisons.py View on Github external
def test_levenshtein_distance_statement_integer(self):
        """
        Test that an exception is not raised if a statement is initialized
        with an integer value as its text attribute.
        """
        statement = Statement(text=2)
        other_statement = Statement(text='Hello')

        value = self.compare(statement, other_statement)

        self.assertEqual(value, 0)
github gunthercox / ChatterBot / tests / logic / test_time.py View on Github external
def test_positive_input(self):
        statement = Statement(text="Do you know what time it is?")
        response = self.adapter.process(statement)

        self.assertEqual(response.confidence, 1)
        self.assertIn("The current time is ", response.text)
github gunthercox / ChatterBot / tests / logic_adapter_tests / test_multi_adapter.py View on Github external
def process(self, statement):
        response = Statement('Good morning.')
        response.confidence = 0.2
        return response
github gunthercox / ChatterBot / tests / logic / best_match_integration_tests / test_levenshtein_distance.py View on Github external
def test_confidence_half_match(self):
        # Assume that the storage adapter returns a partial match
        self.adapter.chatbot.storage.filter = MagicMock(return_value=[
            Statement(text='xxyy')
        ])

        statement = Statement(text='wwxx')
        match = self.adapter.get(statement)

        self.assertEqual(match.confidence, 0.5)
github gunthercox / ChatterBot / tests / logic / test_unit_conversion.py View on Github external
def test_inches_to_kilometers_variation_2(self):
        statement = Statement(text='how many  inches  in two  kilometers ?')
        self.assertTrue(self.adapter.can_process(statement))
        expected_value = 78740.2
        response_statement = self.adapter.process(statement)
        self.assertIsNotNone(response_statement)
        self.assertLessEqual(abs(response_statement.confidence - 1.0), 1e-10)
        self.assertLessEqual(abs(float(response_statement.text) - expected_value), 0.1)
github gunthercox / ChatterBot / tests / logic / test_best_match.py View on Github external
def test_match_with_no_response(self):
        """
        A response to the input should be returned if a response is known.
        """
        self.chatbot.storage.create(
            text='To eat pasta.',
            in_response_to='What is your quest?'
        )

        statement = Statement(text='What is your quest?')
        response = self.adapter.process(statement)

        self.assertEqual(response.text, 'To eat pasta.')
        self.assertEqual(response.confidence, 0)
github gunthercox / ChatterBot / tests / logic / test_mathematical_evaluation.py View on Github external
def test_e_constant(self):
        statement = Statement(text='What is e plus one ?')
        response = self.adapter.process(statement)
        self.assertEqual(response.text, 'e plus one = 3.718281')
        self.assertEqual(response.confidence, 1)
github gunthercox / ChatterBot / tests_django / test_django_adapter.py View on Github external
def test_create_many_tags(self):
        self.adapter.create_many([
            StatementObject(text='A', tags=['first', 'letter']),
            StatementObject(text='B', tags=['second', 'letter'])
        ])
        results = list(self.adapter.filter())

        self.assertEqual(len(results), 2)
        self.assertIn('letter', results[0].get_tags())
        self.assertIn('letter', results[1].get_tags())
        self.assertIn('first', results[0].get_tags())
        self.assertIn('second', results[1].get_tags())
github gunthercox / chatterbot-corpus / tests / base_case.py View on Github external
def setUp(self):
        self.test_data_directory = None
        self.chatbot = ChatBot('Test Bot', **self.get_kwargs())