def get_relations_from_sentence(self, event_type, template, token, subjects, ents): relations = [] extracted = self.extract_relation_via_template(template, token) if extracted is not None: Logger.log_information_extraction_basic_example(str(extracted)) relations.append(extracted) for relation in relations: self.add_relation_to_concepts_if_not_existing( self.convert_relation_to_lemma(relation, ents), 2) # if event_type == EVENT_DESCRIPTION: # print(template.relation) # if template.relation in [IS_A, HAS_PROPERTY, HAS_A, CAPABLE_OF]: # extracted = self.extract_relation_via_template(template, token) # if extracted is not None: # # Logger.log_information_extraction_basic_example(str(extracted)) # # extracted.first_token = self.convert_noun_to_entities(subjects, ents, extracted.first_token) # # extracted.second_token = self.convert_noun_to_entities(subjects, ents, extracted.second_token) # # Logger.log_information_extraction_basic_example(str(extracted)) # # self.add_relation_to_concepts_if_not_existing(extracted) # # relations.append(extracted) return relations
def LoadBestModel(self, dirNameWithModelToLoad): if self._trainingLog is None: self._trainingLog = Logger(isVerbose=False) self._trainingLog.Append( "TrainingResultsRepository.LoadBestModel() warning: " \ "trainingLog was None! Potentially important details about" \ " training (or run) could haven't been saved!") bestModel = None if type(dirNameWithModelToLoad) == str: basePathToModel = self._createBasePathForResults() fullPathToModel = \ os.path.join( basePathToModel, dirNameWithModelToLoad, "best_model.pth") if os.path.isfile(fullPathToModel): bestModel = torch.load(fullPathToModel) self._trainingLog.Append( "TrainingResultsRepository.LoadBestModel() info: " \ "'training_results/{0}/best_model.pth' file has been " "loaded!".format(dirNameWithModelToLoad)) else: self._trainingLog.Append( "TrainingResultsRepository.LoadBestModel() error: " \ "cannot load 'best_model.pth' file - path does not" \ " exist! (dirname = '{0}')".format(dirNameWithModelToLoad)) else: self._trainingLog.Append( "TrainingResultsRepository.LoadBestModel() error: " \ "dirNameWithModelToLoad has wrong type! " \ "(expected: str, actual: {0})".format( type(dirNameWithModelToLoad))) return bestModel
class Scanner: """ A class that scans Slack Workspace and saves data to database Attributes ---------- client : WebClient a Slack WebClient via getting data from Slack Workspace is done database : DataBase a objects that is responsible for communicating with database logger : Logger a object that is saving scanner logs to a predefined file reaction_scraper : ReactionScrapper a object that is responsible for managing reactions from Slack Workspace Methods ------- scan_users() Saves new Slack users that are not in the database to the database scan_channels() Saves new Slack channels that are not in the database to the database scan_reactions() Saves new Slack reactions that are not in the database to the database via ReactionManager scan_complete() Saves new Slack users, channels and reactions that are not in the database to the database """ def __init__(self, client: WebClient, database: DataBase): self.client, self.database = client, database self.logger = Logger() self.reaction_scraper = ReactionScrapper(self.client, self.database, self.logger) def scan_users(self): self.logger.info_log('Started scanning for user.') response = self.client.users_list() for user in response['members']: if self.database.select(SlackUser, id=user['id']) is None: slack_user = SlackUser(user['id'], user['name']) self.database.insert(slack_user) self.logger.info_log('Finished scanning for user.') def scan_channels(self): response = self.client.conversations_list() for channel in response['channels']: date_created = datetime.fromtimestamp(channel['created']) author_id = channel['creator'] slack_channel = Channel(channel['id'], '#' + channel['name'], author_id, date_created) if self.database.select(Channel, id=channel['id']) is None: self.database.insert(slack_channel) self.logger.info_log('Finished scanning for channels.') def scan_reactions(self): self.reaction_scraper.count() def scan_complete(self): self.logger.info_log('Started complete scan.') self.scan_users() self.scan_channels() self.scan_reactions() self.logger.info_log('Finished complete scan.')
def test_eden(): response = [ "I loved you too much to let you die, dear sister, but your heart was failing you, so I gave you mine.", "He started worrying if he was important and decided he wanted to ask the people he knew if they thought he was important", "They all ignored him and he was very confused on why this was happening.", "As people gathered ’round him, singing loudly, shining bright lights everywhere, he kept his eyes on the light blue horizon.", "Smile, after all, it is Christmas and you have no reason to not smile on Christmas.", "Breathing heavily, Arabella lurched forwards, bearing her sword.", "I must congratulate you on your victory", "You think that I am his true love?", "I will do my best to save our Prince.", "She cried out as the sword flew from her grasp.", "I have broken our promise and cannot help you anymore.", "As soon as I saw him I knew it was a match made in heaven.", "Hansel got angry with Gretel", "I fought, endured, and cried my way to my degree.", "I thought he might miss the flight but I suddenly found him on the plane." ] # response = ["I thought he might miss the flight but I suddenly found him on the plane."] Logger.setup_loggers() for X in response: orsen.perform_text_understanding(X) # emotion = orsen.get_emotion(X) Logger.dump_log("=======================================") print("DONE CHECKING")
def print_occ_values(self): Logger.log_occ_values(self.af + " , " + self.de + " , " + self.of + " , " + self.oa + " , " + self.sp + " , " + self.sr + " , " + self.op + " , " + self.pros + " , " + self.stat + " , " + str(self.unexp) + " , " + self.sa + " , " + str(self.vr) + " , " + self.ed + " , " + self.eoa + " , " + self.edev + " , " + self.ef)
def test_Save_LocationIsNotString(self, notStringLocation): trainingLog = Logger(False) trainingLog._content = "Ford Sierra II 2.0 DOHC 125KM" trainingLog.Save(notStringLocation) pathToLogFile = os.path.join(str(notStringLocation), "%s.log" % trainingLog._fileName) doesLogFileExist = os.path.exists(pathToLogFile) self.assertFalse(doesLogFileExist)
def LoadPopulation(self, dirNameWithPopulationToLoad): if self._trainingLog is None: self._trainingLog = Logger(isVerbose=False) self._trainingLog.Append( "TrainingResultsRepository.LoadPopulation() warning: " \ "trainingLog was None! Potentially important details about" \ " training (or run) could haven't been saved!") population = None if type(dirNameWithPopulationToLoad) == str: basePathToPopulation = self._createBasePathForResults() fullPathToPopulation = \ os.path.join( basePathToPopulation, dirNameWithPopulationToLoad, "population") if os.path.isdir(fullPathToPopulation): models = [] listOfModelFileNames = os.listdir(fullPathToPopulation) listOfModelFileNames.sort() for fileName in listOfModelFileNames: if fnmatch(fileName, "model_*.pth"): fullPathToModelFile = \ os.path.join(fullPathToPopulation, fileName) tempModel = torch.load(fullPathToModelFile) models.append(tempModel) if len(models) == 0: self._trainingLog.Append( "TrainingResultsRepository.LoadPopulation() error: " \ "'training_results/{0}/population' is empty - " \ "has no 'model_<n>.pth' files! " \ "(examples: 'model_1.pth', 'model_2.pth' " \ "etc.)".format(dirNameWithPopulationToLoad)) else: population = models self._trainingLog.Append( "TrainingResultsRepository.LoadPopulation() info: " \ "'training_results/{0}/population' has been " \ "loaded!".format(dirNameWithPopulationToLoad)) else: self._trainingLog.Append( "TrainingResultsRepository.LoadPopulation() error: " \ "cannot load population from " \ "'training_results/{0}/population' - path " \ "does not exist!".format(dirNameWithPopulationToLoad)) else: self._trainingLog.Append( "TrainingResultsRepository.LoadPopulation() error: " \ "dirNameWithPopulationToLoad has wrong type! " \ "(expected: str, actual: {0})".format( type(dirNameWithPopulationToLoad))) return population
def get_available_device(self): device_count = pynvml.nvmlDeviceGetCount() for i in range(device_count): handle = pynvml.nvmlDeviceGetHandleByIndex(i) mem_info = pynvml.nvmlDeviceGetMemoryInfo(handle) used_ratio = mem_info.used / mem_info.total if used_ratio < 0.1: Log.log(Log.INFO, f'Use GPU:{i} for running.') return torch.device(f'cuda:{i}') Log.log(Log.INFO, 'Use CPU:0 for running.') return torch.device('cpu:0')
def test_Save_LocationDoesNotExist(self): nonExistentLocation = "TEST_NON_EXISTENT_LOCATION" self.assertFalse(os.path.exists(nonExistentLocation)) trainingLog = Logger(False) trainingLog._content = "Ford Sierra II 2.0 DOHC 125KM" trainingLog.Save(nonExistentLocation) pathToLogFile = os.path.join(nonExistentLocation, "%s.log" % trainingLog._fileName) doesLogFileExist = os.path.exists(pathToLogFile) self.assertFalse(doesLogFileExist)
def get_occ_emotion(self, event_to_eval, response): chosen_emotion = None # setup event to evaluate self.curr_event = event_to_eval if event_to_eval.type == EVENT_ACTION: Logger.log_occ_values("EVALUATING ACTION: " + str(event_to_eval.sequence_number) + " : " + self.get_vader_event_string()) # setup response self.response = response print("CHECKING AT OCC: ", event_to_eval.sequence_number) # setup emotion self.emotion = self.get_emotion(str(event_to_eval.verb.lemma_)) if self.emotion is None: Logger.log_occ_values("NO EMOTION FOUND") return None self.set_state() chosen_emotion = self.choose_emotion(event_to_eval, self.get_event_valence()) elif event_to_eval.type == EVENT_DESCRIPTION: # self.set_state() chosen_emotion = self.get_attribute_emotion(event_to_eval) # if len(chosen_emotion) == 0: # return None # # setup event to evaluate # # self.curr_event = curr_action_event # # # setup response # self.response = response # # print("CHECKING AT OCC: ", curr_action_event.sequence_number) # # setup emotion # self.emotion = self.get_emotion(str(curr_action_event.verb.lemma_)) # # # if self.emotion is None: # Logger.log_occ_values( # "EVALUATING: " + str(curr_action_event.sequence_number) + " : " + self.get_vader_event_string()) # Logger.log_occ_values("NO EMOTION FOUND") # return None # # self.set_state() # # chosen_emotion = self.choose_emotion(curr_action_event, self.get_event_valence()) self.print_occ_values() return chosen_emotion
def save(self, path: str): root_dir = './ckpt/%s/' % self.model_name if not os.path.exists(root_dir): os.makedirs(root_dir) if path is None or not path.endswith('.pth'): Log.log(Log.ERROR, 'Save filename should end with .pth.') raise ValueError pth_path = os.path.join(root_dir, path) torch.save(self.state_dict(), pth_path) Log.log(Log.INFO, 'Model is saved at [%s].' % pth_path)
def setup_templates_is_usable(self): print("--==--Dialogue Planner setup templates is usable--==--") self.init_set_dialogue_moves_usable() # fetch all usable dialogue templates # For Logging Logger.log_dialogue_model_basic("Initial Valid Dialogue Moves:") for i in range(len(DIALOGUE_LIST)): Logger.log_dialogue_model_basic_example(DIALOGUE_LIST[i]) Logger.log_dialogue_model_basic_example(self.is_usable) for i in range(len(DIALOGUE_LIST)): #check if dialogue move is initially valid to_check = DIALOGUE_LIST[i] Logger.log_dialogue_model_basic(to_check) if self.is_usable[i]: # check if dialogue has templates self.usable_templates.append( self.get_usable_templates(DIALOGUE_LIST[i].get_type())) else: self.usable_templates.append([]) # gets number of occurences self.frequency_count[i] = self.get_num_usage( DIALOGUE_LIST[i].get_type()) # recheck dialogue moves given templates for i in range(len(DIALOGUE_LIST)): self.is_usable[i] = self.is_dialogue_usable( DIALOGUE_LIST[i].get_type(), self.usable_templates[i])
def get_pickled_world(self): pickled_world = [] #pickle objects pickled_objects = [] try: for X in self.objects: pickled_objects.append(X.get_pickled_object()) except Exception as e: Logger.log_conversation("ERROR: " + str(e)) # pickle characters pickled_characters = [] try: for X in self.characters: pickled_characters.append(X.get_pickled_character()) except Exception as e: Logger.log_conversation("ERROR: " + str(e)) # pickle setting pickled_settings = [] try: for X in self.settings: pickled_settings.append(X.get_pickled_setting()) except Exception as e: Logger.log_conversation("ERROR: " + str(e)) # pickle event pickled_event_chain = [] try: for X in self.event_chains: pickled_event_chain.append(X.get_pickled_event()) except Exception as e: Logger.log_conversation("ERROR: " + str(e)) # pickle emotion event pickled_emotion_event = [] try: for X in self.emotion_events: pickled_emotion_event.append(X.get_pickled_emotion_event()) except Exception as e: Logger.log_conversation("ERROR: " + str(e)) pickled_world.append(pickled_objects) pickled_world.append(pickled_characters) pickled_world.append(pickled_settings) pickled_world.append(pickled_event_chain) pickled_world.append(pickled_emotion_event) return pickled_world
def start_storytelling(): is_end_story = False while not is_end_story: start_time = time.time() user_input = get_input() #TODO: Uncomment after testing print("TRYING TO GET TIME %s: " % (time.time() - start_time)) print("TRYING TO GET TIME again : ", str(time.time() - start_time)) Logger.log_conversation("LATENCY TIME (seconds): " + str(time.time() - start_time)) # user_input = "John kicked the love" user_input = clean_user_input(user_input) Logger.log_conversation("User : "******"IS END STORY: ", is_end_story) if not is_end_story: orsen_response = orsen.get_response(user_input) print("=========================================================") print(CURR_ORSEN_VERSION + ": " + orsen_response) print("=========================================================") Logger.log_conversation(CURR_ORSEN_VERSION + ": " + str(orsen_response)) # is_end_story = orsen.is_end_story(user_input) elif CURR_ORSEN_VERSION == EDEN: """EDEN""" # orsen_response = orsen.get_response("", move_to_execute = DIALOGUE_TYPE_E_END) orsen_response = orsen.get_response( "", move_to_execute=DIALOGUE_TYPE_RECOLLECTION) # orsen_response = orsen_response + orsen.get_response("", move_to_execute = DIALOGUE_TYPE_RECOLLECTION) print("=========================================================") print(CURR_ORSEN_VERSION + ": " + orsen_response) print("=========================================================") Logger.log_conversation(CURR_ORSEN_VERSION + ": " + str(orsen_response)) elif CURR_ORSEN_VERSION == ORSEN1 or CURR_ORSEN_VERSION == ORSEN2: # """ORSEN""" orsen_response = "Thank you for the story! Do you want to hear it again?" print("=========================================================") print(CURR_ORSEN_VERSION + ": " + orsen_response) print("=========================================================") Logger.log_conversation(CURR_ORSEN_VERSION + ": " + str(orsen_response)) user_input = get_input() if user_input.lower() in IS_AFFIRM: print(orsen.repeat_story())
def test_Append_InvalidParameters(self, isLogVerbose, invalidInfoParameter): trainingLog = Logger(isLogVerbose) logContentBeforeCall = "Ford Sierra II 2.0 DOHC 125KM\n" trainingLog._content = logContentBeforeCall with patch('sys.stdout', new=StringIO()) as fakeOutput: trainingLog.Append(invalidInfoParameter) expectedPrintMessage = "" actualPrintMessage = fakeOutput.getvalue() self.assertEqual(actualPrintMessage, expectedPrintMessage) logContentAfterCall = trainingLog._content self.assertEqual(logContentAfterCall, logContentBeforeCall)
def extract_event_creation(self, s): events = [] event = [] for token in s: if token.dep_ == 'attr': event.append(token) events.append(event) Logger.log_information_extraction_basic( "Extracted creation events from user input:") for e in events: Logger.log_information_extraction_basic_example(e) return events
def setUp(self): self.instruction1 = BasicInstruction() self.memory = Memory() self.memory.buildMemory(5) self.frame1 = Frame(self.memory, 0, 1) self.frame2 = Frame(self.memory, 1, 2) self.frame3 = Frame(self.memory, 3, 1) self.frame4 = Frame(self.memory, 4, 1) self.logger = Logger( "/home/matlock/Escritorio/Sistemas Operativos/OSProyect/resource/log.txt" ) self.mmu = MMU(self.logger) self.mmu.fullFrames.append(self.frame1) self.mmu.fullFrames.append(self.frame3) self.mmu.emptyFrames.append(self.frame2) self.mmu.emptyFrames.append(self.frame4) self.program = Program('a') self.program.addInstruction(self.instruction1) self.pcbA = PCB('a', 0, 0, 1) self.programb = Program('b') self.pcbB = PCB('b', 0, 3, 1) self.programb.addInstruction(self.instruction1) self.frame1.load(self.pcbA, self.program) self.frame3.load(self.pcbB, self.programb) self.programc = Program('c') self.programc.addInstruction(self.instruction1) self.programc.addInstruction(self.instruction1) self.programc.addInstruction(self.instruction1) self.pcbC = PCB('c', 0, 3, 3)
def main1(): instruction1 = BasicInstruction() instruction3 = Priority_Instruction() logger = Logger("../resource/log.txt") program = Program('a') program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) programb = Program('b') programb.addInstruction(instruction3) programc = Program('c') programc.addInstruction(instruction1) programc.addInstruction(instruction1) programc.addInstruction(instruction1) timer = Timer(2) memory = Memory() memory.buildMemory(9) frame1 = Frame(memory,0,9) mmu = MMU() mmu.addEmptyFrame(frame1) cpu = CPU(None,mmu,None,timer,logger) scheduler = Scheduler(PFIFO()) ioqueue = IOQueue(scheduler,logger) disk = Disk(None) kernel = Kernel(cpu,ioqueue,scheduler,mmu,disk,logger) disk.setKernel(kernel) disk.save(program) disk.save(programb) disk.save(programc) cpu.setKernel(kernel) kernel.executeProgram('a')
def test_Save_LocationIsNotDir(self): nonDirectoryLocation = "TEST_NON_DIRECTORY_LOCATION.log" with open(nonDirectoryLocation, "w") as tempFile: tempFile.write("kanapka") self.assertTrue(os.path.exists(nonDirectoryLocation)) self.assertFalse(os.path.isdir(nonDirectoryLocation)) trainingLog = Logger(False) trainingLog._content = "Ford Sierra II 2.0 DOHC 125KM" trainingLog.Save(nonDirectoryLocation) pathToLogFile = os.path.os.path.join(nonDirectoryLocation, "%s.log" % trainingLog._fileName) doesLogFileExist = os.path.exists(pathToLogFile) self.assertFalse(doesLogFileExist) os.remove(nonDirectoryLocation) self.assertFalse(os.path.exists(nonDirectoryLocation))
def __init__(self, link: str, payload: dict, **kwargs): self.database = DataBase() self.progress_queue_manager = ProgressQueueManager() self.logger = Logger() self.link = link self.payload = payload self.date_format = { 'small': '%Y-%m-%dT%H:%M', 'medium': '%Y-%m-%dCET%H:%M', 'large': '%Y-%m-%dCEST%H:%M' } self.headers = {'User-Agent': 'Mozilla/5.0'} self.html_parser = 'html.parser' if kwargs and 'headers' in kwargs: self.headers = kwargs['headers'] if kwargs and 'html_parser' in kwargs: self.html_parser = kwargs['html_parser']
def get_features(self, data_loader, path=None, trained_model=None): ''' Get the feature outputs of the model. :param data_loader: The dataloader of the dataset. :param path: The path to the pth file. :param trained_model: If use trained model, pass this model to this method. :return: features, gt, model features: (n, 512 * 7 * 7) gt: (n, ) model: The loaded model ''' if trained_model is None: model = self.model().to(self.device) epoch = model.load(path) else: model = trained_model epoch = 'trained' assert 'VGG' in model.model_name Log.log(Log.INFO, f'Start getting features with epoch [ {epoch} ] ...') features = None gt = None with torch.no_grad(): for data in tqdm(data_loader): x, y = data batch_gt = y.cpu().numpy() y = np.argmax(y, axis=1) x, y = Variable(x).to(self.device), \ Variable(y).to(self.device) batch_features = model.get_features(x) batch_features = batch_features.cpu().numpy() if features is None: features = batch_features else: features = np.concatenate((features, batch_features), axis=0) if gt is None: gt = batch_gt else: gt = np.concatenate((gt, batch_gt), axis=0) return features, gt, model
def test_Save_LogContentIsEmptyOrOnlyWhitespaces(self, logContent): testLocation = "TEST_LOCATION_FOR_LOG_FILE" if os.path.isdir(testLocation): rmtree(testLocation) os.mkdir(testLocation) self.assertTrue(os.path.isdir(testLocation)) trainingLog = Logger(False) trainingLog._content = logContent trainingLog.Save(testLocation) pathToLogFile = os.path.join(testLocation, "{0}.log".format(trainingLog._fileName)) self.assertFalse(os.path.exists(pathToLogFile)) rmtree(testLocation) self.assertFalse(os.path.isdir(testLocation))
def test_Append(self, isLogVerbose, infoToAppend, expectedPrintMessage, mock_datetime): mock_datetime.now.return_value = datetime(1995, 7, 4, 17, 15, 0) trainingLog = Logger(isLogVerbose) logContentBeforeCall = "Ford Sierra II 2.0 DOHC 125KM\n" trainingLog._content = logContentBeforeCall with patch('sys.stdout', new=StringIO()) as fakeOutput: trainingLog.Append(infoToAppend) actualPrintMessage = fakeOutput.getvalue() self.assertEqual(actualPrintMessage, expectedPrintMessage) expectedLogContentAfterCall = \ logContentBeforeCall + "[ 1995-07-04 17:15:00 ] " + \ infoToAppend + "\n" actualLogContentAfterCall = trainingLog._content self.assertEqual(actualLogContentAfterCall, expectedLogContentAfterCall)
def __init__(self, model, vr): self.model_name = model self.workers = 8 nor = False if model in ['EfficientNet']: nor = True self.data_train = dataset(subset='Train', valid_ratio=vr, normalize=nor) self.data_valid = dataset(subset='Valid', valid_ratio=vr, normalize=nor) self.data_test = dataset(subset='Test', normalize=nor) print(self.data_train) print(self.data_test) self.model = import_model(model) Log.log(Log.INFO, f'Running on model [ {model} ].') self.data_loader_train = torch.utils.data.DataLoader( dataset=self.data_train, batch_size=self.model.batch_size, shuffle=True, num_workers=self.workers) self.data_loader_valid = torch.utils.data.DataLoader( dataset=self.data_valid, batch_size=self.model.batch_size, shuffle=False, num_workers=self.workers) self.data_loader_test = torch.utils.data.DataLoader( dataset=self.data_test, batch_size=self.model.batch_size, shuffle=False, num_workers=0) self.device = self.get_available_device() dataset.clear() if not os.path.exists(os.path.join(self.log_path, model)): os.makedirs(os.path.join(self.log_path, model)) self.full_log_path = os.path.join(self.log_path, model, 'log_data.csv')
def error(): orsen_response = "I don't understand. Please repeat what you said" Logger.log_conversation( "Alexa didn't get the trigger. Went to TryAgain intent") Logger.log_dialogue_model( "Alexa didn't get the trigger. Went to TryAgain intent") Logger.log_conversation(CURR_ORSEN_VERSION + ": " + str(orsen_response)) Logger.log_dialogue_model(CURR_ORSEN_VERSION + ": " + str(orsen_response)) return question(orsen_response)
def unknown(): orsen_response = "I don't understand. Please repeat what you said" Logger.log_conversation( "Alexa didn't get the trigger. Went to AMAZON.FallbackIntent") Logger.log_dialogue_model( "Alexa didn't get the trigger. Went to AMAZON.FallbackIntent") Logger.log_conversation(CURR_ORSEN_VERSION + ": " + str(orsen_response)) Logger.log_dialogue_model(CURR_ORSEN_VERSION + ": " + str(orsen_response)) return question(orsen_response)
def get_attribute_emotion(self, event_to_eval): emotion_list = [] for attribute in event_to_eval.attributes: Logger.log_occ_values("EVALUATING DESC ATTRIBUTE: " + str(attribute.description)) retrieved_emotion = self.get_emotion_by_synonym( str(attribute.description)) if retrieved_emotion != "": emotion_list.append( self.get_emotion_by_synonym(str(attribute.description))) else: Logger.log_occ_values("NO EMOTION FOUND") simplified_emotion_str = self.simplify_emotions(emotions=emotion_list) final_emotion_list = [] for X in simplified_emotion_str: final_emotion_list.append( EmotionEventTemplateBuilder.build(event_to_eval, emotion=X)) return final_emotion_list
def remove_relation_to_concepts_if_not_valid(self, relation): print(relation) local_concept_manager = DBOConceptLocalImpl() concept = local_concept_manager.get_specific_concept( first=str(relation.first_token), relation=str(relation.relation), second=str(relation.second_token)) user = UserHandler.get_instance().curr_user if concept is None: pass else: if str(concept.user_id) != str(user.id): Logger.log_information_extraction_basic( "Decrementing concept: " + concept.one_line_print()) if concept.score <= (MIGRATION_SCORE_THRESHOLD * -1) - 1: # pass local_concept_manager.update_valid(concept.first, concept.relation, concept.second, 0) Logger.log_information_extraction_basic( "Deleting the concept " + concept.one_line_print() + " from local.") else: local_concept_manager.update_score(concept.first, concept.relation, concept.second, concept.score - 1) Logger.log_information_extraction_basic( "Decreasing the score of " + concept.one_line_print() + " from " + str(concept.score) + " to " + str(concept.score - 1))
def Save(self, population, bestIndividual, shouldSavePopulation): if self._trainingLog is None: self._trainingLog = Logger(isVerbose=False) self._trainingLog.Append( "TrainingResultsRepository.Save() warning: " \ "trainingLog was None! Potentially important details about " \ "training (or run) could haven't been saved!") locationForTrainingResults = self._createLocationForTrainingResults() os.mkdir(locationForTrainingResults) if self._doParametersHaveValidTypes(population, bestIndividual, shouldSavePopulation): if len(population) == 0: self._trainingLog.Append( "TrainingResultsRepository.Save() error: " \ "population is empty!") self._pathToLastSavedModel = None else: self._saveBestModel(locationForTrainingResults, bestIndividual) if shouldSavePopulation: self._saveWholePopulation(locationForTrainingResults, population) self._trainingLog.Append( "TrainingResultsRepository.Save() info: " \ "training results were saved to the location " \ "'{0}'!".format(locationForTrainingResults)) self._pathToLastSavedModel = locationForTrainingResults else: self._trainingLog.Append( "TrainingResultsRepository.Save() error: " \ "some of parameters have wrong type!\n" \ "type(population) == {0}, " \ "type(bestIndividual) == {1}, " \ "type(shouldSavePopulation) == {2}".format( type(population), type(bestIndividual), type(shouldSavePopulation))) self._pathToLastSavedModel = None self._trainingLog.Save(locationForTrainingResults)
def init_system(self): self.wds = System(dt=1) self.tank = Reservoir(system=self.wds, max_volume=200, min_volume=20, initial_volume=100) costant_sources = 10 normal_sources = 10 self.reservoirs = list() for i in range(0, costant_sources+normal_sources): self.reservoirs.append(Reservoir(system=self.wds, max_volume=50, min_volume=5, initial_volume=10)) self.sources = list() for i in range(0, costant_sources): self.sources.append(ConstantSource(destination=self.reservoirs[i], flow=.8)) for i in range(0, normal_sources): self.sources.append(GaussianSource( scale=30, mu=12, std=5, period=24, seed=i, destination=self.reservoirs[costant_sources + i], )) uniform_demands = 5 normal_demands = 10 double_normal_demands = 5 self.demands = list() for i in range(0, uniform_demands): self.demands.append(UniformDemand(source=self.tank, range=[0.8, 1.2], seed=i)) for i in range(0, normal_demands): self.demands.append(GaussianDemand(source=self.tank, mu=12, std=5, scale=20, period=24, seed=i)) for i in range(0, double_normal_demands): self.demands.append(DoubleGaussianDemand(source=self.tank, mus=[6, 18], stds=[2, 2], scale=10, period=24, seed=i)) self.pumps = list() for reservoir in self.reservoirs: self.pumps.append(Pump(source=reservoir, destination=self.tank, flow=1, power=1)) self.logger = Logger(groups={ "reservoirs": [self.tank] + self.reservoirs, "pumps": self.pumps, "demands": self.demands, "sources": self.sources }) self.wds.add_logger(self.logger) self.fitness = Fitness(self.logger)
def step_deploy (self, source, locations, definition = '.creep.def', environment = '.creep.env'): deployer = Deployer (Logger.build (logging.CRITICAL), definition, environment, True) self.assertTrue (deployer.deploy (source, locations, [], [], None, None))
def main(): # Parse command line options parser = argparse.ArgumentParser( description="Perform incremental deployment from Git/plain workspace to FTP/SSH/local folder." ) parser.add_argument("name", nargs="*", help="Deploy to specified named location (* = everywhere)") parser.add_argument( "-a", "--append", action="append", default=[], help="Manually append file or directory to locations", metavar="PATH", ) parser.add_argument("-b", "--base", default=".", help="Change base directory", metavar="DIR") parser.add_argument("--extra-append", action="append", default=[], help=argparse.SUPPRESS) parser.add_argument( "-e", "--environment", default=".creep.env", help="Read environment configuration from specified file or JSON string", metavar="FILE/JSON", ) parser.add_argument("-f", "--rev-from", help="Initial version used to compute diff", metavar="REV") parser.add_argument( "-d", "--definition", default=".creep.def", help="Read definition configuration from specified file or JSON string", metavar="FILE/JSON", ) parser.add_argument( "-q", "--quiet", dest="level", action="store_const", const=logging.CRITICAL + 1, default=logging.INFO, help="Quiet mode, don't display anything but errors", ) parser.add_argument( "-r", "--remove", action="append", default=[], help="Manually remove file or directory from locations", metavar="PATH", ) parser.add_argument("--extra-remove", action="append", default=[], help=argparse.SUPPRESS) parser.add_argument("-t", "--rev-to", help="Target version used to compute diff", metavar="REV") parser.add_argument( "-v", "--verbose", dest="level", action="store_const", const=logging.DEBUG, default=logging.INFO, help="Verbose mode, display extra information", ) parser.add_argument("-y", "--yes", action="store_true", help="Always answer yes to prompts") args = parser.parse_args() deployer = Deployer(Logger.build(args.level), args.definition, args.environment, args.yes) if not deployer.deploy( args.base, args.name, args.append + args.extra_append, args.remove + args.extra_append, args.rev_from, args.rev_to, ): return 1 return 0