def setUp(self):
     LearnfAIMLTests.test_client = LearnfTestClient()
     LearnfAIMLTests.test_client.bot.brain._configuration._aiml_files = BrainFileConfiguration(
         files=os.sep + "tmp")
     self.learnf_path = LearnfAIMLTests.test_client.bot.brain.configuration.defaults._learn_filename
     if os.path.exists(self.learnf_path):
         os.remove(self.learnf_path)
Exemple #2
0
    def __init__(self):
        BaseConfigurationData.__init__(self, "files")
        self._aiml_files        = BrainAIMLFileConfiguration()
        self._set_files         = BrainFileConfiguration("sets")
        self._map_files         = BrainFileConfiguration("maps")
        self._rdf_files         = BrainFileConfiguration("rdf")

        self._denormal          = None
        self._normal            = None
        self._gender            = None
        self._person            = None
        self._person2           = None
        self._properties        = None
        self._triples           = None
        self._preprocessors     = None
        self._postprocessors    = None
Exemple #3
0
    def test_with_file_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                sets:
                    file: $BOT_ROOT/sets/test.txt
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        files_config = yaml.get_section("files", brain_config)
        self.assertIsNotNone(files_config)

        sets_config = BrainFileConfiguration("sets")
        sets_config.load_config_section(yaml, files_config, ".")

        self.assertEqual("./sets/test.txt", sets_config.file)
Exemple #4
0
    def test_learnf_simple(self):
        template = ET.fromstring("""
			<template>
				<learnf>
				    <category>
				        <pattern>HELLO <eval>WORLD</eval> THERE</pattern>
				        <template>HIYA</template>
				    </category>
				</learnf>
			</template>
			""")

        self.test_bot.brain._configuration._aiml_files = BrainFileConfiguration(
            os.sep + "tmp", ".aiml", False)

        ast = self.parser.parse_template_expression(template)
        self.assertIsNotNone(ast)
        self.assertIsInstance(ast, TemplateNode)
        self.assertIsNotNone(ast.children)
        self.assertEqual(len(ast.children), 1)

        learn_node = ast.children[0]
        self.assertIsNotNone(learn_node)
        self.assertIsInstance(learn_node, TemplateLearnfNode)
        self.assertEqual(1, len(learn_node.children))
        self.assertIsInstance(learn_node.children[0], LearnCategory)
        self.assertIsNotNone(learn_node.children[0].pattern)
        self.assertIsInstance(learn_node.children[0].pattern, ET.Element)
        self.assertIsNotNone(learn_node.children[0].topic)
        self.assertIsInstance(learn_node.children[0].topic, ET.Element)
        self.assertIsNotNone(learn_node.children[0].that)
        self.assertIsInstance(learn_node.children[0].that, ET.Element)
        self.assertIsNotNone(learn_node.children[0].template)
        self.assertIsInstance(learn_node.children[0].template, TemplateNode)

        resolved = learn_node.resolve(self.test_bot, self.test_clientid)
        self.assertEqual(resolved, "")

        response = self.test_bot.ask_question(self.test_clientid,
                                              "HELLO WORLD THERE")
        self.assertEqual("HIYA", response)
Exemple #5
0
    def test_with_files_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                sets:
                    files: $BOT_ROOT/sets
                    extension: .txt
                    directories: false
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        files_config = yaml.get_section("files", brain_config)
        self.assertIsNotNone(files_config)

        sets_config = BrainFileConfiguration("sets")
        sets_config.load_config_section(yaml, files_config, ".")

        self.assertEqual(["./sets"], sets_config.files)
        self.assertEqual(".txt", sets_config.extension)
        self.assertFalse(sets_config.directories)