Beispiel #1
0
 def load_from_file(self, filename, client_configuration, bot_root):
     configuration = ProgramyConfiguration(client_configuration)
     with open(filename, 'r+') as xml_data_file:
         tree = ET.parse(xml_data_file, parser=LineNumberingParser())
         self.xml_data = tree.getroot()
         configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #2
0
 def load_from_text(self, text, client_configuration, bot_root):
     self.yaml_data = yaml.load(text)
     if self.yaml_data is None:
         raise Exception("Yaml data is missing")
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #3
0
 def load_from_text(self, text, client_configuration, bot_root):
     self.yaml_data = yaml.load(text)
     if self.yaml_data is None:
         raise Exception("Yaml data is missing")
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #4
0
 def load_from_file(self, filename, client_configuration, bot_root):
     configuration = ProgramyConfiguration(client_configuration)
     with open(filename, 'r+', encoding="utf-8") as xml_data_file:
         tree = ET.parse(xml_data_file, parser=LineNumberingParser())
         self.xml_data = tree.getroot()
         configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #5
0
 def load_from_text(self,
                    text,
                    client_configuration,
                    bot_root,
                    subs: Substitutions = None):
     self.yaml_data = yaml.load(text, Loader=yaml.FullLoader)
     if self.yaml_data is None:
         raise Exception("Yaml data is missing")
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root, subs=subs)
     return configuration
Beispiel #6
0
    def load_from_file(self, filename, client_configuration, bot_root, subs: Substitutions = None):
        configuration = ProgramyConfiguration(client_configuration)
        try:
            with open(filename, 'r+', encoding="utf-8") as yml_data_file:
                self.yaml_data = yaml.load(yml_data_file)
                configuration.load_config_data(self, bot_root, subs=subs)

        except Exception as excep:
            YLogger.exception(self, "Failed to open yaml config file [%s]", excep, filename)

        return configuration
Beispiel #7
0
    def load_from_file(self, filename, client_configuration, bot_root):
        configuration = ProgramyConfiguration(client_configuration)
        try:
            with open(filename, 'r+', encoding="utf-8") as json_data_file:
                self.json_data = json.load(json_data_file)
                configuration.load_config_data(self, bot_root)

        except Exception as excep:
            YLogger.exception(self, "Failed to open json config file [%s]", excep, filename)

        return configuration
Beispiel #8
0
    def load_from_file(self, filename, client_configuration, bot_root, subs: Substitutions = None):
        configuration = ProgramyConfiguration(client_configuration)

        try:
            with open(filename, 'r+', encoding="utf-8") as xml_data_file:
                tree = ET.parse(xml_data_file, parser=LineNumberingParser())
                self.xml_data = tree.getroot()
                configuration.load_config_data(self, bot_root, subs)

        except Exception as excep:
            YLogger.exception(self, "Failed to open xml config file [%s]", excep, filename)

        return configuration
    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(max_search_depth=100, max_search_timeout=-1)
        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 = ProgramyConfiguration(self.get_client_config(),
                                            brain_config=self.get_brain_config(),
                                            bot_config=self.get_bot_config())

        self.test_bot = Bot(Brain(self.get_brain_config()), 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)
    def load_configuration(self, arguments):

        client_config = self.get_client_configuration()
        self._configuration = ProgramyConfiguration(client_config)

        yaml_file = YamlConfigurationFile()
        yaml_file.load_from_file(self._config_filename, client_config, ".")
Beispiel #11
0
    def load_configuration(self, arguments, subs: Substitutions = None):

        category_path = os.path.dirname(__file__)
        pattern_path = os.path.dirname(
            __file__) + os.sep + "parser/pattern/pattern_nodes.conf"
        template_path = os.path.dirname(
            __file__) + os.sep + "parser/template/template_nodes.conf"

        client_config = self.get_client_configuration()
        self._configuration = ProgramyConfiguration(client_config)

        yaml_file = YamlConfigurationFile()
        yaml_file.load_from_text(
            """
console:
  description: Program-Y Console Client
  bot:  bot
  prompt: ">>>"

  storage:
      entities:
          categories: file
          template_nodes: file
          pattern_nodes: file

      stores:

          file:
              type:   file
              config:
                categories_storage:
                  dirs: %s
                  subdirs: true
                  extension: .aiml

                pattern_nodes_storage:
                  file: %s
                template_nodes_storage:
                  file: %s

#####################################################################################################
#

bot:
    brain: brain

    initial_question: Hi, how can I help you today?
    default_response: Sorry, I don't have an answer for that!
    exit_response: So long, and thanks for the fish!

    override_properties: true

        """ % (category_path, pattern_path, template_path), client_config, ".")
Beispiel #12
0
    def load_configuration(self, arguments):
        if arguments.bot_root is None:
            if arguments.config_filename is not None:
                arguments.bot_root = os.path.dirname(arguments.config_filename)
            else:
                arguments.bot_root = "."
            print("No bot root argument set, defaulting to [%s]" % arguments.bot_root)

        if arguments.config_filename is not None:
            self.configuration = ConfigurationFactory.load_configuration_from_file(self.get_client_configuration(), arguments.config_filename, arguments.config_format, arguments.bot_root)
        else:
            print ("No configuration file specified, using defaults only !")
            self.configuration = ProgramyConfiguration(self.get_client_configuration())
Beispiel #13
0
    def test_bot_with_config(self):
        configuration = ProgramyConfiguration(ConsoleConfiguration())
        self.assertIsNotNone(configuration)
        self.assertIsNotNone(configuration.client_configuration.configurations[0])
        self.assertIsNotNone(configuration.client_configuration.configurations[0].configurations[0])

        configuration.client_configuration.configurations[0].prompt = ":"
        configuration.client_configuration.configurations[0].default_response = "No answer for that"
        configuration.client_configuration.configurations[0].exit_response = "See ya!"

        bot = Bot(config=configuration.client_configuration.configurations[0])
        self.assertIsNotNone(bot)

        self.assertEqual(bot.default_response, "No answer for that")
        self.assertEqual(bot.exit_response, "See ya!")
Beispiel #14
0
    def load_configuration(self, arguments, subs: Substitutions = None):
        if arguments.bot_root is None:
            if arguments.config_filename is not None:
                arguments.bot_root = os.path.dirname(arguments.config_filename)
            else:
                arguments.bot_root = "."
            outputLog(self, "No bot root argument set, defaulting to [%s]" % arguments.bot_root)

        if arguments.config_filename is not None:
            self._configuration = ConfigurationFactory.load_configuration_from_file(self.get_client_configuration(),
                                                                                    arguments.config_filename,
                                                                                    arguments.config_format,
                                                                                    arguments.bot_root,
                                                                                    subs)
        else:
            outputLog(self, "No configuration file specified, using defaults only !")
            self._configuration = ProgramyConfiguration(self.get_client_configuration())
    def test_bot_with_config(self):
        configuration = ProgramyConfiguration(ConsoleConfiguration())
        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!")
Beispiel #16
0
 def test_programy(self):
     program_config = ProgramyConfiguration(MockConfiguration())
     self.assertIsNotNone(program_config)
     self.assertIsNotNone(program_config.client_configuration)
Beispiel #17
0
 def load_configuration(self, arguments, subs: Substitutions = None):
     config = ConsoleConfiguration()
     self._configuration = ProgramyConfiguration(config)
Beispiel #18
0
    def load_configuration(self, arguments, subs: Substitutions = None):
        client_config = self.get_client_configuration()

        client_config.storage.storage_configurations[
            'file'] = FileStorageConfiguration()

        filepath = os.path.dirname(__file__) + os.sep

        client_config.storage.entity_store[
            StorageFactory.PATTERN_NODES] = 'file'
        if 'patterns' in self._files:
            client_config.storage.storage_configurations[
                'file']._pattern_nodes_storage = FileStoreConfiguration(
                    file=self._files['patterns'], fileformat="text")
        else:
            # Default if pattern node file not specified
            client_config.storage.storage_configurations[
                'file']._pattern_nodes_storage = FileStoreConfiguration(
                    file=filepath + 'basicbot/nodes/pattern_nodes.conf',
                    fileformat="text")

        client_config.storage.entity_store[
            StorageFactory.TEMPLATE_NODES] = 'file'
        if 'templates' in self._files:
            client_config.storage.storage_configurations[
                'file']._template_nodes_storage = FileStoreConfiguration(
                    file=self._files['templates'], fileformat="text")
        else:
            # Default if template node file not specified
            client_config.storage.storage_configurations[
                'file']._template_nodes_storage = FileStoreConfiguration(
                    file=filepath + 'basicbot/nodes/template_nodes.conf',
                    fileformat="text")

        if 'aiml' in self._files:
            client_config.storage.entity_store[
                StorageFactory.CATEGORIES] = 'file'
            client_config.storage.storage_configurations[
                'file']._categories_storage = FileStoreConfiguration(
                    dirs=self._files['aiml'],
                    fileformat="xml",
                    extension="aiml",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)

        client_config.storage.entity_store[StorageFactory.LEARNF] = 'file'
        if 'learnf' in self._files:
            client_config.storage.storage_configurations[
                'file']._learnf_storage = FileStoreConfiguration(
                    dirs=self._files['learnf'],
                    fileformat="xml",
                    extension="aiml",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._learnf_storage = FileStoreConfiguration(
                    dirs=filepath + 'basicbot/categories/learnf',
                    fileformat="xml",
                    extension="aiml",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)

        client_config.storage.entity_store[StorageFactory.PROPERTIES] = 'file'
        if 'properties' in self._files:
            client_config.storage.storage_configurations[
                'file']._properties_storage = FileStoreConfiguration(
                    file=self._files['properties'], fileformat="text")

        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._properties_storage = FileStoreConfiguration(
                    file=filepath + 'basicbot/properties/properties.txt',
                    fileformat="text")

        client_config.storage.entity_store[StorageFactory.DEFAULTS] = 'file'
        if 'defaults' in self._files:
            client_config.storage.storage_configurations[
                'file']._defaults_storage = FileStoreConfiguration(
                    file=self._files['defaults'], fileformat="text")

        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._defaults_storage = FileStoreConfiguration(
                    file=filepath + 'basicbot/properties/defaults.txt',
                    fileformat="text")

        client_config.storage.entity_store[StorageFactory.SETS] = 'file'
        if 'sets' in self._files:
            client_config.storage.storage_configurations[
                'file']._sets_storage = FileStoreConfiguration(
                    dirs=self._files['sets'],
                    fileformat="text",
                    extension="txt",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._sets_storage = FileStoreConfiguration(
                    dirs=[filepath + 'basicbot/sets'],
                    fileformat="text",
                    extension="txt",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)

        client_config.storage.entity_store[StorageFactory.MAPS] = 'file'
        if 'maps' in self._files:
            client_config.storage.storage_configurations[
                'file']._maps_storage = FileStoreConfiguration(
                    dirs=self._files['maps'],
                    fileformat="text",
                    extension="txt",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._maps_storage = FileStoreConfiguration(
                    dirs=['basicbot/maps'],
                    fileformat="text",
                    extension="txt",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)

        client_config.storage.entity_store[StorageFactory.RDF] = 'file'
        if 'rdfs' in self._files:
            client_config.storage.storage_configurations[
                'file']._rdfs_storage = FileStoreConfiguration(
                    dirs=self._files['rdfs'],
                    fileformat="text",
                    extension="txt",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._rdfs_storage = FileStoreConfiguration(
                    dirs=['basicbot/rdfs'],
                    fileformat="text",
                    extension="txt",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)

        client_config.storage.entity_store[StorageFactory.DENORMAL] = 'file'
        if 'denormals' in self._files:
            client_config.storage.storage_configurations[
                'file']._denormal_storage = FileStoreConfiguration(
                    file=self._files['denormals'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._denormal_storage = FileStoreConfiguration(
                    file='basibot/lookups/denormals.txt', fileformat="text")

        client_config.storage.entity_store[StorageFactory.NORMAL] = 'file'
        if 'normals' in self._files:
            client_config.storage.storage_configurations[
                'file']._normal_storage = FileStoreConfiguration(
                    file=self._files['normals'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._normal_storage = FileStoreConfiguration(
                    file='basicbot/lookups/normals.txt', fileformat="text")

        client_config.storage.entity_store[StorageFactory.GENDER] = 'file'
        if 'genders' in self._files:
            client_config.storage.storage_configurations[
                'file']._gender_storage = FileStoreConfiguration(
                    file=self._files['genders'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._gender_storage = FileStoreConfiguration(
                    file='basicbot/lookups/genders.txt', fileformat="text")

        client_config.storage.entity_store[StorageFactory.PERSON] = 'file'
        if 'persons' in self._files:
            client_config.storage.storage_configurations[
                'file']._person_storage = FileStoreConfiguration(
                    file=self._files['persons'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._person_storage = FileStoreConfiguration(
                    file='basicbot/lookups/persons.txt', fileformat="text")

        client_config.storage.entity_store[StorageFactory.PERSON2] = 'file'
        if 'person2s' in self._files:
            client_config.storage.storage_configurations[
                'file']._person2_storage = FileStoreConfiguration(
                    file=self._files['person2s'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._person2_storage = FileStoreConfiguration(
                    file='basicbot/lookups/person2s.txt', fileformat="text")

        client_config.storage.entity_store[
            StorageFactory.REGEX_TEMPLATES] = 'file'
        if 'regexes' in self._files:
            client_config.storage.storage_configurations[
                'file']._regex_storage = FileStoreConfiguration(
                    file=self._files['regexes'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._regex_storage = FileStoreConfiguration(
                    file='basicbot/regex/regex-templates.txt',
                    fileformat="text")

        if 'triggers' in self._files:
            client_config.storage.entity_store[
                StorageFactory.TRIGGERS] = 'file'
            client_config.storage.storage_configurations[
                'file']._triggers_storage = FileStoreConfiguration(
                    file=self._files['triggers'], fileformat="text")

        if 'usergroups' in self._files:
            client_config.storage.entity_store[
                StorageFactory.USERGROUPS] = 'file'
            client_config.storage.storage_configurations[
                'file']._usergroups_storage = FileStoreConfiguration(
                    file=self._files['usergroups'], fileformat="text")

        if 'spellings' in self._files:
            client_config.storage.entity_store[
                StorageFactory.SPELLING_CORPUS] = 'file'
            client_config.storage.storage_configurations[
                'file']._spelling_storage = FileStoreConfiguration(
                    file=self._files['spellings'], fileformat="text")

        client_config.storage.entity_store[
            StorageFactory.PREPROCESSORS] = 'file'
        if 'preprocessors' in self._files:
            client_config.storage.storage_configurations[
                'file']._preprocessors_storage = FileStoreConfiguration(
                    file=self._files['preprocessors'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._preprocessors_storage = FileStoreConfiguration(
                    file=filepath + 'basicbot/processing/preprocessors.conf',
                    fileformat="text")

        client_config.storage.entity_store[
            StorageFactory.POSTPROCESSORS] = 'file'
        if 'postprocessors' in self._files:
            client_config.storage.storage_configurations[
                'file']._postprocessors_storage = FileStoreConfiguration(
                    file=self._files['postprocessors'], fileformat="text")
        elif self._defaults is True:
            client_config.storage.storage_configurations[
                'file']._postprocessors_storage = FileStoreConfiguration(
                    file=filepath + 'basicbot/processing/postprocessors.conf',
                    fileformat="text")

        if 'postquestionprocessors' in self._files:
            client_config.storage.entity_store[
                StorageFactory.POSTQUESTIONPROCESSORS] = 'file'
            client_config.storage.storage_configurations[
                'file']._postquestionprocessors_storage = FileStoreConfiguration(
                    file=self._files['postquestionprocessors'],
                    fileformat="text")

        if 'licenses' in self._files:
            client_config.storage.entity_store[
                StorageFactory.LICENSE_KEYS] = 'file'
            client_config.storage.storage_configurations[
                'file']._license_storage = FileStoreConfiguration(
                    file=self._files['licenses'], fileformat="text")

        if 'errors' in self._files:
            client_config.storage.entity_store[StorageFactory.ERRORS] = 'file'
            client_config.storage.storage_configurations[
                'file']._errors_storage = FileStoreConfiguration(
                    file=self._files['errors'], fileformat="text")

        if 'duplicates' in self._files:
            client_config.storage.entity_store[StorageFactory.ERRORS] = 'file'
            client_config.storage.storage_configurations[
                'file']._duplicates_storage = FileStoreConfiguration(
                    file=self._files['duplicates'], fileformat="text")

        if 'binaries' in self._files:
            client_config.storage.entity_store[
                StorageFactory.BINARIES] = 'file'
            client_config.storage.storage_configurations[
                'file']._binaries_storage = FileStoreConfiguration(
                    file=self._files['binaries'], fileformat="text")

        if 'braintrees' in self._files:
            client_config.storage.entity_store[
                StorageFactory.BRAINTREE] = 'file'
            client_config.storage.storage_configurations[
                'file']._braintree_storage = FileStoreConfiguration(
                    file=self._files['braintrees'], fileformat="text")

        if 'conversations' in self._files:
            client_config.storage.entity_store[
                StorageFactory.CONVERSATIONS] = 'file'
            client_config.storage.storage_configurations[
                'file']._conversation_storage = FileStoreConfiguration(
                    dirs=self._files['conversations'],
                    fileformat="text",
                    extension="txt",
                    encoding="utf-8",
                    subdirs=True,
                    delete_on_start=False)

        if 'oobs' in self._files:
            client_config.storage.entity_store[StorageFactory.OOBS] = 'file'
            client_config.storage.storage_configurations[
                'file']._oobs_storage = FileStoreConfiguration(
                    file=self._files['oobs'], fileformat="text")

        self._configuration = ProgramyConfiguration(client_config)
Beispiel #19
0
 def load_from_text(self, text, client_configuration, bot_root, subs: Substitutions = None):
     self.json_data = json.loads(text)
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root, subs)
     return configuration
Beispiel #20
0
 def test_programy(self):
     program_config = ProgramyConfiguration(TestConfiguration())
     self.assertIsNotNone(program_config)
     self.assertIsNotNone(program_config.brain_configuration)
     self.assertIsNotNone(program_config.bot_configuration)
     self.assertIsNotNone(program_config.client_configuration)
Beispiel #21
0
 def load_from_file(self, filename, client_configuration, bot_root):
     configuration = ProgramyConfiguration(client_configuration)
     with open(filename, 'r+', encoding="utf-8") as json_data_file:
         self.json_data = json.load(json_data_file)
         configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #22
0
 def load_configuration(self, arguments):
     config = ConsoleConfiguration()
     self._configuration = ProgramyConfiguration(config)
Beispiel #23
0
 def load_from_text(self, text, client_configuration, bot_root):
     tree = ET.fromstring(text)
     self.xml_data = tree
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #24
0
 def load_from_text(self, text, client_configuration, bot_root):
     self.json_data = json.loads(text)
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #25
0
 def load_configuration(self, arguments):
     self.configuration = ProgramyConfiguration(ConsoleConfiguration())
Beispiel #26
0
 def load_from_file(self, filename, client_configuration, bot_root):
     configuration = ProgramyConfiguration(client_configuration)
     with open(filename, 'r+') as yml_data_file:
         self.yaml_data = yaml.load(yml_data_file)
         configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #27
0
 def load_from_file(self, filename, client_configuration, bot_root):
     configuration = ProgramyConfiguration(client_configuration)
     with open(filename, 'r+', encoding="utf-8") as json_data_file:
         self.json_data = json.load(json_data_file)
         configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #28
0
 def load_from_text(self, text, client_configuration, bot_root):
     self.json_data = json.loads(text)
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root)
     return configuration
Beispiel #29
0
 def load_from_text(self, text, client_configuration, bot_root):
     tree = ET.fromstring(text)
     self.xml_data = tree
     configuration = ProgramyConfiguration(client_configuration)
     configuration.load_config_data(self, bot_root)
     return configuration