static void Save(sentence_pair pair, SaveInfo info) { string fileName = info.FileName + ".txt"; if (!File.Exists(fileName)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(fileName)) { sw.WriteLine("<?xml version = \"1.0\" encoding = \"utf - 8\" ?>"); sw.WriteLine("<sentence_pairs>"); } } // This text is always added, making the file longer over time // if it is not deleted. using (StreamWriter sw = File.AppendText(fileName)) { sw.WriteLine($"<sentence_pair classification = \"\" edit_distance = \"{pair.edit_distance}\" shared_words = \"{pair.shared_words}\" pair_no = \"{info.Counter}\" >"); sw.WriteLine($"<sentence_1>{pair.sentence_1}</sentence_1>"); sw.WriteLine($"<sentence_2>{pair.sentence_2}</sentence_2>"); sw.WriteLine($"</sentence_pair>"); } }
static void SavePairToFile(sentence_pair pair, SaveInfo info) { lock (info.lock_obj) { if (info.Counter <= info.MaxSentencePairs) { Save(pair, info); info.Increment(); } } }