/// <summary> /// Получает самые частоиспользуемые в тексте слова и заявляет,что они ключевые /// </summary> /// <returns></returns> private string GetKeywords() { var dictWordCount = GetDictionary(); var count = dictWordCount.Count; var keys = new List <string>(count); var vals = new List <int>(count); var trueVals = new List <int>(count); foreach (var i in dictWordCount) { keys.Add(i.Key); vals.Add(i.Value); trueVals.Add(i.Value); } var stemmer = _inputText.IndexOfAny("абвгдеёжзиёклмнопрстуфхцчшщьыъэюя".ToCharArray()) == -1 ? (IStemmer) new EnglishStemmer() : new RussianStemmer(); for (var i = 1; i < count; i++) { if (stemmer.Stem(keys[i]) != stemmer.Stem(keys[i - 1])) { continue; } if (keys[i].Length > keys[i - 1].Length || trueVals[i] < trueVals[i - 1]) { keys[i] = keys[i - 1]; trueVals[i] = trueVals[i - 1]; } vals[i] += vals[i - 1]; keys.RemoveAt(i - 1); vals.RemoveAt(i - 1); trueVals.RemoveAt(i-- - 1); count--; } var keyWords = new OrderedMultiDictionary <int, string> (true, (i, i1) => - i.CompareTo(i1), (s, s1) => String.Compare(s, s1, StringComparison.Ordinal)); for (var i = 0; i < count; i++) { keyWords.Add(vals[i], keys[i]); if (i > 10) { keyWords.Remove(keyWords.Last().Key, keyWords.Last().Value.Last()); } } var keywords = keyWords.SelectMany(i => i.Value).Aggregate("", (current, j) => current + (j + "+")); File.CreateText("./programfiles/top_ten.fail").Write(keywords); return(keywords); }
private static void RemoveLastScore() { if (scoreboard.Last().Value.Count > 0) { string[] values = new string[scoreboard.Last().Value.Count]; scoreboard.Last().Value.CopyTo(values, 0); scoreboard.Last().Value.Remove(values.Last()); } else { int[] keys = new int[scoreboard.Count]; scoreboard.Keys.CopyTo(keys, 0); scoreboard.Remove(keys.Last()); } }