Example #1
0
    def test_with_files_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                aiml:
                    files: $BOT_ROOT/aiml
                    extension: .aiml
                    directories: true
                    errors: /tmp/y-bot_errors.txt
                    duplicates: /tmp/y-bot_duplicates.txt
        """, ConsoleConfiguration(), ".")

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

        aiml_config = BrainAIMLFileConfiguration()
        aiml_config.load_config_section(yaml, files_config, ".")

        self.assertEqual("./aiml", aiml_config.files)
        self.assertEqual(".aiml", aiml_config.extension)
        self.assertTrue(aiml_config.directories)
        self.assertEqual("/tmp/y-bot_errors.txt", aiml_config.errors)
        self.assertEqual("/tmp/y-bot_duplicates.txt", aiml_config.duplicates)
Example #2
0
    def test_with_file_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                aiml:
                    file: $BOT_ROOT/aiml/test.aiml
                    errors: /tmp/y-bot-errors.txt
                    duplicates: /tmp/y-bot-duplicates.txt
                    conversation: /tmp/y-bot-conversation.txt
        """, ConsoleConfiguration(), ".")

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

        aiml_config = BrainAIMLFileConfiguration()
        aiml_config.load_config_section(yaml, files_config, ".")

        self.assertEqual("./aiml/test.aiml", aiml_config.file)
        self.assertEqual("aiml", aiml_config.extension)
        self.assertFalse(aiml_config.directories)
        self.assertEqual("/tmp/y-bot-errors.txt", aiml_config.errors.filename)
        self.assertEqual("/tmp/y-bot-duplicates.txt",
                         aiml_config.duplicates.filename)
        self.assertEqual("/tmp/y-bot-conversation.txt",
                         aiml_config.conversation.filename)
Example #3
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
Example #4
0
    def test_with_files_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                aiml:
                    files: $BOT_ROOT/aiml
                    extension: .aiml
                    directories: true
                    errors:
                      file: /tmp/y-bot-errors.txt
                      format: txt
                      encoding: utf-8
                      delete_on_start: true
                    duplicates:
                      file: /tmp/y-bot-duplicates.txt
                      format: txt
                      encoding: utf-8
                      delete_on_start: true
                    conversation:
                      file: /tmp/y-bot-conversation.csv
                      format: csv
                      delete_on_start: true
        """, ConsoleConfiguration(), ".")

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

        aiml_config = BrainAIMLFileConfiguration()
        aiml_config.load_config_section(yaml, files_config, ".")

        self.assertEqual(["./aiml"], aiml_config.files)
        self.assertEqual(".aiml", aiml_config.extension)
        self.assertTrue(aiml_config.directories)
        self.assertEqual("/tmp/y-bot-errors.txt", aiml_config.errors.filename)
        self.assertEqual("/tmp/y-bot-duplicates.txt",
                         aiml_config.duplicates.filename)
        self.assertEqual("/tmp/y-bot-conversation.csv",
                         aiml_config.conversation.filename)
    def test_with_file_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                aiml:
                    file: $BOT_ROOT/aiml/test.aiml
                    errors: $BOT_ROOT/output/y-bot_errors.txt
                    duplicates: $BOT_ROOT/output/y-bot_duplicates.txt
        """, ConsoleConfiguration(), ".")

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

        aiml_config = BrainAIMLFileConfiguration()
        aiml_config.load_config_section(yaml, files_config, ".")

        self.assertEqual("./aiml/test.aiml", aiml_config.file)
Example #6
0
class BrainFilesConfiguration(BaseConfigurationData):
    def __init__(self):
        BaseConfigurationData.__init__(self, "files")
        self._aiml_files = BrainAIMLFileConfiguration()
        self._set_files = BrainFileConfiguration("sets")
        self._map_files = BrainFileConfiguration("maps")

        self._denormal = None
        self._normal = None
        self._gender = None
        self._person = None
        self._person2 = None
        self._predicates = None
        self._pronouns = None
        self._properties = None
        self._triples = None
        self._preprocessors = None
        self._postprocessors = None

    @property
    def aiml_files(self):
        return self._aiml_files

    @property
    def set_files(self):
        return self._set_files

    @property
    def map_files(self):
        return self._map_files

    @property
    def denormal(self):
        return self._denormal

    @property
    def normal(self):
        return self._normal

    @property
    def gender(self):
        return self._gender

    @property
    def person(self):
        return self._person

    @property
    def person2(self):
        return self._person2

    @property
    def predicates(self):
        return self._predicates

    @property
    def pronouns(self):
        return self._pronouns

    @property
    def properties(self):
        return self._properties

    @property
    def triples(self):
        return self._triples

    @property
    def preprocessors(self):
        return self._preprocessors

    @property
    def postprocessors(self):
        return self._postprocessors

    def load_config_section(self, config_file, brain_config, bot_root):
        files_config = config_file.get_section("files", brain_config)
        if files_config is not None:
            self._aiml_files.load_config_section(config_file, files_config,
                                                 bot_root)
            self._set_files.load_config_section(config_file, files_config,
                                                bot_root)
            self._map_files.load_config_section(config_file, files_config,
                                                bot_root)

            self._denormal = self._get_file_option(config_file, "denormal",
                                                   files_config, bot_root)
            self._normal = self._get_file_option(config_file, "normal",
                                                 files_config, bot_root)
            self._gender = self._get_file_option(config_file, "gender",
                                                 files_config, bot_root)
            self._person = self._get_file_option(config_file, "person",
                                                 files_config, bot_root)
            self._person2 = self._get_file_option(config_file, "person2",
                                                  files_config, bot_root)
            self._predicates = self._get_file_option(config_file, "predicates",
                                                     files_config, bot_root)
            self._pronouns = self._get_file_option(config_file, "pronouns",
                                                   files_config, bot_root)
            self._properties = self._get_file_option(config_file, "properties",
                                                     files_config, bot_root)
            self._triples = self._get_file_option(config_file, "triples",
                                                  files_config, bot_root)
            self._preprocessors = self._get_file_option(
                config_file, "preprocessors", files_config, bot_root)
            self._postprocessors = self._get_file_option(
                config_file, "postprocessors", files_config, bot_root)
        else:
            logging.error(
                "Config section [files] missing from Brain, default values not appropriate"
            )
Example #7
0
class BrainFilesConfiguration(BaseSectionConfigurationData):
    def __init__(self):
        BaseSectionConfigurationData.__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
        self._regex_templates = None

    @property
    def aiml_files(self):
        return self._aiml_files

    @property
    def set_files(self):
        return self._set_files

    @property
    def map_files(self):
        return self._map_files

    @property
    def denormal(self):
        return self._denormal

    @property
    def normal(self):
        return self._normal

    @property
    def gender(self):
        return self._gender

    @property
    def person(self):
        return self._person

    @property
    def person2(self):
        return self._person2

    @property
    def properties(self):
        return self._properties

    @property
    def rdf_files(self):
        return self._rdf_files

    @property
    def triples(self):
        return self._triples

    @property
    def preprocessors(self):
        return self._preprocessors

    @property
    def postprocessors(self):
        return self._postprocessors

    @property
    def regex_templates(self):
        return self._regex_templates

    def load_config_section(self, configuration_file, configuration, bot_root):
        files_config = configuration_file.get_section("files", configuration)
        if files_config is not None:
            self._aiml_files.load_config_section(configuration_file,
                                                 files_config, bot_root)
            self._set_files.load_config_section(configuration_file,
                                                files_config, bot_root)
            self._map_files.load_config_section(configuration_file,
                                                files_config, bot_root)
            self._rdf_files.load_config_section(configuration_file,
                                                files_config, bot_root)

            self._denormal = self._get_file_option(configuration_file,
                                                   "denormal", files_config,
                                                   bot_root)
            self._normal = self._get_file_option(configuration_file, "normal",
                                                 files_config, bot_root)
            self._gender = self._get_file_option(configuration_file, "gender",
                                                 files_config, bot_root)
            self._person = self._get_file_option(configuration_file, "person",
                                                 files_config, bot_root)
            self._person2 = self._get_file_option(configuration_file,
                                                  "person2", files_config,
                                                  bot_root)
            self._properties = self._get_file_option(configuration_file,
                                                     "properties",
                                                     files_config, bot_root)
            self._triples = self._get_file_option(configuration_file,
                                                  "triples", files_config,
                                                  bot_root)
            self._preprocessors = self._get_file_option(
                configuration_file, "preprocessors", files_config, bot_root)
            self._postprocessors = self._get_file_option(
                configuration_file, "postprocessors", files_config, bot_root)
            self._regex_templates = self._get_file_option(
                configuration_file, "regex_templates", files_config, bot_root)
        else:
            if logging.getLogger().isEnabledFor(logging.ERROR):
                logging.error(
                    "Config section [files] missing from Brain, default values not appropriate"
                )