public async Task EnterAsync() { var wellKnownWords = (await _usersWordsService.GetAllWords(Chat.User)) .Where(u => u._absoluteScore >= 4) .ToArray(); var paginationForWords = new List <List <UserWordModel> >(); var i = 0; while (i < wellKnownWords.Length) { paginationForWords.Add(wellKnownWords.Skip(i).Take(10).ToList()); i += 10; } var msg = new StringBuilder(); msg.Append("*"); if (!wellKnownWords.Any()) { msg.Append(Chat.Texts.NoWellKnownWords); } else if (wellKnownWords.Length == 1) { msg.Append(Chat.Texts.JustOneLearnedWord); } else if (wellKnownWords.Length <= 4) { msg.Append(Chat.Texts.LearnSomeWordsMarkdown(wellKnownWords.Length)); } else { msg.Append(Chat.Texts.LearnMoreWordsMarkdown(wellKnownWords.Length)); } msg.Append("*\r\n\r\n"); if (wellKnownWords.Length == 0) { return; } var msgWithWords = new StringBuilder(); foreach (var word in paginationForWords[0]) { msgWithWords.Append( $"{Emojis.SoftMark} *{word.Word}:* {word.AllTranslationsAsSingleString}\r\n"); } if (paginationForWords.Count > 1) { msgWithWords.Append(Chat.Texts.PageXofYMarkdown(1, paginationForWords.Count)); } InlineKeyboardButton[][] buttons = null; if (paginationForWords.Count > 1) { _wellKnownWordsUpdateHook.SetWellKnownWords(paginationForWords); _wellKnownWordsUpdateHook.SetNumberOfPaginate(0); _wellKnownWordsUpdateHook.SetBeginningMessage(msg.ToString()); buttons = new[] { WellKnownWordsHelper.GetPagingKeys(), new[] { InlineButtons.MainMenu($"{Emojis.MainMenu} {Chat.Texts.MainMenuButton}") } }; } else { buttons = new[] { new[] { InlineButtons.MainMenu($"{Chat.Texts.TranslateButton} {Emojis.Translate}") } } }; await Chat.ChatIo.SendMarkdownMessageAsync(msgWithWords.ToString(), buttons); } }
public void AddMutualPhrasesToVocab(int userId, int maxCount) { var allWords = _usersWordsService.GetAllWords(userId).Select(s => s.ToLower().Trim()).ToHashSet(); var allWordsForLearning = _usersWordsService.GetAllUserWordsForLearning(userId); List <int> allPhrasesIdForUser = new List <int>(); foreach (var word in allWordsForLearning) { var phrases = word.GetPhrasesId(); allPhrasesIdForUser.AddRange(phrases); } var allPhrases = _dictionaryService.FindSeverealPrasesById(allPhrasesIdForUser.ToArray()); List <Phrase> searchedPhrases = new List <Phrase>(); int endings = 0; foreach (var phrase in allPhrases) { var phraseText = phrase.EnPhrase; int count = 0; int endingCount = 0; foreach (var word in phraseText.Split(new[] { ' ', ',' })) { var lowerWord = word.Trim().ToLower(); if (allWords.Contains(lowerWord)) { count++; } else if (word.EndsWith('s')) { var withoutEnding = lowerWord.Remove(lowerWord.Length - 1); if (allWords.Contains(withoutEnding)) { endingCount++; } } else if (word.EndsWith("ed")) { var withoutEnding = lowerWord.Remove(lowerWord.Length - 2); if (allWords.Contains(withoutEnding)) { endingCount++; } } else if (word.EndsWith("ing")) { var withoutEnding = lowerWord.Remove(lowerWord.Length - 3); if (allWords.Contains(withoutEnding)) { endingCount++; } } if (count + endingCount > 1) { searchedPhrases.Add(phrase); if (endingCount > 0) { endings++; } if (count + endingCount > 2) { Console.WriteLine(phraseText); } break; } } } var firstPhrases = searchedPhrases.Randomize().Take(maxCount); foreach (var phrase in firstPhrases) { Console.WriteLine("Adding " + phrase.EnPhrase); _usersWordsService.AddPhraseAsWordToUserCollection(phrase); //cv _usersWordsService.RemovePhrase(phrase.Id,userId); } Console.WriteLine($"Found: {searchedPhrases.Count}+{endings}"); }