Пример #1
0
    def __init__(self, bot, configuration: BrainConfiguration):
        self._bot = bot
        self._configuration = configuration

        self._tokenizer = self.load_tokenizer()

        self._aiml_parser = self.load_aiml_parser()

        self._denormal_collection = DenormalCollection()
        self._normal_collection = NormalCollection()
        self._gender_collection = GenderCollection()
        self._person_collection = PersonCollection()
        self._person2_collection = PersonCollection()
        self._rdf_collection = RDFCollection()
        self._sets_collection = SetCollection()
        self._maps_collection = MapCollection()
        self._properties_collection = PropertiesCollection()
        self._variables_collection = PropertiesCollection()

        self._preprocessors = ProcessorLoader()
        self._postprocessors = ProcessorLoader()

        self._authentication = None
        self._authorisation = None

        self._default_oob = None
        self._oob = {}

        self._regex_templates = {}

        self._dynamics_collection = DynamicsCollection()

        self.load(self.configuration)

        self.dump_brain_tree()
Пример #2
0
    def __init__(self, configuration: BrainConfiguration):
        self._configuration = configuration
        self._aiml_parser = AIMLParser(self)

        self._denormal_collection = DenormalCollection()
        self._normal_collection = NormalCollection()
        self._gender_collection = GenderCollection()
        self._person_collection = PersonCollection()
        self._person2_collection = PersonCollection()
        self._rdf_collection = RDFCollection()
        self._sets_collection = SetCollection()
        self._maps_collection = MapCollection()
        self._properties_collection = PropertiesCollection()

        self._preprocessors = ProcessorLoader()
        self._postprocessors = ProcessorLoader()

        self._authentication = None
        self._authorisation = None

        self._default_oob = None
        self._oob = {}

        self._regex_templates = {}

        self._dynamics_collection = DynamicsCollection()

        self.load(self._configuration)
Пример #3
0
    def test_load_from_file(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._properties_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "properties.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PROPERTIES] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PROPERTIES] = storage_engine

        collection = PropertiesCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertTrue(collection.has_property("name"))
        self.assertFalse(collection.has_property("age"))

        self.assertEqual("KeiffBot 1.0", collection.property("name"))
        self.assertIsNone(collection.property("age"))
Пример #4
0
    def load_regex_templates(self, configuration):
        if configuration.files.regex_templates is not None:
            collection = PropertiesCollection()
            total = collection.load_from_filename(
                configuration.files.regex_templates)
            YLogger.info(self, "Loaded a total of %d regex templates", total)

            for pair in collection.pairs:
                name = pair[0]
                pattern = pair[1]
                try:
                    self._regex_templates[name] = re.compile(
                        pattern, re.IGNORECASE)
                except Exception:
                    YLogger.error(self, "Invalid regex template [%s]", pattern)
Пример #5
0
    def load_regex_templates(self, brain_configuration):
        if brain_configuration.files.regex_templates is not None:
            collection = PropertiesCollection()
            total = collection.load_from_filename(brain_configuration.files.regex_templates)
            if logging.getLogger().isEnabledFor(logging.INFO):
                logging.info("Loaded a total of %d regex templates", total)

            for pair in collection.pairs:
                name = pair[0]
                pattern = pair[1]
                try:
                    self._regex_templates[name] = re.compile(pattern, re.IGNORECASE)
                except Exception:
                    if logging.getLogger().isEnabledFor(logging.INFO):
                        logging.error("Invalid regex template [%s]", pattern)
Пример #6
0
    def test_load_variables(self):
        config = FileStorageConfiguration()
        config._defaults_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "defaults.txt",
                                                          format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileDefaultVariablesStore(engine)

        collection = PropertiesCollection()
        store.load(collection)

        self.assertTrue(collection.has_property("var1"))
        self.assertTrue("val1", collection.property("var1"))
        self.assertTrue(collection.has_property("var2"))
        self.assertTrue("val2", collection.property("val2"))
Пример #7
0
    def test_properties_operations(self):
        collection = PropertiesCollection()
        self.assertIsNotNone(collection)

        collection.add_property("name", "KeiffBot 1.0")
        collection.add_property("firstname", "Keiff")
        collection.add_property("middlename", "AIML")
        collection.add_property("lastname", "BoT")
        collection.add_property("fullname", "KeiffBot")

        self.assertTrue(collection.has_property("name"))
        self.assertFalse(collection.has_property("age"))

        self.assertEqual("KeiffBot 1.0", collection.property("name"))
        self.assertIsNone(collection.property("age"))
Пример #8
0
    def test_display_startup_messages_old_form(self):
        arguments = MockArgumentParser()
        client = MockConsoleBotClient(arguments)
        self.assertIsNotNone(client)
        client._arguments.context = False
        context = client.create_client_context("console")

        properties = PropertiesCollection()
        properties.add_property("name", "Old_Bot"),
        properties.add_property("version", "1.0"),
        properties.add_property("birthdate", "2000/1/1")
        context.brain._properties_collection = properties

        client.display_startup_messages(context)
        self.assertEqual("Old_Bot, v1.0, initiated 2000/1/1 Hello",
                         client.response)
Пример #9
0
    def test_load_properties(self):
        config = FileStorageConfiguration()
        config._properties_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "properties.txt", format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePropertyStore(engine)

        collection = PropertiesCollection()
        store.load(collection)

        self.assertTrue(collection.has_key("name"))
        self.assertTrue("Y-Bot", collection.value("name"))
        self.assertTrue(collection.has_key("firstname"))
        self.assertTrue("Y", collection.value("firstname"))
        self.assertTrue(collection.has_key("middlename"))
        self.assertTrue("AIML", collection.value("middlename"))
Пример #10
0
    def __init__(self, bot, configuration: BrainConfiguration):

        assert bot is not None
        assert configuration is not None

        self._questions = 0

        self._bot = bot
        self._configuration = configuration

        self._pattern_factory = None
        self._template_factory = None

        self._binaries = BinariesManager(configuration.binaries)
        self._braintree = BraintreeManager(configuration.braintree)

        self._tokenizer = Tokenizer.load_tokenizer(configuration.tokenizer)

        self._denormal_collection = DenormalCollection()
        self._normal_collection = NormalCollection()
        self._gender_collection = GenderCollection()
        self._person_collection = PersonCollection()
        self._person2_collection = Person2Collection()

        self._rdf_collection = RDFCollection()
        self._sets_collection = SetCollection()
        self._maps_collection = MapCollection()

        self._properties_collection = PropertiesCollection()
        self._default_variables_collection = DefaultVariablesCollection()
        self._regex_templates = RegexTemplatesCollection()
        self._dynamics_collection = DynamicsCollection()

        self._preprocessors = PreProcessorCollection()
        self._postprocessors = PostProcessorCollection()
        self._postquestionprocessors = PostQuestionProcessorCollection()

        self._services = ServiceHandler()

        self._oobhandler = OOBHandler()

        self._security = SecurityManager(configuration.security)

        self._aiml_parser = self.load_aiml_parser()

        self.load(self.configuration)
Пример #11
0
    def test_display_startup_messages_new_form(self):
        arguments = MockArgumentParser()
        client = MockConsoleBotClient(arguments)
        self.assertIsNotNone(client)
        client._arguments.context = False
        context = client.create_client_context("console")

        properties = PropertiesCollection()
        properties.add_property("name", "New_Bot"),
        properties.add_property("app_version", "2.1"),
        properties.add_property("grammar_version", "2.2"),
        properties.add_property("birthdate", "2010/1/1")
        context.brain._properties_collection = properties

        client.display_startup_messages(context)
        self.assertEqual(
            "New_Bot, App: v2.1 Grammar v2.2, initiated 2010/1/1 Hello",
            client.response)
Пример #12
0
    def __init__(self, configuration: BrainConfiguration):
        self._configuration = configuration
        self._aiml_parser = AIMLParser()

        self._denormal_collection = DenormalCollection()
        self._normal_collection = NormalCollection()
        self._gender_collection = GenderCollection()
        self._person_collection = PersonCollection()
        self._person2_collection = PersonCollection()
        self._predicates_collection = PredicatesCollection()
        self._pronouns_collection = PronounsCollection()
        self._triples_collection = TriplesCollection()
        self._sets_collection = SetCollection()
        self._maps_collection = MapCollection()
        self._properties_collection = PropertiesCollection()

        self._preprocessors = ProcessorLoader()
        self._postprocessors = ProcessorLoader()

        self.load(self._configuration)
Пример #13
0
    def test_properties_from_text(self):

        properties = PropertiesCollection()
        self.assertIsNotNone(properties)

        properties.load_from_text("""
            url:http://www.keithsterling.com/aiml
            name:KeiffBot 1.0
            firstname:Keiff
            middlename:AIML
            lastname:BoT
            fullname:KeiffBot
            email:[email protected]
            gender:male
            botmaster:Keith Sterling
            organization:keithsterling.com
            version:0.0.1
            birthplace:Edinburgh, Scotland
            job:mobile virtual assistant
            species:robot
            birthday:September 9th
            birthdate:September 9th, 2016
            sign:Virgo
            logo:<img src="http://www.keithsterling.com/aiml/logo.png" width="128"/>
            religion:Atheist
            default-get:unknown
            default-property:unknown
            default-map:unknown
            learn-filename:keiffbot-learn.aiml
        """)

        self.assertEqual(properties.property('url'),
                         "http://www.keithsterling.com/aiml")
        self.assertEqual(properties.property('job'),
                         "mobile virtual assistant")
        self.assertEqual(properties.property('learn-filename'),
                         "keiffbot-learn.aiml")
Пример #14
0
 def test_initialise_collection(self):
     collection = PropertiesCollection()
     self.assertIsNotNone(collection)
Пример #15
0
    def __init__(self, bot, configuration: BrainConfiguration):

        assert (bot is not None)
        assert (configuration is not None)

        self._bot = bot
        self._configuration = configuration

        self._binaries = BinariesManager(configuration.binaries)
        self._braintree = BraintreeManager(configuration.braintree)
        self._tokenizer = Tokenizer.load_tokenizer(configuration)

        if configuration.debugfiles.save_errors_collection is True:
            errors_dict = {}
        else:
            errors_dict = None

        self._denormal_collection = DenormalCollection(errors_dict)
        self._normal_collection = NormalCollection(errors_dict)
        self._gender_collection = GenderCollection(errors_dict)
        self._person_collection = PersonCollection(errors_dict)
        self._person2_collection = Person2Collection(errors_dict)
        self._rdf_collection = RDFCollection(errors_dict)
        self._sets_collection = SetCollection(errors_dict)
        self._maps_collection = MapCollection(errors_dict)

        self._properties_collection = PropertiesCollection(errors_dict)
        self._default_variables_collection = DefaultVariablesCollection(
            errors_dict)
        self._botnames_collection = BotNamesCollection(errors_dict)

        self._preprocessors = PreProcessorCollection(errors_dict)
        self._postprocessors = PostProcessorCollection(errors_dict)

        self._pattern_factory = None
        self._template_factory = None

        self._security = SecurityManager(configuration.security)

        self._oobhandler = OOBHandler(configuration.oob)

        self._regex_templates = RegexTemplatesCollection(errors_dict)

        self._dynamics_collection = DynamicsCollection()

        self._aiml_parser = self.load_aiml_parser()

        self._nlu_collection = NluCollection(bot.client, configuration.nlu,
                                             errors_dict)
        self._nlu = NluRequest.load_nlu(configuration.nlu)
        self._nlu_utterance = None

        self.load(self.configuration)

        if configuration.debugfiles.save_errors_collection is True:
            storage_factory = self.bot.client.storage_factory
            if storage_factory.entity_storage_engine_available(
                    StorageFactory.ERRORS_COLLECTION) is True:
                errors_collection_engine = storage_factory.entity_storage_engine(
                    StorageFactory.ERRORS_COLLECTION)
                errors_collection_store = errors_collection_engine.errors_collection_store(
                )
                errors_collection_store.save_errors_collection(errors_dict)