class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter() # Add a mock storage adapter to the context self.adapter.set_context(MockContext()) def test_no_choices(self): self.adapter.context.storage.filter = MagicMock(return_value=[]) statement = Statement("Hello") with self.assertRaises(ClosestMeaningAdapter.EmptyDatasetException): self.adapter.get(statement) def test_get_closest_statement(self): """ Note, the content of the in_response_to field for each of the test statements is only required because the logic adapter will filter out any statements that are not in response to a known statement. """ possible_choices = [ Statement("This is a lovely bog.", in_response_to=[Response("This is a lovely bog.")]), Statement("This is a beautiful swamp.", in_response_to=[Response("This is a beautiful swamp.")]), Statement("It smells like swamp.", in_response_to=[Response("It smells like swamp.")]) ] self.adapter.context.storage.filter = MagicMock(return_value=possible_choices) statement = Statement("This is a lovely swamp.") confidence, match = self.adapter.get(statement) self.assertEqual("This is a lovely bog.", match)
class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter() def test_no_choices(self): from chatterbot.adapters.exceptions import EmptyDatasetException possible_choices = [] statement = Statement("Hello") with self.assertRaises(EmptyDatasetException): self.adapter.get(statement, possible_choices) def test_get_closest_statement(self): """ Note, the content of the in_response_to field for each of the test statements is only required because the logic adapter will filter out any statements that are not in response to a known statement. """ possible_choices = [ Statement("This is a lovely bog.", in_response_to=[Response("This is a lovely bog.")]), Statement("This is a beautiful swamp.", in_response_to=[Response("This is a beautiful swamp.")]), Statement("It smells like swamp.", in_response_to=[Response("It smells like swamp.")]) ] statement = Statement("This is a lovely swamp.") confidence, match = self.adapter.get(statement, possible_choices) self.assertEqual("This is a lovely bog.", match)
class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter() def test_no_choices(self): from chatterbot.adapters.exceptions import EmptyDatasetException possible_choices = [] statement = Statement("Hello") with self.assertRaises(EmptyDatasetException): self.adapter.get(statement, possible_choices) def test_get_closest_statement(self): possible_choices = [ Statement("This is a lovely bog."), Statement("This is a beautiful swamp."), Statement("It smells like swamp.") ] statement = Statement("This is a lovely swamp.") confidence, match = self.adapter.get(statement, possible_choices) self.assertEqual("This is a lovely bog.", match)
class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter() # Add a mock storage adapter to the context self.adapter.set_context(MockContext()) def test_no_choices(self): self.adapter.context.storage.filter = MagicMock(return_value=[]) statement = Statement("Hello") with self.assertRaises(ClosestMeaningAdapter.EmptyDatasetException): self.adapter.get(statement) def test_get_closest_statement(self): """ Note, the content of the in_response_to field for each of the test statements is only required because the logic adapter will filter out any statements that are not in response to a known statement. """ possible_choices = [ Statement("This is a lovely bog.", in_response_to=[Response("This is a lovely bog.")]), Statement("This is a beautiful swamp.", in_response_to=[Response("This is a beautiful swamp.")]), Statement("It smells like swamp.", in_response_to=[Response("It smells like swamp.")]) ] self.adapter.context.storage.filter = MagicMock( return_value=possible_choices) statement = Statement("This is a lovely swamp.") confidence, match = self.adapter.get(statement) self.assertEqual("This is a lovely bog.", match)
class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter() def test_no_choices(self): possible_choices = [] close = self.adapter.get("Hello", possible_choices) self.assertEqual("Hello", close) def test_get_closest_statement(self): possible_choices = [ "This is a lovely bog.", "This is a beautiful swamp.", "It smells like swamp." ] close = self.adapter.get("This is a lovely swamp.", possible_choices) self.assertEqual("This is a lovely bog.", close)
class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter(None) def test_no_choices(self): possible_choices = [] statement = Statement("Hello") with self.assertRaises(EmptyDatasetException): self.adapter.get(statement, possible_choices) def test_get_closest_statement(self): possible_choices = [ Statement("This is a lovely bog."), Statement("This is a beautiful swamp."), Statement("It smells like swamp.") ] statement = Statement("This is a lovely swamp.") close = self.adapter.get(statement, possible_choices) self.assertEqual("This is a lovely bog.", close)
class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter() # Add a mock storage adapter to the context self.adapter.set_context(MockContext()) def test_no_choices(self): self.adapter.context.storage.filter = MagicMock(return_value=[]) statement = Statement('Hello') with self.assertRaises(ClosestMeaningAdapter.EmptyDatasetException): self.adapter.get(statement) def test_get_closest_statement(self): """ Note, the content of the in_response_to field for each of the test statements is only required because the logic adapter will filter out any statements that are not in response to a known statement. """ possible_choices = [ Statement('This is a lovely bog.', in_response_to=[Response('This is a lovely bog.')]), Statement('This is a beautiful swamp.', in_response_to=[Response('This is a beautiful swamp.')]), Statement('It smells like swamp.', in_response_to=[Response('It smells like swamp.')]) ] self.adapter.context.storage.filter = MagicMock( return_value=possible_choices ) statement = Statement('This is a lovely swamp.') confidence, match = self.adapter.get(statement) self.assertEqual('This is a lovely bog.', match) def test_different_punctuation(self): possible_choices = [ Statement('Who are you?'), Statement('Are you good?'), Statement('You are good') ] self.adapter.context.storage.get_response_statements = MagicMock( return_value=possible_choices ) statement = Statement('Are you good') confidence, match = self.adapter.get(statement) self.assertEqual('Are you good?', match) def test_no_known_responses(self): """ In the case that a match is selected which has no known responses. In this case a random response will be returned, but the confidence should be zero because it is a random choice. """ self.adapter.context.storage.update = MagicMock() self.adapter.context.storage.filter = MagicMock( return_value=[] ) self.adapter.context.storage.get_random = MagicMock( return_value=Statement("Random") ) confidence, match = self.adapter.process(Statement("Blah")) self.assertEqual(confidence, 0) self.assertEqual(match.text, "Random")
class ClosestMeaningAdapterTests(TestCase): def setUp(self): self.adapter = ClosestMeaningAdapter() # Add a mock storage adapter to the context self.adapter.set_context(MockContext()) def test_no_choices(self): self.adapter.context.storage.filter = MagicMock(return_value=[]) statement = Statement('Hello') with self.assertRaises(ClosestMeaningAdapter.EmptyDatasetException): self.adapter.get(statement) def test_get_closest_statement(self): """ Note, the content of the in_response_to field for each of the test statements is only required because the logic adapter will filter out any statements that are not in response to a known statement. """ possible_choices = [ Statement('This is a lovely bog.', in_response_to=[Response('This is a lovely bog.')]), Statement('This is a beautiful swamp.', in_response_to=[Response('This is a beautiful swamp.')]), Statement('It smells like swamp.', in_response_to=[Response('It smells like swamp.')]) ] self.adapter.context.storage.filter = MagicMock( return_value=possible_choices) statement = Statement('This is a lovely swamp.') confidence, match = self.adapter.get(statement) self.assertEqual('This is a lovely bog.', match) def test_different_punctuation(self): possible_choices = [ Statement('Who are you?'), Statement('Are you good?'), Statement('You are good') ] self.adapter.context.storage.get_response_statements = MagicMock( return_value=possible_choices) statement = Statement('Are you good') confidence, match = self.adapter.get(statement) self.assertEqual('Are you good?', match) def test_no_known_responses(self): """ In the case that a match is selected which has no known responses. In this case a random response will be returned, but the confidence should be zero because it is a random choice. """ self.adapter.context.storage.update = MagicMock() self.adapter.context.storage.filter = MagicMock(return_value=[]) self.adapter.context.storage.get_random = MagicMock( return_value=Statement("Random")) confidence, match = self.adapter.process(Statement("Blah")) self.assertEqual(confidence, 0) self.assertEqual(match.text, "Random")