Esempio n. 1
0
        public WordsPair GetRandomWordsPair(List <WordsPair> list)
        {
            int       testPairNumber = rnd.Next(0, list.Count);
            WordsPair pair           = list.ElementAt(testPairNumber);

            return(pair);
        }
Esempio n. 2
0
        private bool GetNextWordsPair()
        {
            currPair = GetWordPairVisit(mContr);
            if (currPair == null)
            {
                if (timer != null)
                {
                    timer.Stop();
                    timer.Dispose();
                }
                return(false);
            }
            string question = currPair.Original;

            questionTextBox.Text = question;
            questionTextBox.SelectAll();
            questionTextBox.SelectionAlignment = HorizontalAlignment.Center;
            questionTextBox.DeselectAll();
            if (!MuteQuestion)
            {
                mContr.SpeakThis(question);
            }
            rightAnswer = currPair.Translation;
            return(true);
        }
Esempio n. 3
0
        private WordsPair MovePairFromOneBuffeToOther(List <WordsPair> bufSrc, List <WordsPair> bufDest)
        {
            WordsPair pair = bufSrc.ElementAt(rnd.Next(bufSrc.Count));

            bufSrc.Remove(pair);
            bufDest.Add(pair);
            return(pair);
        }
Esempio n. 4
0
        public WordsPair GetNextWord()
        {
            WordsPair pair = MovePairFromOneBuffeToOther(words, tempWords);

            if (words.Count == 0)
            {
                Reload();
                round = true;
            }
            return(pair);
        }
Esempio n. 5
0
        public bool PlayOnePair(WordsPair pair, ICheckIsExit checkIsExit, out bool isExit)
        {
            isExit = false;

            _speaker.Speak($"{pair.First} = {pair.Second}");
            _speaker.Speak($"{pair.Second} = {pair.First}");
            var input = _listener.Input();

            if (checkIsExit.IsExit(input))
            {
                isExit = true;
                return(true);
            }
            return(true);
        }
Esempio n. 6
0
 private void NextPairsForSentenceButton_Click(object sender, EventArgs e)
 {
     if (!learningService.RoundFinish)
     {
         WordsPair pair1 = learningService.GetNextWord();
         WordsPair pair2 = learningService.GetNextWord();
         GetFirstPhraseLabel().Text  = pair1.Translation;
         GetSecondPhraseLabel().Text = pair2.Translation;
         GetToolTip().SetToolTip(GetFirstPhraseLabel(), pair1.Original);
         GetToolTip().SetToolTip(GetSecondPhraseLabel(), pair2.Original);
     }
     else
     {
         StartWrittenPart();
     }
 }
Esempio n. 7
0
        public bool PlayOnePair(WordsPair pair, ICheckIsExit checkIsExit, out bool isExit)
        {
            var result = true;

            isExit = false;

            _speaker.Speak($"{pair.Second} = {pair.First}");
            _speaker.Speak("Введите слово:");
            var first = _listener.Input();

            if (checkIsExit.IsExit(first))
            {
                isExit = true;
                return(result);
            }

            if (first == pair.First.Caption)
            {
                _speaker.Speak("Ok!");
                result = true;
            }
            else
            {
                _speaker.Speak($"No. Правильно будет \"{pair.First}\"");
                result = false;
            }
            _speaker.Speak("");
            return(result);

            //_speaker.Speak("Введите второе слово:");
            //var second = _listener.Input();
            //if (checkIsExit.IsExit(second))
            //{
            //    isExit = true;
            //    return;
            //}
            //if (second == pair.Second.Caption)
            //    _speaker.Speak("Ok!");
            //else
            //    _speaker.Speak($"No. Правильно {pair.Second}");
        }
Esempio n. 8
0
        public QuizWithAnswers GetNewChooseAnswerQuiz()
        {
            WordsPair testPair    = GetAnyRandomWordsPair();
            string    question    = testPair.Original;
            string    rightAnswer = testPair.Translation;

            string[] wrongs = new string[3];
            for (int i = 0; i < 3; i++)
            {
                WordsPair wrongPair;
                do
                {
                    wrongPair = GetAnyRandomWordsPair();
                } while (wrongPair.Equals(testPair));

                wrongs[i] = wrongPair.Translation;
            }
            QuizWithAnswers quiz = new QuizWithAnswers(question, rightAnswer, wrongs[0], wrongs[1], wrongs[2]);

            return(quiz);
        }
Esempio n. 9
0
 private void ShowNextWordButton_Click(object sender, EventArgs e)
 {
     if (!learningService.RoundFinish)
     {
         WordsPair pair = learningService.GetNextWord();
         GetQuestioLabel().Text = pair.Translation;
         TextHorizontalAlignmentCenter(GetQuestioLabel());
         GetAnswerLabel().Text = pair.Original;
         TextHorizontalAlignmentCenter(GetAnswerLabel());
         if (!MuteQuestion)
         {
             mContr.SpeakThis(pair.Translation);
         }
         return;
     }
     else
     {
         StartMakeSentencePart();
         NextPairsForSentenceButton_Click(null, null);
     }
 }
Esempio n. 10
0
 public WordPairViewModel(WordsPair wordPair)
 {
     _wordPair = wordPair;
 }
Esempio n. 11
0
 public Word GetQuestion(WordsPair pair)
 {
     return(pair.First);
 }
Esempio n. 12
0
 public Word GetTranslate(WordsPair pair)
 {
     return(pair.Second);
 }
Esempio n. 13
0
        private void readCsv()
        {
            checkEmptyFields();
            using (TextFieldParser csvParser = new TextFieldParser(path, Encoding.Default))
            {
                Dictionary <string, WordsPair> directTranslation = new Dictionary <string, WordsPair>();
                Dictionary <string, WordsPair> reversTranslation = new Dictionary <string, WordsPair>();;
                // set up parser
                csvParser.CommentTokens = new string[] { "#" };
                csvParser.SetDelimiters(new string[] { "," });
                csvParser.HasFieldsEnclosedInQuotes = true;
                csvParser.TrimWhiteSpace            = true;
                // read first row
                string[] fields = csvParser.ReadFields();

                EnglishDetector enDetector = new EnglishDetector(); // Detector for determining where English is.
                LanguageDictionary.EnglishIs englishIs;
                string from       = fields[0];
                string to         = fields[1];
                string firstWord  = fields[2];
                string secondWord = fields[3];
                bool   studied    = false;
                try
                {
                    englishIs = enDetector.isTheDirectionEnglish(to)
                        ? LanguageDictionary.EnglishIs.TO
                        : (enDetector.isTheDirectionEnglish(from)
                        ? LanguageDictionary.EnglishIs.FROM
                        : LanguageDictionary.EnglishIs.NEITHER);
                }
                catch (System.Exception)
                {
                    englishIs = LanguageDictionary.EnglishIs.NEITHER;
                    Logger.Error("Fail when detector trying to determine english language.");
                    throw new IOException("No internet connection.");
                }
                if (englishIs.Equals(LanguageDictionary.EnglishIs.NEITHER))
                {
                    throw new IOException("No english at first row.");
                }
                if (fields.Length == 5)
                {
                    studied = fields[4].Equals("1");
                }
                // initiate dictionary with first row
                directTranslation.Add(fields[2], new WordsPair(firstWord, secondWord, studied));
                reversTranslation.Add(fields[3], new WordsPair(secondWord, firstWord, studied));
                // let's process other rows
                while (!csvParser.EndOfData)
                {
                    // Read current line fields, pointer moves to the next line.
                    fields     = csvParser.ReadFields();
                    firstWord  = fields[2];
                    secondWord = fields[3];
                    studied    = false;
                    if (fields.Length == 5)
                    {
                        studied = fields[4].Equals("1");
                    }

                    if (fields[0].Equals(from))
                    {
                        // if key exist then concatenates second meaning to translation
                        if (directTranslation.ContainsKey(firstWord))
                        {
                            directTranslation[firstWord] = new WordsPair(firstWord, $"{directTranslation[firstWord].Translation}; {secondWord}", studied);
                        }
                        else
                        {
                            directTranslation.Add(firstWord, new WordsPair(firstWord, secondWord, studied));
                        }

                        if (reversTranslation.ContainsKey(secondWord))
                        {
                            reversTranslation[secondWord] = new WordsPair(secondWord, $"{reversTranslation[secondWord].Translation}; {firstWord}", studied);
                        }
                        else
                        {
                            reversTranslation.Add(secondWord, new WordsPair(secondWord, firstWord, studied));
                        }
                    }
                    else if (fields[0].Equals(to))
                    {
                        if (reversTranslation.ContainsKey(firstWord))
                        {
                            reversTranslation[firstWord] = new WordsPair(firstWord, $"{reversTranslation[firstWord].Translation}; {secondWord}", studied);
                        }
                        else
                        {
                            reversTranslation.Add(firstWord, new WordsPair(firstWord, secondWord, studied));
                        }

                        if (directTranslation.ContainsKey(secondWord))
                        {
                            directTranslation[secondWord] = new WordsPair(secondWord, $"{directTranslation[secondWord].Translation}; {firstWord}", studied);
                        }
                        else
                        {
                            directTranslation.Add(secondWord, new WordsPair(secondWord, firstWord, studied));
                        }
                    }
                    else
                    {
                        Logger.Info("Too many languages. Skipping this row: {0}, {1}, {2}, {3}", fields[0], fields[1], fields[2], fields[3]);
                    }
                }

                LanguageDictionary directTranslationLanguageDictionary = new LanguageDictionary(from, to, englishIs);
                LanguageDictionary reversTranslationLanguageDictionary = new LanguageDictionary(to, from,
                                                                                                englishIs.Equals(LanguageDictionary.EnglishIs.TO) ? LanguageDictionary.EnglishIs.FROM : LanguageDictionary.EnglishIs.TO);
                foreach (WordsPair wPair in directTranslation.Values)
                {
                    directTranslationLanguageDictionary.Add(wPair);
                }
                foreach (WordsPair wPair in reversTranslation.Values)
                {
                    reversTranslationLanguageDictionary.Add(wPair);
                }
                Vocabularies.Add(directTranslationLanguageDictionary);
                Vocabularies.Add(reversTranslationLanguageDictionary);

                // TODO: Delete below
                Console.WriteLine($"{directTranslationLanguageDictionary} {directTranslation.Count}");
                Console.WriteLine($"{reversTranslationLanguageDictionary} {reversTranslation.Count}");
            }
        }
Esempio n. 14
0
 public Word GetQuestion(WordsPair pair)
 {
     return(pair.Second);
 }
Esempio n. 15
0
 public Word GetTranslate(WordsPair pair)
 {
     return(pair.First);
 }