def test_collection_operations(self): person2_text = """ "I was","he or she was" "he was","I was" "she was","I was" "I am","he or she is" "I","he or she" "me","him or her" "my","his or her" "myself","him or herself" "mine","his or hers" """ collection = Person2Collection() self.assertIsNotNone(collection) collection.load_from_text(person2_text) self.assertEqual(collection.personalise_string(None, "I was"), "he or she was") self.assertEqual( collection.personalise_string(None, "hello he was over there"), "hello I was over there") pattern = collection.person("I AM") self.assertIsNotNone(pattern) self.assertEqual("he or she is", pattern)
def test_load(self): storage_factory = StorageFactory() file_store_config = FileStorageConfiguration() file_store_config._person2_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "person2.txt", format="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PERSON2] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PERSON2] = storage_engine collection = Person2Collection() self.assertIsNotNone(collection) collection.load(storage_factory) self.assertEqual(collection.personalise_string(None, "I was"), "he or she was") self.assertEqual( collection.personalise_string(None, "hello he was over there"), "hello I was over there")
def test_reload_jp(self): storage_factory = StorageFactory() tokenizer = TokenizerJP() file_store_config = FileStorageConfiguration() file_store_config._person2_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "person2_jp.txt", format="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PERSON2] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PERSON2] = storage_engine collection = Person2Collection() self.assertIsNotNone(collection) collection.load(storage_factory) self.assertEqual(collection.personalise_string(tokenizer, "私"), "彼か彼女") self.assertEqual(collection.personalise_string(tokenizer, "彼か彼女が来た"), "私か私が来た") collection.reload(storage_factory) self.assertEqual(collection.personalise_string(tokenizer, "私"), "彼か彼女") self.assertEqual(collection.personalise_string(tokenizer, "彼か彼女が来た"), "私か私が来た")
def test_load(self): storage_factory = StorageFactory() file_store_config = FileStorageConfiguration() file_store_config._person2_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "person2.txt", fileformat="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PERSON2] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PERSON2] = storage_engine collection = Person2Collection() self.assertIsNotNone(collection) self.assertTrue(collection.load(storage_factory)) self.assertEqual(collection.personalise_string("I was"), "he or she was") self.assertEqual( collection.personalise_string("hello he was over there"), "hello i was over there") self.assertEquals([ re.compile('(^I WAS | I WAS | I WAS$)', re.IGNORECASE), ' HE OR SHE WAS ' ], collection.person(" I WAS ")) self.assertEquals(None, collection.person(" I XXX "))
def test_collection_duplicate(self): collection = Person2Collection() 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 = Person2Collection() self.assertIsNotNone(collection) collection.add_to_lookup("私", "彼か彼女") collection.add_to_lookup("私", '彼氏') self.assertEqual(collection.person("私"), '彼か彼女')
def test_collection_invalid(self): collection = Person2Collection() 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_collection_invalid_JP(self): collection = Person2Collection() 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 __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 test_collection_operations_JP(self): person2_text = """ "私","彼か彼女" "彼","私" "彼女","私" """ collection = Person2Collection() self.assertIsNotNone(collection) collection.load_from_text(person2_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_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 = Person2Collection() self.assertIsNotNone(collection) self.assertFalse(collection.load(storage_factory))
def test_initialise_collection(self): collection = Person2Collection() self.assertIsNotNone(collection)
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)