コード例 #1
0
    def setUp(self):
        self.parser = TemplateGraph(AIMLParser())
        self.assertIsNotNone(self.parser)

        self.test_brain = None
        self.test_sentence = Sentence("test sentence")

        test_node = PatternOneOrMoreWildCardNode("*")

        self.test_sentence._matched_context = MatchContext()
        self.test_sentence._matched_context._matched_nodes = [
            Match(Match.WORD, test_node, 'one'),
            Match(Match.WORD, test_node, 'two'),
            Match(Match.WORD, test_node, 'three'),
            Match(Match.WORD, test_node, 'four'),
            Match(Match.WORD, test_node, 'five'),
            Match(Match.WORD, test_node, 'six'),
            Match(Match.TOPIC, test_node, '*'),
            Match(Match.THAT, test_node, '*')
        ]

        test_config = ClientConfiguration()

        self.test_bot = Bot(Brain(BrainConfiguration()),
                            config=test_config.bot_configuration)
        self.test_clientid = "testid"

        conversation = self.test_bot.get_conversation(self.test_clientid)
        question = Question.create_from_sentence(self.test_sentence)
        conversation._questions.append(question)
コード例 #2
0
    def test_conversation(self):
        test_brain = Brain(BrainConfiguration())
        test_bot = Bot(test_brain, BotConfiguration())
        conversation = Conversation("test", test_bot, max_histories=3)
        self.assertIsNotNone(conversation)
        self.assertIsNotNone(conversation._bot)
        self.assertIsNotNone(conversation._clientid)
        self.assertEqual(conversation._clientid, "test")
        self.assertEqual(0, len(conversation._questions))
        self.assertEqual(3, conversation._max_histories)
        self.assertEqual(1, len(conversation._predicates))

        question = Question.create_from_text("Hello There")
        conversation.record_dialog(question)
        self.assertEqual(1, len(conversation._questions))

        question = Question.create_from_text("Hello There Again")
        conversation.record_dialog(question)
        self.assertEqual(2, len(conversation._questions))

        question = Question.create_from_text("Hello There Again Again")
        conversation.record_dialog(question)
        self.assertEqual(3, len(conversation._questions))

        question = Question.create_from_text("Hello There Again Again Again")
        conversation.record_dialog(question)
        self.assertEqual(3, len(conversation._questions))
コード例 #3
0
    def test_bot_chat_loop(self):
        test_brain = TestBrain(BrainConfiguration())
        self.assertIsNotNone(test_brain)
        self.assertIsInstance(test_brain, Brain)

        bot = Bot(test_brain, BotConfiguration())
        self.assertIsNotNone(bot)
        self.assertIsInstance(bot, Bot)

        test_brain.setresponse ("response1")
        response = bot.ask_question("testid", "hello")
        self.assertIsNotNone(response)
        self.assertEqual(response, "response1")

        test_brain.setresponse ("response2")
        response = bot.ask_question("testid", "hello again")
        self.assertIsNotNone(response)
        self.assertEqual(response, "response2")

        test_brain.setresponse("response3")
        response = bot.ask_question("testid", "goodbye")
        self.assertIsNotNone(response)
        self.assertEqual(response, "response3")

        conversation = bot.get_conversation("testid")
        self.assertIsNotNone(conversation)

        self.assertEqual(conversation.nth_question(3).sentence(0).text(), "hello")
        self.assertEqual(conversation.nth_question(3).sentence(0).response, "response1")

        self.assertEqual(conversation.nth_question(2).sentence(0).text(), "hello again")
        self.assertEqual(conversation.nth_question(2).sentence(0).response, "response2")

        self.assertEqual(conversation.nth_question(1).sentence(0).text(), "goodbye")
        self.assertEqual(conversation.nth_question(1).sentence(0).response, "response3")
コード例 #4
0
 def test_bot_defaultresponses(self):
     test_brain = Brain(BrainConfiguration())
     bot = Bot(test_brain, BotConfiguration())
     self.assertIsNotNone(bot)
     self.assertEqual(bot.prompt, ">>> ")
     self.assertEqual(bot.default_response, "Sorry, I don't have an answer for that right now")
     self.assertEqual(bot.exit_response, "Bye!")
コード例 #5
0
    def setUp(self):
        self.parser = TemplateGraph()
        self.assertIsNotNone(self.parser)

        self.test_brain = None
        test_config = ClientConfiguration()
        self.test_bot = Bot(Brain(BrainConfiguration()),
                            config=test_config.bot_configuration)
        self.test_clientid = "testid"
コード例 #6
0
ファイル: test_brain.py プロジェクト: datatalking/program-y
    def test_brain_init(self):
        brain = Brain(BrainConfiguration())
        self.assertIsNotNone(brain)

        self.assertIsNotNone(brain._aiml_parser)
        self.assertIsNotNone(brain._denormal_collection)
        self.assertIsNotNone(brain._normal_collection)
        self.assertIsNotNone(brain._gender_collection)
        self.assertIsNotNone(brain._person_collection)
        self.assertIsNotNone(brain._person2_collection)
        self.assertIsNotNone(brain._predicates_collection)
        self.assertIsNotNone(brain._pronouns_collection)
        self.assertIsNotNone(brain._properties_collection)
        self.assertIsNotNone(brain._triples_collection)
        self.assertIsNotNone(brain._sets_collection)
        self.assertIsNotNone(brain._maps_collection)
コード例 #7
0
ファイル: test_think.py プロジェクト: FunRobots/simple_bot
    def setUp(self):
        self.parser = TemplateGraph()
        self.assertIsNotNone(self.parser)

        self.test_brain = None
        self.test_sentence = Sentence("test sentence")
        self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
        self.test_sentence._thatstars = ["*"]
        self.test_sentence._topicstars = ["*"]

        test_config = ClientConfiguration()

        self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
        self.test_clientid = "testid"

        conversation = self.test_bot.get_conversation(self.test_clientid)
        question = Question.create_from_sentence(self.test_sentence)
        conversation._questions.append(question)
コード例 #8
0
    def test_bot_with_config(self):
        configuration = ClientConfiguration()
        self.assertIsNotNone(configuration)
        self.assertIsNotNone(configuration.bot_configuration)
        self.assertIsNotNone(configuration.brain_configuration)

        configuration.bot_configuration.prompt = ":"
        configuration.bot_configuration.default_response = "No answer for that"
        configuration.bot_configuration.exit_response = "See ya!"

        test_brain = Brain(BrainConfiguration())
        test_brain.load(configuration.brain_configuration)

        bot = Bot(test_brain, config=configuration.bot_configuration)
        self.assertIsNotNone(bot)

        self.assertEqual(bot.prompt, ":")
        self.assertEqual(bot.default_response, "No answer for that")
        self.assertEqual(bot.exit_response, "See ya!")
コード例 #9
0
    def test_bot_with_conversation(self):
        test_brain = TestBrain(BrainConfiguration())
        self.assertIsNotNone(test_brain)

        bot = Bot(test_brain, BotConfiguration())
        self.assertIsNotNone(bot)

        self.assertFalse(bot.has_conversation("testid"))

        response = bot.ask_question("testid", "hello")
        self.assertIsNotNone(response)
        self.assertTrue(bot.has_conversation("testid"))

        response = bot.ask_question("testid", "hello")
        self.assertIsNotNone(response)
        self.assertTrue(bot.has_conversation("testid"))

        response = bot.ask_question("testid2", "hello")
        self.assertIsNotNone(response)
        self.assertTrue(bot.has_conversation("testid2"))
コード例 #10
0
    def test_init(self):
        client_config = ClientConfiguration()
        yaml = YamlConfigurationFile(client_config)
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
          supress_warnings: true
          allow_system_aiml: true
          allow_learn_aiml: true
          allow_learnf_aiml: true

          files:
                aiml:

                    files: $BOT_ROOT/aiml
                    extension: .aiml
                    directories: false
                sets:
                    files: $BOT_ROOT/sets
                    extension: .txt
                    directories: false
                maps:
                    files: $BOT_ROOT/maps
                    extension: .txt
                    directories: false
                denormal: $BOT_ROOT/config/denormal.txt
                normal: $BOT_ROOT/config/normal.txt
                gender: $BOT_ROOT/config/gender.txt
                person: $BOT_ROOT/config/person.txt
                person2: $BOT_ROOT/config/person2.txt
                predicates: $BOT_ROOT/config/predicates.txt
                pronouns: $BOT_ROOT/config/pronouns.txt
                properties: $BOT_ROOT/config/properties.txt
                triples: $BOT_ROOT/config/triples.txt
                preprocessors: $BOT_ROOT/config/preprocessors.conf
                postprocessors: $BOT_ROOT/config/postprocessors.conf

        """, ".")

        brain_config = BrainConfiguration()
        brain_config.load_config_section(yaml, ".")

        self.assertEqual(True, brain_config.supress_warnings)
        self.assertEqual(True, brain_config.allow_system_aiml)
        self.assertEqual(True, brain_config.allow_learn_aiml)
        self.assertEqual(True, brain_config.allow_learnf_aiml)

        self.assertIsNotNone(brain_config.aiml_files)
        self.assertIsNotNone(brain_config.set_files)
        self.assertIsNotNone(brain_config.map_files)
        self.assertEqual("./config/denormal.txt", brain_config.denormal)
        self.assertEqual("./config/normal.txt", brain_config.normal)
        self.assertEqual("./config/gender.txt", brain_config.gender)
        self.assertEqual("./config/person.txt", brain_config.person)
        self.assertEqual("./config/person2.txt", brain_config.person2)
        self.assertEqual("./config/predicates.txt", brain_config.predicates)
        self.assertEqual("./config/pronouns.txt", brain_config.pronouns)
        self.assertEqual("./config/properties.txt", brain_config.properties)
        self.assertEqual("./config/triples.txt", brain_config.triples)
        self.assertEqual("./config/preprocessors.conf",
                         brain_config.preprocessors)
        self.assertEqual("./config/postprocessors.conf",
                         brain_config.postprocessors)
        self.assertIsNotNone(brain_config.services)
コード例 #11
0
 def setUp(self):
     self.bot = Bot(Brain(BrainConfiguration()), config=BotConfiguration())
コード例 #12
0
 def test_bot_init_supplied_brain(self):
     test_brain = Brain(BrainConfiguration())
     bot = Bot(test_brain, BotConfiguration())
     self.assertIsNotNone(bot)
     self.assertIsNotNone(bot.brain)
コード例 #13
0
ファイル: base.py プロジェクト: datatalking/program-y
 def __init__(self):
     Bot.__init__(self, Brain(BrainConfiguration()), BotConfiguration())
     self._response = "Unknown"