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)
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()
def assert_upload_from_text(self, store): store.empty() store.upload_from_text( None, """ " with you "," with me2 " " with me "," with you2 " " to you "," to me2 " " to me "," to you2 " " of you "," of me2 " " of me "," of you2 " " for you "," for me2 " " for me "," for you2 " " give you "," give me2 " " give me "," give you2 " """) collection = PersonCollection() store.load(collection) self.assertEqual(collection.person(" WITH YOU "), [ re.compile('(^WITH YOU | WITH YOU | WITH YOU$)', re.IGNORECASE), ' WITH ME2 ' ]) self.assertEqual(collection.personalise_string("This is with you "), "This is with me2")
def test_load(self): storage_factory = StorageFactory() file_store_config = FileStorageConfiguration() file_store_config._person_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "person.txt", format="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PERSON] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PERSON] = storage_engine collection = PersonCollection() self.assertIsNotNone(collection) collection.load(storage_factory) self.assertEqual(collection.personalise_string(" with me "), "with you2") self.assertEqual( collection.personalise_string("Hello are you with me"), "Hello am i2 with you2")
def test_load(self): storage_factory = StorageFactory() file_store_config = FileStorageConfiguration() file_store_config._person_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "person.txt", fileformat="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PERSON] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PERSON] = storage_engine collection = PersonCollection() self.assertIsNotNone(collection) self.assertTrue(collection.load(storage_factory)) self.assertEqual(collection.personalise_string(" with me "), "with you2") self.assertEqual( collection.personalise_string("Hello are you with me"), "Hello am i2 with you2") self.assertEqual([ re.compile('(^WITH YOU | WITH YOU | WITH YOU$)', re.IGNORECASE), ' WITH ME2 ' ], collection.person(" WITH YOU ")) self.assertEqual(None, collection.person(" WITH XXX "))
def test_load_jp(self): storage_factory = StorageFactory() tokenizer = TokenizerJP() file_store_config = FileStorageConfiguration() file_store_config._person_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "person_jp.txt", format="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PERSON] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PERSON] = storage_engine collection = PersonCollection() self.assertIsNotNone(collection) collection.load(storage_factory) self.assertEqual(collection.personalise_string(tokenizer, "私が正しい"), "貴方が正しい") self.assertEqual(collection.personalise_string(tokenizer, "あなたは変"), "わたしは変")
def test_collection_duplicate(self): collection = PersonCollection() self.assertIsNotNone(collection) collection.add_to_lookup("with you", "with me") collection.add_to_lookup("with you", 'with him') self.assertEqual(collection.person("WITH YOU"), 'with me')
def test_collection_duplicate_jp(self): collection = PersonCollection() self.assertIsNotNone(collection) collection.add_to_lookup("貴方", "私") collection.add_to_lookup("貴方", '彼氏') self.assertEqual(collection.person("貴方"), '私')
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)
def assert_upload_from_file(self, store): person_collection = PersonCollection() store.upload_from_file(os.path.dirname( __file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person.txt") store.load(person_collection) self.assertEqual(person_collection.person(" WITH YOU "), [re.compile('(^WITH YOU | WITH YOU | WITH YOU$)', re.IGNORECASE), ' WITH ME2 ']) self.assertEqual(person_collection.personalise_string("Is he with you"), "Is he with me2")
def test_load_persons(self): person_text = """ " with you "," with me2 " " with me "," with you2 " """ collection = PersonCollection() self.assertIsNotNone(collection) collection.load_from_text(person_text) self.assertEqual(collection.personalise_string(" with me "), "with you2")
def test_replace_person(self): person_text = """ " with me "," with you2 " " are you "," am I2 " """ collection = PersonCollection() self.assertIsNotNone(collection) collection.load_from_text(person_text) self.assertEqual(collection.personalise_string("Hello are you with me"), "Hello am I2 with you2")
def test_load_from_file(self): config = FileStorageConfiguration() config._person_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person.txt", format="text", encoding="utf-8", delete_on_start=False) engine = FileStorageEngine(config) engine.initialise() store = FilePersonStore(engine) person_collection = PersonCollection() store.load(person_collection) self.assertEqual(person_collection.person(" WITH YOU "), [re.compile('(^WITH YOU | WITH YOU | WITH YOU$)', re.IGNORECASE), ' WITH ME2 ']) self.assertEqual(person_collection.personalise_string("Is he with you"), "Is he with me2")
def test_collection_invalid(self): collection = PersonCollection() self.assertIsNotNone(collection) collection.add_to_lookup("with you", "with me") self.assertFalse(collection.has_keyVal("WITH HIM")) self.assertIsNone(collection.value("WITH HIM")) self.assertIsNone(collection.person("WITH HIM")) self.assertEqual( collection.personalise_string(None, "This is with him"), "This is with him")
def test_load_from_file(self): config = FileStorageConfiguration() config._person2_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person2.txt", fileformat="text", encoding="utf-8", delete_on_start=False) engine = FileStorageEngine(config) engine.initialise() store = FilePerson2Store(engine) person2_collection = PersonCollection() store.load(person2_collection) self.assertEqual(person2_collection.person(" I WAS "), [re.compile('(^I WAS | I WAS | I WAS$)', re.IGNORECASE), ' HE OR SHE WAS ']) self.assertEqual(person2_collection.personalise_string("I was there"), "he or she was there")
def test_collection_invalid_JP(self): collection = PersonCollection() self.assertIsNotNone(collection) collection.add_to_lookup("貴方", "私") self.assertFalse(collection.has_keyVal("彼")) self.assertIsNone(collection.value("彼")) tokenizer = TokenizerJP() self.assertIsNone(collection.person("彼")) self.assertEqual(collection.personalise_string(tokenizer, "彼が来た"), "彼が来た")
def test_person(self): person_text = """ " with you "," with me2 " " with me "," with you2 " """ collection = PersonCollection() self.assertIsNotNone(collection) collection.load_from_text(person_text) pattern = collection.person(" with you ") self.assertIsNotNone(pattern) self.assertEquals(" with me2 ", pattern[1])
def assert_upload_from_file(self, store): person2_collection = PersonCollection() store.upload_from_file( os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person2.txt") store.load(person2_collection) self.assertEqual(person2_collection.person(" I WAS "), [ re.compile('(^I WAS | I WAS | I WAS$)', re.IGNORECASE), ' HE OR SHE WAS ' ]) self.assertEqual(person2_collection.personalise_string("I was there"), "he or she was there")
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)
def assert_upload_csv_file(self, store): store.empty() store.upload_from_file(os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "csv" + os.sep + "person.csv", fileformat=Store.CSV_FORMAT) collection = PersonCollection() store.load(collection) self.assertEqual(collection.person(" WITH YOU "), [ re.compile('(^WITH YOU | WITH YOU | WITH YOU$)', re.IGNORECASE), ' WITH ME2 ' ]) self.assertEqual(collection.personalise_string("This is with you "), "This is with me2")
def test_collection_operations_jp(self): person_text = """ "貴方","私" "私","貴方" "あなた","わたし" "わたし","あなた" """ collection = PersonCollection() self.assertIsNotNone(collection) collection.load_from_text(person_text) tokenizer = TokenizerJP() self.assertEqual(collection.personalise_string(tokenizer, "私が正しい"), "貴方が正しい") self.assertEqual(collection.personalise_string(tokenizer, "あなたは変"), "わたしは変") pattern = collection.person("貴方") self.assertIsNotNone(pattern) self.assertEqual("私", pattern)
def test_collection_operations(self): person_text = """ " with you "," with me2 " " with me "," with you2 " " are you "," am I2 " " with me "," with you2 " """ collection = PersonCollection() self.assertIsNotNone(collection) collection.load_from_text(person_text) self.assertEqual(collection.personalise_string(" with me "), "with you2") self.assertEqual( collection.personalise_string("Hello are you with me"), "Hello am i2 with you2") pattern = collection.person(" with you ") self.assertIsNotNone(pattern) self.assertEqual(" WITH ME2 ", pattern[1])
def test_load_with_exception(self): storage_factory = StorageFactory() file_store_config = FileStorageConfiguration() file_store_config._person_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "person.txt", fileformat="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PERSON] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PERSON] = storage_engine collection = PersonCollection() self.assertIsNotNone(collection) self.assertFalse(collection.load(storage_factory))
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)
def test_initialise_collection(self): collection = PersonCollection() self.assertIsNotNone(collection)