public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { Console.WriteLine("=====> " + word.OriginWord + " <====="); Console.WriteLine("Press any key to see the translation..."); Console.ReadKey(); Console.WriteLine("Translation is \r\n" + word.Translation + "\r\n Did you guess?"); Console.WriteLine("[Y]es [N]o [E]xit"); var answer = Console.ReadKey(); switch (answer.Key) { case ConsoleKey.Y: service.RegistrateSuccess(word); return(ExamResult.Passed); case ConsoleKey.N: service.RegistrateFailure(word); return(ExamResult.Failed); case ConsoleKey.E: return(ExamResult.Exit); case ConsoleKey.Escape: return(ExamResult.Exit); default: return(ExamResult.Retry); } }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { var variants = examList.Randomize().Select(e => e.OriginWord).ToArray(); Console.WriteLine("=====> " + word.Translation + " <====="); for (int i = 1; i <= variants.Length; i++) { Console.WriteLine($"{i}: " + variants[i - 1]); } Console.Write("Choose the translation: "); var selected = Console.ReadLine(); if (selected == null || selected.ToLower().StartsWith("e")) { return(ExamResult.Exit); } if (!int.TryParse(selected, out var selectedIndex) || selectedIndex > variants.Length || selectedIndex < 1) { return(ExamResult.Retry); } if (variants[selectedIndex - 1] == word.OriginWord) { service.RegistrateSuccess(word); return(ExamResult.Passed); } service.RegistrateFailure(word); return(ExamResult.Failed); }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { var words = word.OriginWord.Split(',').Select(s => s.Trim()); var minCount = words.Min(t => t.Count(c => c == ' ')); if (minCount > 0 && word.PassedScore < minCount * 4) { return(ExamResult.Impossible); } Console.WriteLine("=====> " + word.Translation + " <====="); Console.Write("Write the translation: "); var userEntry = Console.ReadLine(); if (string.IsNullOrEmpty(userEntry)) { return(ExamResult.Retry); } if (words.Any(t => string.Compare(userEntry, t, StringComparison.OrdinalIgnoreCase) == 0)) { service.RegistrateSuccess(word); return(ExamResult.Passed); } else { //search for other translation var translationCandidate = service.Get(userEntry.ToLower()); if (translationCandidate != null) { if (translationCandidate.GetTranslations().Any(t1 => word.GetTranslations().Any(t2 => string.CompareOrdinal(t1.Trim(), t2.Trim()) == 0))) { //translation is correct, but for other word Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"the translation was correct, but the question was about the word '{word.OriginWord}'\r\nlet's try again"); Console.ResetColor(); Console.ReadLine(); return(ExamResult.Retry); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"'{userEntry}' translates as {translationCandidate.Translation}"); Console.ResetColor(); service.RegistrateFailure(word); return(ExamResult.Failed); } } Console.WriteLine("The translation was: " + word.OriginWord); service.RegistrateFailure(word); return(ExamResult.Failed); } }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var targetPhrase = word.Phrases.GetRandomItem(); var other = examList.SelectMany(e => e.Phrases) .Where(p => !string.IsNullOrWhiteSpace(p?.Origin) && p != targetPhrase) .Take(8); if (!other.Any()) { return(ExamResult.Impossible); } var variants = other .Append(targetPhrase) .Randomize() .Select(e => e.Translation) .ToArray(); Console.WriteLine("=====> " + targetPhrase.Origin + " <====="); for (int i = 1; i <= variants.Length; i++) { Console.WriteLine($"{i}: " + variants[i - 1]); } Console.Write("Choose the translation: "); var selected = Console.ReadLine(); if (selected.ToLower().StartsWith("e")) { return(ExamResult.Exit); } if (!int.TryParse(selected, out var selectedIndex) || selectedIndex > variants.Length || selectedIndex < 1) { return(ExamResult.Retry); } if (variants[selectedIndex - 1] == targetPhrase.Translation) { service.RegistrateSuccess(word); return(ExamResult.Passed); } service.RegistrateFailure(word); return(ExamResult.Failed); }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { var words = word.OriginWord.Split(',').Select(s => s.Trim()); var minCount = words.Min(t => t.Count(c => c == ' ')); if (minCount > 0 && word.PassedScore < minCount * 4) { return(ExamResult.Impossible); } await chat.SendMessage($"=====> {word.Translation} <=====\r\nWrite the translation... "); var userEntry = await chat.WaitUserTextInput(); if (string.IsNullOrEmpty(userEntry)) { return(ExamResult.Retry); } if (words.Any(t => string.Compare(userEntry, t, StringComparison.OrdinalIgnoreCase) == 0)) { service.RegistrateSuccess(word); return(ExamResult.Passed); } else { //search for other translation var translationCandidate = service.Get(userEntry.ToLower()); if (translationCandidate != null) { if (translationCandidate.GetTranslations().Any(t1 => word.GetTranslations().Any(t2 => string.CompareOrdinal(t1.Trim(), t2.Trim()) == 0))) { //translation is correct, but for other word await chat.SendMessage($"the translation was correct, but the question was about the word '{word.OriginWord}'\r\nlet's try again"); //Console.ReadLine(); return(ExamResult.Retry); } else { await chat.SendMessage($"'{userEntry}' translates as {translationCandidate.Translation}"); service.RegistrateFailure(word); return(ExamResult.Failed); } } await chat.SendMessage("The translation was: " + word.OriginWord); service.RegistrateFailure(word); return(ExamResult.Failed); } }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { var msg = $"=====> {word.OriginWord} <=====\r\nDo you know the translation?"; var _ = chat.SendMessage(msg, new InlineKeyboardButton() { CallbackData = "1", Text = "See the translation" }); await chat.WaitInlineIntKeyboardInput(); _ = chat.SendMessage("Translation is \r\n" + word.Translation + "\r\n Did you guess?", new InlineKeyboardButton { CallbackData = "1", Text = "Yes" }, new InlineKeyboardButton { CallbackData = "0", Text = "No" }); var choice = await chat.WaitInlineIntKeyboardInput(); if (choice == 1) { service.RegistrateSuccess(word); return(ExamResult.Passed); } else { service.RegistrateFailure(word); return(ExamResult.Failed); } /*var answer = Console.ReadKey(); * switch (answer.Key) * { * case ConsoleKey.Y: * service.RegistrateSuccess(word); * return ExamResult.Passed; * case ConsoleKey.N: * service.RegistrateFailure(word); * return ExamResult.Failed; * case ConsoleKey.E: return ExamResult.Exit; * case ConsoleKey.Escape: return ExamResult.Exit; * default: return ExamResult.Retry; * }*/ }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var targetPhrase = word.Phrases.GetRandomItem(); string shuffled; while (true) { var split = targetPhrase.Origin.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (split.Length < 2) { return(ExamResult.Impossible); } shuffled = string.Join(" ", split.Randomize()); if (shuffled != targetPhrase.Origin) { break; } } await chat.SendMessage("Words in phrase are shuffled. Write them in correct order:\r\n'" + shuffled + "'"); string entry = null; while (string.IsNullOrWhiteSpace(entry)) { entry = await chat.WaitUserTextInput(); entry = entry.Trim(); } if (string.CompareOrdinal(targetPhrase.Origin, entry) == 0) { service.RegistrateSuccess(word); return(ExamResult.Passed); } await chat.SendMessage($"Original phrase was: '{targetPhrase.Origin}'"); service.RegistrateFailure(word); return(ExamResult.Failed); }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var targetPhrase = word.Phrases.GetRandomItem(); string shuffled; while (true) { var split = targetPhrase.Origin.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (split.Length < 2) { return(ExamResult.Impossible); } shuffled = string.Join(" ", split.Randomize()); if (shuffled != targetPhrase.Origin) { break; } } Console.WriteLine("Words in phrase are shuffled. Write them in correct order:\r\n'" + shuffled + "'"); string entry = null; while (string.IsNullOrWhiteSpace(entry)) { Console.WriteLine(":"); entry = Console.ReadLine().Trim(); } if (string.CompareOrdinal(targetPhrase.Origin, entry) == 0) { service.RegistrateSuccess(word); return(ExamResult.Passed); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Original phrase was: '{targetPhrase.Origin}'"); Console.ResetColor(); service.RegistrateFailure(word); return(ExamResult.Failed); }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var phrase = word.Phrases.GetRandomItem(); var replaced = phrase.Origin.Replace(phrase.OriginWord, "..."); if (replaced == phrase.Origin) { return(ExamResult.Impossible); } var sb = new StringBuilder(); sb.AppendLine($"\"{phrase.Translation}\""); sb.AppendLine(); sb.AppendLine($" translated as "); sb.AppendLine(); sb.AppendLine($"\"{replaced}\""); sb.AppendLine($"Choose missing word..."); var variants = examList.Randomize().Select(e => e.OriginWord).ToArray(); var _ = chat.SendMessage(sb.ToString(), InlineButtons.CreateVariants(variants)); var choice = await chat.TryWaitInlineIntKeyboardInput(); if (choice == null) { return(ExamResult.Retry); } if (variants[choice.Value] == word.OriginWord) { service.RegistrateSuccess(word); return(ExamResult.Passed); } await chat.SendMessage($"Origin was: \"{phrase.Origin}\""); service.RegistrateFailure(word); return(ExamResult.Failed); }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var phrase = word.Phrases.GetRandomItem(); var replaced = phrase.Translation.Replace(phrase.TranslationWord, "..."); if (replaced == phrase.Translation) { return(ExamResult.Impossible); } var sb = new StringBuilder(); sb.AppendLine($"\"{phrase.Origin}\""); sb.AppendLine($" translated as "); sb.AppendLine($"\"{replaced}\""); sb.AppendLine(); sb.AppendLine($"Enter missing word: "); while (true) { var enter = await chat.WaitUserTextInput(); if (string.IsNullOrWhiteSpace(enter)) { continue; } if (string.CompareOrdinal(phrase.TranslationWord.ToLower().Trim(), enter.ToLower().Trim()) == 0) { service.RegistrateSuccess(word); return(ExamResult.Passed); } await chat.SendMessage($"Origin phrase was \"{phrase.Translation}\""); service.RegistrateFailure(word); return(ExamResult.Failed); } }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { var translations = word.GetTranslations(); var minCount = translations.Min(t => t.Count(c => c == ' ')); if (minCount > 0 && word.PassedScore < minCount * 4) { return(ExamResult.Impossible); } Console.WriteLine("=====> " + word.OriginWord + " <====="); Console.Write("Write the translation: "); var translation = Console.ReadLine(); if (string.IsNullOrEmpty(translation)) { return(ExamResult.Retry); } if (translations.Any(t => string.Compare(translation, t, StringComparison.OrdinalIgnoreCase) == 0)) { service.RegistrateSuccess(word); return(ExamResult.Passed); } else { if (word.GetAllMeanings() .Any(t => string.Compare(translation, t, StringComparison.OrdinalIgnoreCase) == 0)) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Choosen translation is out of scope (but it is correct). Expected translations are: " + word.Translation); Console.ResetColor(); Console.WriteLine(); return(ExamResult.Impossible); } Console.WriteLine("The translation was: " + word.Translation); service.RegistrateFailure(word); return(ExamResult.Failed); } }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var phrase = word.Phrases.GetRandomItem(); var replaced = phrase.Translation.Replace(phrase.TranslationWord, "..."); if (replaced == phrase.Translation) { return(ExamResult.Impossible); } Console.WriteLine($"\"{phrase.Origin}\""); Console.WriteLine($" translated as "); Console.WriteLine($"\"{replaced}\""); Console.WriteLine(); Console.Write($"Enter missing word: "); while (true) { var enter = Console.ReadLine(); if (string.IsNullOrWhiteSpace(enter)) { continue; } if (string.CompareOrdinal(phrase.TranslationWord.ToLower().Trim(), enter.ToLower().Trim()) == 0) { service.RegistrateSuccess(word); return(ExamResult.Passed); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Origin phrase was \"{phrase.Translation}\""); Console.ResetColor(); service.RegistrateFailure(word); return(ExamResult.Failed); } }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { var variants = examList.Randomize().Select(e => e.Translation).ToArray(); var msg = $"=====> {word.OriginWord} <=====\r\nChoose the translation"; await chat.SendMessage(msg, InlineButtons.CreateVariants(variants)); var choice = await chat.TryWaitInlineIntKeyboardInput(); if (choice == null) { return(ExamResult.Retry); } if (variants[choice.Value] == word.Translation) { service.RegistrateSuccess(word); return(ExamResult.Passed); } service.RegistrateFailure(word); return(ExamResult.Failed); }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { var translations = word.GetTranslations(); var minCount = translations.Min(t => t.Count(c => c == ' ')); if (minCount > 0 && word.PassedScore < minCount * 4) { return(ExamResult.Impossible); } await chat.SendMessage($"=====> {word.OriginWord} <=====\r\nWrite the translation... "); var translation = await chat.WaitUserTextInput(); if (string.IsNullOrEmpty(translation)) { return(ExamResult.Retry); } if (translations.Any(t => string.Compare(translation, t, StringComparison.OrdinalIgnoreCase) == 0)) { service.RegistrateSuccess(word); return(ExamResult.Passed); } else { if (word.GetAllMeanings() .Any(t => string.Compare(translation, t, StringComparison.OrdinalIgnoreCase) == 0)) { await chat.SendMessage($"Choosen translation is out of scope (but it is correct). Expected translations are: " + word.Translation); return(ExamResult.Impossible); } await chat.SendMessage("The translation was: " + word.Translation); service.RegistrateFailure(word); return(ExamResult.Failed); } }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { var msg = $"=====> {word.Translation} <=====\r\nDo you know the translation?"; var _ = chat.SendMessage(msg, new InlineKeyboardButton() { CallbackData = "1", Text = "See the translation" }); await chat.WaitInlineIntKeyboardInput(); _ = chat.SendMessage("Translation is \r\n" + word.OriginWord + "\r\n Did you guess?", new InlineKeyboardButton { CallbackData = "1", Text = "Yes" }, new InlineKeyboardButton { CallbackData = "0", Text = "No" }); var choice = await chat.WaitInlineIntKeyboardInput(); if (choice == 1) { service.RegistrateSuccess(word); return(ExamResult.Passed); } else { service.RegistrateFailure(word); return(ExamResult.Failed); } }
public async Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var targetPhrase = word.Phrases.GetRandomItem(); var other = examList.SelectMany(e => e.Phrases) .Where(p => !string.IsNullOrWhiteSpace(p?.Origin) && p != targetPhrase) .Take(8); if (!other.Any()) { return(ExamResult.Impossible); } var variants = other .Append(targetPhrase) .Randomize() .Select(e => e.Translation) .ToArray(); var msg = $"=====> {targetPhrase.Origin} <=====\r\nChoose the translation"; await chat.SendMessage(msg, InlineButtons.CreateVariants(variants)); var choice = await chat.TryWaitInlineIntKeyboardInput(); if (choice == null) { return(ExamResult.Retry); } if (variants[choice.Value] == targetPhrase.Translation) { service.RegistrateSuccess(word); return(ExamResult.Passed); } service.RegistrateFailure(word); return(ExamResult.Failed); /* * Console.WriteLine("=====> " + targetPhrase.Origin + " <====="); * * for (int i = 1; i <= variants.Length; i++) * { * Console.WriteLine($"{i}: " + variants[i - 1]); * } * * Console.Write("Choose the translation: "); * * var selected = Console.ReadLine(); * if (selected.ToLower().StartsWith("e")) * return ExamResult.Exit; * * if (!int.TryParse(selected, out var selectedIndex) || selectedIndex > variants.Length || * selectedIndex < 1) * return ExamResult.Retry; * * if (variants[selectedIndex - 1] == targetPhrase.Translation) * { * service.RegistrateSuccess(word); * return ExamResult.Passed; * } * service.RegistrateFailure(word); * return ExamResult.Failed;*/ }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) { if (!word.Phrases.Any()) { return(ExamResult.Impossible); } var phrase = word.Phrases.GetRandomItem(); var replaced = phrase.Origin.Replace(phrase.OriginWord, "..."); if (replaced == phrase.Origin) { return(ExamResult.Impossible); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\"{phrase.Translation}\""); Console.ResetColor(); Console.WriteLine(); Console.WriteLine($" translated as "); Console.WriteLine(); Console.WriteLine($"\"{replaced}\""); Console.ResetColor(); Console.WriteLine(); Console.WriteLine($"Choose missing word: "); var variants = examList.Randomize().Select(e => e.OriginWord).ToArray(); for (int i = 1; i <= variants.Length; i++) { Console.WriteLine($"{i}: " + variants[i - 1]); } Console.Write("Choose the translation: "); var selected = Console.ReadLine(); if (selected.ToLower().StartsWith("e")) { return(ExamResult.Exit); } if (!int.TryParse(selected, out var selectedIndex) || selectedIndex > variants.Length || selectedIndex < 1) { return(ExamResult.Retry); } if (variants[selectedIndex - 1] == word.OriginWord) { service.RegistrateSuccess(word); return(ExamResult.Passed); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Origin was: \"{phrase.Origin}\""); Console.ResetColor(); service.RegistrateFailure(word); return(ExamResult.Failed); }