Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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"
            )
Esempio n. 4
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"
                )