Пример #1
0
class ClosestMatchAdapterTests(TestCase):

    def setUp(self):
        self.adapter = ClosestMatchAdapter(None)

    def test_get_closest_statement(self):
        possible_choices = [
            Statement("Who do you love?"),
            Statement("What is the meaning of life?"),
            Statement("I am Iron Man."),
            Statement("What... is your quest?"),
            Statement("Yuck, black licorice jelly beans."),
            Statement("I hear you are going on a quest?"),
        ]
        statement = Statement("What is your quest?")

        close = self.adapter.get(statement, possible_choices)

        self.assertEqual("What... is your quest?", close)

    def test_no_choices(self):
        possible_choices = []
        statement = Statement("What is your quest?")

        with self.assertRaises(EmptyDatasetException):
            self.adapter.get(statement, possible_choices)
Пример #2
0
class ClosestMatchAdapterTests(TestCase):

    def setUp(self):
        self.adapter = ClosestMatchAdapter()

    def test_no_choices(self):
        from chatterbot.adapters.exceptions import EmptyDatasetException

        possible_choices = []
        statement = Statement("What is your quest?")

        with self.assertRaises(EmptyDatasetException):
            self.adapter.get(statement, possible_choices)

    def test_get_closest_statement(self):
        possible_choices = [
            Statement("Who do you love?"),
            Statement("What is the meaning of life?"),
            Statement("I am Iron Man."),
            Statement("What... is your quest?"),
            Statement("Yuck, black licorice jelly beans."),
            Statement("I hear you are going on a quest?"),
        ]
        statement = Statement("What is your quest?")

        confidence, match = self.adapter.get(statement, possible_choices)

        self.assertEqual("What... is your quest?", match)
Пример #3
0
class ClosestMatchAdapterTests(TestCase):

    def setUp(self):
        self.adapter = ClosestMatchAdapter()

    def test_get_closest_statement(self):
        possible_choices = [
            Statement("Who do you love?"),
            Statement("What is the meaning of life?"),
            Statement("I am Iron Man."),
            Statement("What... is your quest?"),
            Statement("Yuck, black licorice jelly beans."),
            Statement("I hear you are going on a quest?"),
        ]
        statement = Statement("What is your quest?")

        close = self.adapter.get(statement, possible_choices)

        self.assertEqual("What... is your quest?", close)

    def test_no_choices(self):
        possible_choices = []
        statement = Statement("What is your quest?")

        close = self.adapter.get(statement, possible_choices)

        self.assertEqual("What is your quest?", close)
Пример #4
0
class ClosestMatchAdapterTests(TestCase):

    def setUp(self):
        self.adapter = ClosestMatchAdapter()

    def test_no_choices(self):
        from chatterbot.adapters.exceptions import EmptyDatasetException

        possible_choices = []
        statement = Statement("What is your quest?")

        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("Who do you love?", in_response_to=[Response("I hear you are going on a quest?")]),
            Statement("What is the meaning of life?", in_response_to=[Response("Yuck, black licorice jelly beans.")]),
            Statement("I am Iron Man.", in_response_to=[Response("What... is your quest?")]),
            Statement("What... is your quest?", in_response_to=[Response("I am Iron Man.")]),
            Statement("Yuck, black licorice jelly beans.", in_response_to=[Response("What is the meaning of life?")]),
            Statement("I hear you are going on a quest?", in_response_to=[Response("Who do you love?")]),
        ]
        statement = Statement("What is your quest?")

        confidence, match = self.adapter.get(statement, possible_choices)

        self.assertEqual("What... is your quest?", match)
Пример #5
0
    def test_get_closest_statement(self):

        adapter = ClosestMatchAdapter()

        possible_choices = [
            "Who do you love?",
            "What is the meaning of life?",
            "I am Iron Man.",
            "What... is your quest?",
            "Yuck, black licorice jelly beans.",
            "I hear you are going on a quest?",
        ]

        close = adapter.get("What is your quest?", possible_choices)

        self.assertEqual("What... is your quest?", close)
Пример #6
0
    def test_get_closest_statement(self):

        adapter = ClosestMatchAdapter()

        possible_choices = [
            "Who do you love?",
            "What is the meaning of life?",
            "I am Iron Man.",
            "What... is your quest?",
            "Yuck, black licorice jelly beans.",
            "I hear you are going on a quest?",
        ]

        close = adapter.get("What is your quest?", possible_choices)

        self.assertEqual("What... is your quest?", close)
Пример #7
0
 def setUp(self):
     self.adapter = ClosestMatchAdapter()
Пример #8
0
    def __init__(self):
        self.storage = StorageAdapter()

        self.storage.get_random = Mock(
            side_effect=ClosestMatchAdapter.EmptyDatasetException())
Пример #9
0
    def setUp(self):
        self.adapter = ClosestMatchAdapter()

        # Add a mock storage adapter to the context
        self.adapter.set_context(MockContext())
Пример #10
0
class ClosestMatchAdapterTests(TestCase):
    def setUp(self):
        self.adapter = ClosestMatchAdapter()

        # 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("What is your quest?")

        with self.assertRaises(ClosestMatchAdapter.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(
                "Who do you love?",
                in_response_to=[Response("I hear you are going on a quest?")]),
            Statement("What is the meaning of life?",
                      in_response_to=[
                          Response("Yuck, black licorice jelly beans.")
                      ]),
            Statement("I am Iron Man.",
                      in_response_to=[Response("What... is your quest?")]),
            Statement("What... is your quest?",
                      in_response_to=[Response("I am Iron Man.")]),
            Statement(
                "Yuck, black licorice jelly beans.",
                in_response_to=[Response("What is the meaning of life?")]),
            Statement("I hear you are going on a quest?",
                      in_response_to=[Response("Who do you love?")]),
        ]
        self.adapter.context.storage.filter = MagicMock(
            return_value=possible_choices)

        statement = Statement("What is your quest?")

        confidence, match = self.adapter.get(statement)

        self.assertEqual("What... is your quest?", match)

    def test_confidence_exact_match(self):
        possible_choices = [
            Statement("What is your quest?",
                      in_response_to=[Response("What is your quest?")])
        ]
        self.adapter.context.storage.filter = MagicMock(
            return_value=possible_choices)

        statement = Statement("What is your quest?")
        confidence, match = self.adapter.get(statement)

        self.assertEqual(confidence, 1)

    def test_confidence_half_match(self):
        possible_choices = [
            Statement("xxyy", in_response_to=[Response("xxyy")])
        ]
        self.adapter.context.storage.filter = MagicMock(
            return_value=possible_choices)

        statement = Statement("wwxx")
        confidence, match = self.adapter.get(statement)

        self.assertEqual(confidence, 0.5)

    def test_confidence_no_match(self):
        possible_choices = [Statement("xxx", in_response_to=[Response("xxx")])]
        self.adapter.context.storage.filter = MagicMock(
            return_value=possible_choices)

        statement = Statement("yyy")
        confidence, match = self.adapter.get(statement)

        self.assertEqual(confidence, 0)

    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")
Пример #11
0
 def setUp(self):
     self.adapter = ClosestMatchAdapter()
Пример #12
0
class ClosestMatchAdapterTests(TestCase):
    def setUp(self):
        self.adapter = ClosestMatchAdapter()

    def test_no_choices(self):
        from chatterbot.adapters.exceptions import EmptyDatasetException

        possible_choices = []
        statement = Statement("What is your quest?")

        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(
                "Who do you love?",
                in_response_to=[Response("I hear you are going on a quest?")]),
            Statement("What is the meaning of life?",
                      in_response_to=[
                          Response("Yuck, black licorice jelly beans.")
                      ]),
            Statement("I am Iron Man.",
                      in_response_to=[Response("What... is your quest?")]),
            Statement("What... is your quest?",
                      in_response_to=[Response("I am Iron Man.")]),
            Statement(
                "Yuck, black licorice jelly beans.",
                in_response_to=[Response("What is the meaning of life?")]),
            Statement("I hear you are going on a quest?",
                      in_response_to=[Response("Who do you love?")]),
        ]
        statement = Statement("What is your quest?")

        confidence, match = self.adapter.get(statement, possible_choices)

        self.assertEqual("What... is your quest?", match)

    def test_confidence_exact_match(self):
        possible_choices = [
            Statement("What is your quest?",
                      in_response_to=[Response("What is your quest?")])
        ]

        statement = Statement("What is your quest?")

        confidence, match = self.adapter.get(statement, possible_choices)

        self.assertEqual(confidence, 1)

    def test_confidence_half_match(self):
        possible_choices = [
            Statement("xxyy", in_response_to=[Response("xxyy")])
        ]

        statement = Statement("wwxx")

        confidence, match = self.adapter.get(statement, possible_choices)

        self.assertEqual(confidence, 0.5)

    def test_confidence_no_match(self):
        possible_choices = [Statement("xxx", in_response_to=[Response("xxx")])]

        statement = Statement("yyy")

        confidence, match = self.adapter.get(statement, possible_choices)

        self.assertEqual(confidence, 0)
Пример #13
0
    def setUp(self):
        self.adapter = ClosestMatchAdapter()

        # Add a mock storage adapter to the context
        self.adapter.set_context(MockContext())
Пример #14
0
class ClosestMatchAdapterTests(TestCase):

    def setUp(self):
        self.adapter = ClosestMatchAdapter()

        # 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("What is your quest?")

        with self.assertRaises(ClosestMatchAdapter.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("Who do you love?", in_response_to=[Response("I hear you are going on a quest?")]),
            Statement("What is the meaning of life?", in_response_to=[Response("Yuck, black licorice jelly beans.")]),
            Statement("I am Iron Man.", in_response_to=[Response("What... is your quest?")]),
            Statement("What... is your quest?", in_response_to=[Response("I am Iron Man.")]),
            Statement("Yuck, black licorice jelly beans.", in_response_to=[Response("What is the meaning of life?")]),
            Statement("I hear you are going on a quest?", in_response_to=[Response("Who do you love?")]),
        ]
        self.adapter.context.storage.filter = MagicMock(return_value=possible_choices)

        statement = Statement("What is your quest?")

        confidence, match = self.adapter.get(statement)

        self.assertEqual("What... is your quest?", match)

    def test_confidence_exact_match(self):
        possible_choices = [
            Statement("What is your quest?", in_response_to=[Response("What is your quest?")])
        ]
        self.adapter.context.storage.filter = MagicMock(return_value=possible_choices)

        statement = Statement("What is your quest?")
        confidence, match = self.adapter.get(statement)

        self.assertEqual(confidence, 1)

    def test_confidence_half_match(self):
        possible_choices = [
            Statement("xxyy", in_response_to=[Response("xxyy")])
        ]
        self.adapter.context.storage.filter = MagicMock(return_value=possible_choices)

        statement = Statement("wwxx")
        confidence, match = self.adapter.get(statement)

        self.assertEqual(confidence, 0.5)

    def test_confidence_no_match(self):
        possible_choices = [
            Statement("xxx", in_response_to=[Response("xxx")])
        ]
        self.adapter.context.storage.filter = MagicMock(return_value=possible_choices)

        statement = Statement("yyy")
        confidence, match = self.adapter.get(statement)

        self.assertEqual(confidence, 0)