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) { 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 void Enter(NewWordsService service) { Console.WriteLine("Updating Db"); service.UpdateAgingAndRandomize(); var allModels = service.GetAll(); foreach (var pairModel in allModels) { Console.WriteLine( $"{pairModel.OriginWord} - {pairModel.Translation} score: {pairModel.PassedScore} / {pairModel.Examed} {pairModel.AggregateScore:##.##}"); } Console.WriteLine($"Has {allModels.Length} models"); var examSum = allModels.Sum(a => a.Examed); var passedSum = allModels.Sum(a => a.PassedScore); var passedAggregatedSum = allModels.Sum(a => Math.Min(1, a.PassedScore / (double)PairModel.MaxExamScore)); var passedCount = allModels.Count(a => a.PassedScore >= PairModel.MaxExamScore); var count = allModels.Length; Console.WriteLine($"Knowledge: {100 * passedAggregatedSum / (double)(count):##.##} %"); Console.WriteLine($"Known: {100 * passedCount / (double)(count):##.##} %"); Console.WriteLine($"Failures : {100 * passedSum / (double)(examSum):##.##} %"); }
public void Enter(NewWordsService service) { var allWords = service.GetAll(); RenderKnowledgeHistogram(allWords); Console.WriteLine(); Console.WriteLine(); RenderAddingTimeLine(allWords); RenderExamsTimeLine(service.GetAllExams()); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); Console.WriteLine(); Console.WriteLine($"Context phrases count = {service.GetContextPhraseCount()}"); Console.WriteLine($"Words count = {allWords.Count(w=>!w.OriginWord.Contains(' '))}"); Console.WriteLine($"Words and sentences count = {allWords.Length}"); var groups = allWords .GroupBy(s => s.State) .OrderBy(s => (int)s.Key) .Select(s => new { state = s.Key, count = s.Count() }); var doneCount = allWords.Count(a => a.PassedScore >= PairModel.MaxExamScore); Console.WriteLine($"Done: {doneCount} words ({(doneCount * 100 / allWords.Length)}%)"); Console.WriteLine($"Unknown: {allWords.Length - doneCount} words"); Console.WriteLine(); var learningRate = GetLearningRate(allWords); Console.WriteLine("Score is " + learningRate); if (learningRate < 100) { Console.WriteLine("You has to add more words!"); } else if (learningRate < 200) { Console.WriteLine("It's time to add new words!"); } else if (learningRate < 300) { Console.WriteLine("Zen!"); } else if (learningRate < 400) { Console.WriteLine("Let's do some exams"); } else { Console.WriteLine("Exams exams exams!"); Console.WriteLine($"You have to make at least {(learningRate-300)/10} more exams"); } }
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 AddingWordsMode( Chat chat, YandexTranslateApiClient yapiTranslateApiClient, YandexDictionaryApiClient yandexDictionaryApiClient, NewWordsService wordService ) { _chat = chat; _wordService = wordService; _yapiDicClient = yandexDictionaryApiClient; _yapiTransClient = yapiTranslateApiClient; }
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); }
static void Main() { TaskScheduler.UnobservedTaskException += (sender, args) => Console.WriteLine($"Unobserved ex {args.Exception}"); var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false); IConfigurationRoot configuration = builder.Build(); var yadicapiKey = configuration.GetSection("yadicapi").GetSection("key").Value; var yadicapiTimeout = TimeSpan.FromSeconds(5); var dbFileName = configuration.GetSection("wordDb").Value; var yatransapiKey = configuration.GetSection("yatransapi").GetSection("key").Value; var yatransapiTimeout = TimeSpan.FromSeconds(5); _yapiDicClient = new YandexDictionaryApiClient(yadicapiKey, yadicapiTimeout); _yapiTransClient = new YandexTranslateApiClient(yatransapiKey, yatransapiTimeout); var repo = new WordsRepository(dbFileName); repo.ApplyMigrations(); Console.WriteLine("Dic started"); _wordsService = new NewWordsService(new RuengDictionary(), repo); _botClient = new TelegramBotClient(ApiToken); var me = _botClient.GetMeAsync().Result; Console.WriteLine( $"Hello, World! I am user {me.Id} and my name is {me.FirstName}." ); _botClient.OnUpdate += BotClientOnOnUpdate; _botClient.OnMessage += Bot_OnMessage; _botClient.StartReceiving(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); _botClient.StopReceiving(); }
public void Enter(NewWordsService service) { int phraselessCount = 0; var allWords = service.GetAll(); int newPhrases = 0; foreach (var pairModel in allWords) { if (pairModel.Revision >= 1) { continue; } var translateTask = _client.Translate(pairModel.OriginWord); translateTask.Wait(); var yaTranslations = translateTask.Result.SelectMany(r => r.Tr).Select(s => s.Text.Trim().ToLower()); var originTranlations = pairModel.Translation.Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim().ToLower()); pairModel.AllMeanings = string.Join(";;", yaTranslations.Union(originTranlations).Distinct()); var withPhrases = service.GetOrNullWithPhrases(pairModel.OriginWord); if (!withPhrases.Phrases.Any() || (withPhrases.Phrases.Count == 1 && withPhrases.Phrases[0].IsEmpty)) { var allPhrases = translateTask.Result.SelectMany(r => r.Tr).SelectMany(r => r.GetPhrases(pairModel.OriginWord)).ToList(); foreach (var phrase in allPhrases) { service.Add(phrase); newPhrases++; } if (!allPhrases.Any()) { phraselessCount++; } } pairModel.Revision = 1; service.UpdateRatings(pairModel); Console.Write("."); } Console.WriteLine("new phrases:" + newPhrases); Console.WriteLine("Phraseless count:" + phraselessCount); Console.WriteLine("withPhrases:" + (allWords.Length - phraselessCount)); }
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 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 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 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 GraphsStatsFlow(Chat chat, NewWordsService wordsService) { _chat = chat; _wordsService = wordsService; }
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); }
public void Enter(NewWordsService service) { var dicPing = _yapiDicClient.Ping(); var transPing = _yapiTransClient.Ping(); Task.WaitAll(dicPing, transPing); var timer = new Timer(5000) { AutoReset = false }; timer.Enabled = true; timer.Elapsed += (s, e) => { var pingDicApi = _yapiDicClient.Ping(); var pingTransApi = _yapiTransClient.Ping(); Task.WaitAll(pingDicApi, pingTransApi); timer.Enabled = true; }; if (_yapiDicClient.IsOnline) { Console.WriteLine("Yandex dic is online"); } else { Console.WriteLine("Yandex dic is offline"); } if (_yapiTransClient.IsOnline) { Console.WriteLine("Yandex trans is online"); } else { Console.WriteLine("Yandex trans is offline"); } while (true) { Console.Write("Enter [e] for exit or "); Console.Write("Enter english word: "); string word = Console.ReadLine(); if (word == "e") { break; } Task <YaDefenition[]> task = null; if (_yapiDicClient.IsOnline) { task = _yapiDicClient.Translate(word); } task?.Wait(); List <TranslationAndContext> translations = new List <TranslationAndContext>(); if (task?.Result?.Any() == true) { var variants = task.Result.SelectMany(r => r.Tr); foreach (var yandexTranslation in variants) { var phrases = yandexTranslation.GetPhrases(word); translations.Add(new TranslationAndContext(word, yandexTranslation.Text, yandexTranslation.Pos, phrases.ToArray())); } } else { var dictionaryMatch = service.GetTranslations(word); if (dictionaryMatch != null) { translations.AddRange( dictionaryMatch.Translations.Select(t => new TranslationAndContext(dictionaryMatch.Origin, t, dictionaryMatch.Transcription, new Phrase[0]))); } } if (!translations.Any()) { try { var transAnsTask = _yapiTransClient.Translate(word); transAnsTask.Wait(); if (string.IsNullOrWhiteSpace(transAnsTask.Result)) { Console.WriteLine("No translations found. Check the word and try again"); } else { translations.Add(new TranslationAndContext(word, transAnsTask.Result, null, new Phrase[0])); } } catch (Exception e) { Console.WriteLine("No translations found. Check the word and try again"); } } if (translations.Any()) { Console.WriteLine("e: [back to main menu]"); Console.WriteLine("c: [CANCEL THE ENTRY]"); int i = 1; foreach (var translation in translations) { if (translation.Phrases.Any()) { Console.WriteLine($"{i}: {translation.Translation}\t (+{translation.Phrases.Length})"); } else { Console.WriteLine($"{i}: {translation.Translation}"); } i++; } try { var results = ChooseTranslation(translations.ToArray()); if (results?.Any() == true) { var allTranslations = results.Select(t => t.Translation).ToArray(); var allPhrases = results.SelectMany(t => t.Phrases).ToArray(); service.SaveForExams( word: word, transcription: translations[0].Transcription, translations: allTranslations, allMeanings: translations.Select(t => t.Translation.Trim().ToLower()).ToArray(), phrases: allPhrases); Console.WriteLine($"Saved. Tranlations: {allTranslations.Length}, Phrases: {allPhrases.Length}"); } } catch (OperationCanceledException) { return; } } } }
public ExamResult Pass(NewWordsService service, PairModel word, PairModel[] examList) => _origin.Pass(service, word, examList);
static void Main(string[] args) { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false); IConfigurationRoot configuration = builder.Build(); var yadicapiKey = configuration.GetSection("yadicapi").GetSection("key").Value; var yadicapiTimeout = TimeSpan.FromSeconds(5); var dbFileName = configuration.GetSection("wordDb").Value; var yatransapiKey = configuration.GetSection("yatransapi").GetSection("key").Value; var yatransapiTimeout = TimeSpan.FromSeconds(5); var yapiDicClient = new YandexDictionaryApiClient(yadicapiKey, yadicapiTimeout); var yapiTransClient = new YandexTranslateApiClient(yatransapiKey, yatransapiTimeout); var modes = new IConsoleMode[] { new ExamMode(), new WordAdditionMode(yapiTransClient, yapiDicClient), new GraphsStatsMode(), // new RandomizeMode(), // new AddPhraseToWordsMode(yapiDicClient), }; var repo = new WordsRepository(dbFileName); repo.ApplyMigrations(); Console.WriteLine("Dic started"); //var metrics = repo.GetAllQuestionMetrics(); //string path = "T:\\Dictionary\\eng_rus_full.json"; //Console.WriteLine("Loading dictionary"); //var dictionary = Dic.Logic.Dictionaries.Tools.ReadFromFile(path); var service = new NewWordsService(new RuengDictionary(), repo); Console.Clear(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(@" ____ _ _ ____ ___ _ ____ _ _ ____ ___ ____ _ | |__| | | | | [__ |_/ |__| / |__| | |___ | | |__| | | ___] | \_ | | /__ | | |___ "); Console.ResetColor(); while (true) { Console.WriteLine(); Console.WriteLine("ESC: Quit"); for (int i = 0; i < modes.Length; i++) { Console.WriteLine($"{i+1}: {modes[i].Name}"); } Console.WriteLine(); Console.Write("Choose mode:"); var val = Console.ReadKey(); Console.WriteLine(); if (val.Key == ConsoleKey.Escape) { return; } var choice = ((int)val.Key - (int)ConsoleKey.D1); if (choice > -1 && choice < modes.Length) { var selected = modes[choice]; Console.Clear(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("====== " + selected.Name + " ======"); Console.ResetColor(); modes[choice].Enter(service); } Console.WriteLine(); Console.WriteLine("==========================================="); } }
public WordsController(NewWordsService wordsService, YandexDictionaryApiClient yaapiClient, YandexTranslateApiClient yaTransApi) { _yandexDictionaryApiClient = yaapiClient; _yaTransApi = yaTransApi; _wordsService = wordsService; }
public Task <ExamResult> Pass(Chat chat, NewWordsService service, PairModel word, PairModel[] examList) => _origin.Pass(chat, service, word, examList);
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 void Enter(NewWordsService service) { service.UpdateAgingAndRandomize(50); Console.WriteLine("Examination"); var words = service.GetPairsForLearning(9, 3); Console.Clear(); Console.WriteLine("Examination: "); if (words.Average(w => w.PassedScore) <= 4) { foreach (var pairModel in words.Randomize()) { Console.WriteLine($"{pairModel.OriginWord}\t\t:{pairModel.Translation}"); } } Console.WriteLine(); Console.WriteLine("Press any key to start an examination"); Console.ReadKey(); Console.Clear(); int examsCount = 0; int examsPassed = 0; DateTime started = DateTime.Now; for (int i = 0; i < 3; i++) { foreach (var pairModel in words.Randomize()) { Console.WriteLine(); IExam exam; exam = ExamSelector.GetNextExamFor(i == 0, pairModel); bool retryFlag = false; do { retryFlag = false; Stopwatch sw = Stopwatch.StartNew(); var questionMetric = new QuestionMetric { AggregateScoreBefore = pairModel.AggregateScore, WordId = pairModel.Id, Created = DateTime.Now, ExamsPassed = pairModel.Examed, PassedScoreBefore = pairModel.PassedScore, PhrasesCount = pairModel.Phrases?.Count ?? 0, PreviousExam = pairModel.LastExam, Type = exam.Name, WordAdded = pairModel.Created }; var result = exam.Pass(service, pairModel, words); sw.Stop(); questionMetric.ElaspedMs = (int)sw.ElapsedMilliseconds; switch (result) { case ExamResult.Impossible: exam = ExamSelector.GetNextExamFor(i == 0, pairModel); retryFlag = true; break; case ExamResult.Passed: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\r\n[PASSED]"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(); questionMetric.Result = 1; service.SaveQuestionMetrics(questionMetric); examsCount++; examsPassed++; break; case ExamResult.Failed: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\n[failed]"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(); questionMetric.Result = 0; service.SaveQuestionMetrics(questionMetric); examsCount++; break; case ExamResult.Retry: retryFlag = true; Console.WriteLine(); Console.WriteLine(); break; case ExamResult.Exit: return; } } while (retryFlag); service.RegistrateExam(started, examsCount, examsPassed); } } Console.WriteLine(); Console.WriteLine($"Test done: {examsPassed}/{examsCount}"); foreach (var pairModel in words) { Console.WriteLine(pairModel.OriginWord + " - " + pairModel.Translation + " (" + pairModel.PassedScore + ")"); } Console.WriteLine(); }
public ExamFlow(Chat chat, NewWordsService service) { _chat = chat; _wordsService = service; }