コード例 #1
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        bot:
            spelling:
              classname: programy.spelling.norvig.NorvigSpellingChecker
              corpus: $BOT_ROOT/corpus.txt
              alphabet: abcdefghijklmnopqrstuvwxyz
              check_before: true
              check_and_retry: true
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        spelling_config = BotSpellingConfiguration()
        spelling_config.load_config_section(yaml, bot_config, ".")

        self.assertEquals("programy.spelling.norvig.NorvigSpellingChecker",
                          spelling_config.classname)
        self.assertEquals("./corpus.txt", spelling_config.corpus)
        self.assertEquals("abcdefghijklmnopqrstuvwxyz",
                          spelling_config.alphabet)
        self.assertTrue(spelling_config.check_before)
        self.assertTrue(spelling_config.check_and_retry)
コード例 #2
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        spelling_config = BotSpellingConfiguration()
        spelling_config.load_config_section(yaml, bot_config, ".")

        self.assertIsNone(spelling_config.classname)
        self.assertIsNone(spelling_config.corpus)
        self.assertIsNone(spelling_config.alphabet)
        self.assertFalse(spelling_config.check_before)
        self.assertFalse(spelling_config.check_and_retry)
コード例 #3
0
ファイル: bot.py プロジェクト: uganyasavur/program-y
class BotConfiguration(BaseContainerConfigurationData):

    DEFAULT_ROOT = "."
    DEFAULT_PROMPT = ">>> "
    DEFAULT_RESPONSE = ""
    DEFAULT_RESPONSE_SRAI = ""
    DEFAULT_EMPTY_STRING = ""
    DEFAULT_EXIT_RESPONSE = "Bye!"
    DEFAULT_EXIT_RESPONSE_SRAI = ""
    DEFAULT_INITIAL_QUESTION = "Hello"
    DEFAULT_INITIAL_QUESTION_SRAI = ""
    DEFAULT_OVERRIDE_PREDICATES = True
    DEFAULT_MAX_QUESTION_RECURSION = 100
    DEFAULT_MAX_QUESTION_TIMEOUT = -1
    DEFAULT_MAX_SEARCH_DEPTH = 100
    DEFAULT_MAX_SEARCH_TIMEOUT = -1
    DEFAULT_TAB_PARSE_OUTPUT = True

    def __init__(self):
        self._license_keys = None
        self._bot_root = BotConfiguration.DEFAULT_ROOT
        self._prompt = BotConfiguration.DEFAULT_PROMPT
        self._default_response = BotConfiguration.DEFAULT_RESPONSE
        self._default_response_srai = BotConfiguration.DEFAULT_RESPONSE_SRAI
        self._exit_response = BotConfiguration.DEFAULT_EXIT_RESPONSE
        self._exit_response_srai = BotConfiguration.DEFAULT_EXIT_RESPONSE_SRAI
        self._initial_question = BotConfiguration.DEFAULT_INITIAL_QUESTION
        self._initial_question_srai = BotConfiguration.DEFAULT_INITIAL_QUESTION_SRAI
        self._empty_string = BotConfiguration.DEFAULT_EMPTY_STRING
        self._override_properties = BotConfiguration.DEFAULT_OVERRIDE_PREDICATES
        self._max_question_recursion = BotConfiguration.DEFAULT_MAX_QUESTION_RECURSION
        self._max_question_timeout = BotConfiguration.DEFAULT_MAX_QUESTION_TIMEOUT
        self._max_search_depth = BotConfiguration.DEFAULT_MAX_SEARCH_DEPTH
        self._max_search_timeout = BotConfiguration.DEFAULT_MAX_SEARCH_TIMEOUT
        self._tab_parse_output = BotConfiguration.DEFAULT_TAB_PARSE_OUTPUT
        self._spelling = BotSpellingConfiguration()
        self._conversations = BotConversationsConfiguration()
        BaseContainerConfigurationData.__init__(self, "bot")

    def load_configuration(self, configuration_file, bot_root):
        bot = configuration_file.get_section(self.section_name)
        if bot is not None:
            self._license_keys = self._get_file_option(configuration_file,
                                                       "license_keys", bot,
                                                       bot_root)
            self._prompt = configuration_file.get_option(
                bot, "prompt", BotConfiguration.DEFAULT_PROMPT)
            self._default_response = configuration_file.get_option(
                bot, "default_response", BotConfiguration.DEFAULT_RESPONSE)
            self._default_response_srai = configuration_file.get_option(
                bot, "default_response_srai",
                BotConfiguration.DEFAULT_RESPONSE_SRAI)
            self._empty_string = configuration_file.get_option(
                bot, "empty_string", BotConfiguration.DEFAULT_EMPTY_STRING)
            self._exit_response = configuration_file.get_option(
                bot, "exit_response", BotConfiguration.DEFAULT_EXIT_RESPONSE)
            self._exit_response_srai = configuration_file.get_option(
                bot, "exit_response_srai",
                BotConfiguration.DEFAULT_EXIT_RESPONSE_SRAI)
            self._initial_question = configuration_file.get_option(
                bot, "initial_question",
                BotConfiguration.DEFAULT_INITIAL_QUESTION)
            self._initial_question_srai = configuration_file.get_option(
                bot, "initial_question_srai",
                BotConfiguration.DEFAULT_INITIAL_QUESTION_SRAI)
            self._override_properties = configuration_file.get_option(
                bot, "override_properties",
                BotConfiguration.DEFAULT_OVERRIDE_PREDICATES)
            self._max_question_recursion = configuration_file.get_int_option(
                bot, "max_question_recursion",
                BotConfiguration.DEFAULT_MAX_QUESTION_RECURSION)
            self._max_question_timeout = configuration_file.get_int_option(
                bot, "max_question_timeout",
                BotConfiguration.DEFAULT_MAX_QUESTION_TIMEOUT)
            self._max_search_depth = configuration_file.get_int_option(
                bot, "max_search_depth",
                BotConfiguration.DEFAULT_MAX_SEARCH_DEPTH)
            self._max_search_timeout = configuration_file.get_int_option(
                bot, "max_search_timeout",
                BotConfiguration.DEFAULT_MAX_SEARCH_TIMEOUT)
            self._tab_parse_output = configuration_file.get_bool_option(
                bot, "tab_parse_output",
                BotConfiguration.DEFAULT_TAB_PARSE_OUTPUT)

            self._spelling.load_config_section(configuration_file, bot,
                                               bot_root)
            self._conversations.load_config_section(configuration_file, bot,
                                                    bot_root)
        else:
            if logging.getLogger().isEnabledFor(logging.WARNING):
                logging.warning(
                    "Config section [%s] missing, using default values",
                    self.section_name)

    @property
    def bot_root(self):
        return self._bot_root

    @property
    def license_keys(self):
        return self._license_keys

    @property
    def prompt(self):
        return self._prompt

    @prompt.setter
    def prompt(self, text):
        self._prompt = text

    @property
    def default_response(self):
        return self._default_response

    @default_response.setter
    def default_response(self, text):
        self._default_response = text

    @property
    def default_response_srai(self):
        return self._default_response_srai

    @default_response_srai.setter
    def default_response_srai(self, text):
        self._default_response_srai = text

    @property
    def empty_string(self):
        return self._empty_string

    @empty_string.setter
    def empty_string(self, text):
        self._empty_string = text

    @property
    def exit_response(self):
        return self._exit_response

    @exit_response.setter
    def exit_response(self, text):
        self._exit_response = text

    @property
    def exit_response_srai(self):
        return self._exit_response_srai

    @exit_response_srai.setter
    def exit_response_srai(self, text):
        self._exit_response_srai = text

    @property
    def initial_question(self):
        return self._initial_question

    @initial_question.setter
    def initial_question(self, text):
        self._initial_question = text

    @property
    def initial_question_srai(self):
        return self._initial_question_srai

    @initial_question_srai.setter
    def initial_question_srai(self, text):
        self._initial_question_srai = text

    @property
    def override_properties(self):
        return self._override_properties

    @override_properties.setter
    def override_properties(self, override):
        self._override_properties = override

    @property
    def max_question_recursion(self):
        return self._max_question_recursion

    @property
    def max_question_timeout(self):
        return self._max_question_timeout

    @property
    def max_search_depth(self):
        return self._max_search_depth

    @property
    def max_search_timeout(self):
        return self._max_search_timeout

    @property
    def tab_parse_output(self):
        return self._tab_parse_output

    @property
    def spelling(self):
        return self._spelling

    @property
    def conversations(self):
        return self._conversations
コード例 #4
0
class BotConfiguration(BaseConfigurationData):

    DEFAULT_ROOT                    = "."
    DEFAULT_PROMPT                  = ">>> "
    DEFAULT_RESPONSE                = ""
    DEFAULT_EMPTY_STRING            = ""
    DEFAULT_EXIT_RESPONSE           = "Bye!"
    DEFAULT_INITIAL_QUESTION        = "Hello"
    DEFAULT_OVERRIDE_PREDICATES     = True

    def __init__(self):
        self._license_keys          = None
        self._bot_root              = BotConfiguration.DEFAULT_ROOT
        self._prompt                = BotConfiguration.DEFAULT_PROMPT
        self._default_response      = BotConfiguration.DEFAULT_RESPONSE
        self._exit_response         = BotConfiguration.DEFAULT_EXIT_RESPONSE
        self._initial_question      = BotConfiguration.DEFAULT_INITIAL_QUESTION
        self._empty_string          = BotConfiguration.DEFAULT_EMPTY_STRING
        self._override_predicates   = BotConfiguration.DEFAULT_OVERRIDE_PREDICATES
        self._max_recursion         = 10
        self._spelling              = BotSpellingConfiguration()
        BaseConfigurationData.__init__(self, "bot")

    def load_config_section(self, config_file, bot_root):
        bot = config_file.get_section(self.section_name)
        if bot is not None:
            self._license_keys = self._get_file_option(config_file, "license_keys", bot, bot_root)
            self._prompt = config_file.get_option(bot, "prompt", BotConfiguration.DEFAULT_PROMPT)
            self._default_response = config_file.get_option(bot, "default_response", BotConfiguration.DEFAULT_RESPONSE)
            self._empty_string = config_file.get_option(bot, "empty_string", BotConfiguration.DEFAULT_EMPTY_STRING)
            self._exit_response = config_file.get_option(bot, "exit_response", BotConfiguration.DEFAULT_EXIT_RESPONSE)
            self._initial_question = config_file.get_option(bot, "initial_question", BotConfiguration.DEFAULT_INITIAL_QUESTION)
            self._override_predicates = config_file.get_option(bot, "override_predicates", BotConfiguration.DEFAULT_OVERRIDE_PREDICATES)
            self._max_recursion = config_file.get_int_option(bot, "max_recursion", 10)
            self._spelling.load_config_section(config_file, bot, bot_root)


        else:
            logging.warning("Config section [%s] missing, using default values", self.section_name)
            self._license_keys          = None
            self._bot_root              = BotConfiguration.DEFAULT_ROOT
            self._prompt                = BotConfiguration.DEFAULT_PROMPT
            self._default_response      = BotConfiguration.DEFAULT_RESPONSE
            self._empty_string          = BotConfiguration.DEFAULT_EMPTY_STRING
            self._exit_response         = BotConfiguration.DEFAULT_EXIT_RESPONSE
            self._initial_question      = BotConfiguration.DEFAULT_INITIAL_QUESTION
            self._override_predicates   = BotConfiguration.DEFAULT_OVERRIDE_PREDICATES
            self._max_recursion         = 10

    @property
    def bot_root(self):
        return self._bot_root

    @property
    def license_keys(self):
        return self._license_keys

    @property
    def prompt(self):
        return self._prompt

    @prompt.setter
    def prompt(self, text):
        self._prompt = text

    @property
    def default_response(self):
        return self._default_response

    @default_response.setter
    def default_response(self, text):
        self._default_response = text

    @property
    def empty_string(self):
        return self._empty_string

    @empty_string.setter
    def empty_string(self, text):
        self._empty_string = text

    @property
    def exit_response(self):
        return self._exit_response

    @exit_response.setter
    def exit_response(self, text):
        self._exit_response = text

    @property
    def initial_question(self):
        return self._initial_question

    @initial_question.setter
    def initial_question(self, text):
        self._initial_question = text

    @property
    def override_predicates(self):
        return self._override_predicates

    @override_predicates.setter
    def override_predicates(self, override):
        self._override_predicates = override

    @property
    def max_recursion(self):
        return self._max_recursion

    @property
    def spelling(self):
        return self._spelling