/** * Allows to dump the search lattice in case it is needed. * Note that, in this code we do not care if in case of an * error we do not close the files. This is because lattice * dumping is only needed while model training, plus it should * work without throwing any errors. So if it happens then * it is not a big problem. * @param de_params the decoder parameters */ inline void dump_search_lattice(const de_parameters & de_params) const { LOG_DEBUG1 << "Dumping the search lattice for the translation task " << m_task_id << END_LOG; //Create the file names, we do not add the session id and job id as //the tasks in training mode are issued unique task ids. const string file_name = de_params.m_lattices_folder + "/" + to_string(m_task_id) + "."; const string scores_file_name = file_name + de_params.m_scores_file_ext; const string lattice_file_name = file_name + de_params.m_lattice_file_ext; //Open the output stream to the files ofstream scores_file(scores_file_name), lattice_file(lattice_file_name); try { //Check that the files are open ASSERT_CONDITION_THROW(!scores_file.is_open(), string("Could not open: ") + scores_file_name + string(" for writing")); ASSERT_CONDITION_THROW(!lattice_file.is_open(), string("Could not open: ") + lattice_file_name + string(" for writing")); //Call the sentence decoder to do dumping. m_decoder.dump_search_lattice(lattice_file, scores_file); } catch (std::exception & ex) { //Close the lattice files LOG_ERROR << ex.what() << END_LOG; close_lattice_files(scores_file, lattice_file); //Re-throw an exception, do not use the exception object as it would //create a copy of it loosing all needed additional information. throw; } //Close the lattice files close_lattice_files(scores_file, lattice_file); }
void Top10::LoadScores() { //Clear the list just in case scores.clear(); //Open a file for reading ifstream scores_file(FILE_SCORES.c_str()); if(scores_file != NULL) { for(int n = 0; n != 10; n++) { //Temporal variables string name; unsigned int score; unsigned int kills; //Load the variables scores_file >> name; scores_file >> score; scores_file >> kills; //Create a temporal register Score loaded_register(name, score, kills); //Insert the register scores.push_back(loaded_register); //Skip past the end of the line scores_file.ignore(); } //Close the file scores_file.close(); //Debug //PrintScores(); //If everything goes fine return; } //The default configuration fprintf(stderr, "Error, unable to load the scores file.\n"); }
void Top10::SaveScores() { //Open a file for writing ofstream scores_file(FILE_SCORES.c_str()); //Check if this score is a new high score for(list<Score>::const_iterator iterator = scores.begin(); iterator != scores.end(); iterator++) { //Write the data to the scores scores_file << iterator->name; scores_file << "\t"; scores_file << iterator->score; scores_file << "\t"; scores_file << iterator->kills; scores_file << "\n"; } //Close the file scores_file.close(); }