public string SaveCommonWordsProbabilities(Group group, int wordLength, string fName = "") { if (String.IsNullOrEmpty(fName)) { string dir = "Huffman"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } fName = String.Concat(dir + "\\" + "Group.wordLength.", wordLength, ".CommonVocabulary.csv"); } var commonWordsProbabilities = CalculateCommonWordsProbabilities(group, wordLength); //save ICsvFileWriter writer = new CsvFileWriter(fName); string header = String.Format("{0} common words that present {1} probability {2}", commonWordsProbabilities.Count, commonWordsProbabilities.Values.Sum(), Environment.NewLine); writer.WriteData(header, fName, true); string wordsProbability = ToSaveableString(commonWordsProbabilities); writer.WriteData(wordsProbability, fName, true); return(fName); }
public string SaveCompressionRate(Person p, int wordLength, CompressionType type, string fName = "") { decimal rate = GetCompressionRate(p, wordLength, type); if (String.IsNullOrEmpty(fName)) { string dir = "Huffman"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } fName = String.Concat(dir + "\\" + p.Id, ".wordLength.", wordLength, ".CompressedBy.", Enum.GetName(typeof(CompressionType), type), ".csv"); } string txt = String.Format("{0},{1}{2}", p.Id, rate, Environment.NewLine); ICsvFileWriter writer = new CsvFileWriter(fName); writer.WriteData(txt, fName, true); return(fName); }
public string SaveSequenceAsSplitedWords(Person p, int wordLengh, string fName = "") { var words = GetSequenceAsSplitedWords(p, wordLengh); if (String.IsNullOrEmpty(fName)) { string dir = "Words"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } fName = String.Concat(dir + "\\" + p.Id + ".wordLength.", wordLengh, ".txt"); } string savableString = words.Aggregate((workingSentence, next) => next + " " + workingSentence); //save ICsvFileWriter writer = new CsvFileWriter(fName); writer.WriteData(savableString, fName, true); return(fName); }
public string SaveCanonicalWordsCount(Group group, int wordLength, string fName = "") { if (String.IsNullOrEmpty(fName)) { string dir = "Huffman"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } fName = String.Concat(dir + "\\" + "Group.wordLength.", wordLength, ".CanonicalWordsCount.csv"); } var commonWordsCount = CalculateCanonicalWordsCount(group, wordLength); //save ICsvFileWriter writer = new CsvFileWriter(fName); string wordsProbability = ToSaveableString(commonWordsCount); writer.WriteData(wordsProbability, fName, true); return(fName); }