示例#1
0
        public QuestionPackData CreateAlphabetQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            ConfigAI.AppendToTeacherReport("New Question Pack");

            // Fully ordered alphabet, only 1 pack
            var alphabetLetters = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetAllLetters(parameters.letterFilters),
                new SelectionParameters(parameters.correctSeverity, getMaxData: true, useJourney: parameters.useJourneyForCorrect)
                );

            alphabetLetters.Sort((x, y) =>
            {
                return(x.Number - y.Number);
            }
                                 );

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "Letters: " + alphabetLetters.Count;
                foreach (var l in alphabetLetters)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.CreateFromCorrect(null, alphabetLetters));
        }
示例#2
0
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            // Ordered words
            var words = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetWordsByCategory(category, parameters.wordFilters),
                new SelectionParameters(parameters.correctSeverity, getMaxData: true, useJourney: parameters.useJourneyForCorrect)
                );

            // sort by id
            words.Sort((x, y) =>
            {
                return(x.Id.CompareTo(y.Id));
            }
                       );
            if (skipWordZero)
            {
                words.RemoveAt(0);
            }

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "Words: " + words.Count;
                foreach (var w in words)
                {
                    debugString += " " + w;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.CreateFromCorrect(null, words));
        }
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            // First, get all letters (only base letters, tho, due to forced letter filters)
            int nBaseLettersRequired = 1;

            if (letterAlterationFilters.differentBaseLetters)
            {
                nBaseLettersRequired = nCorrect + nWrong;
            }
            var chosenLetters = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetAllLetters(parameters.letterFilters),
                new SelectionParameters(parameters.correctSeverity, nRequired: nBaseLettersRequired, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs)
                );
            var baseLetters = chosenLetters;

            // Then, find all the different variations and add them to a pool
            var letterPool = vocabularyHelper.GetAllLetterAlterations(baseLetters, letterAlterationFilters);

            // Choose randomly from that pool
            var correctAnswers = letterPool.RandomSelect(nCorrect);
            var wrongAnswers   = letterPool;

            foreach (LetterData data in correctAnswers)
            {
                wrongAnswers.Remove(data);
            }

            if (avoidWrongLettersWithSameSound)
            {
                wrongAnswers.RemoveAll(wrongLetter => correctAnswers.Any(correctLetter => correctLetter.PhonemeSound.Equals(wrongLetter.PhonemeSound)));
            }

            wrongAnswers = wrongAnswers.RandomSelect(Mathf.Min(nWrong, wrongAnswers.Count));

            var question = correctAnswers[0];

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nQuestion: " + question;
                debugString += "\nCorrect Answers: " + correctAnswers.Count;
                foreach (var l in correctAnswers)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Answers: " + wrongAnswers.Count;
                foreach (var l in wrongAnswers)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctAnswers, wrongAnswers));
        }
        public List <QuestionPackData> CreateAllQuestionPacks()
        {
            var packs            = new List <QuestionPackData>();
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            var db      = AppManager.I.DB;
            var choice1 = db.GetWordDataById("the_sun");
            var choice2 = db.GetWordDataById("the_moon");

            var wordsWithArticle = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetWordsByArticle(Database.WordDataArticle.Determinative, parameters.wordFilters),
                new SelectionParameters(parameters.correctSeverity, nPacks, useJourney: parameters.useJourneyForCorrect)
                );

            foreach (var wordWithArticle in wordsWithArticle)
            {
                int articleLength      = 2;
                var letterAfterArticle = vocabularyHelper.GetLettersInWord(wordWithArticle)[articleLength];
                var correctWords       = new List <Database.WordData>();
                var wrongWords         = new List <Database.WordData>();

                switch (letterAfterArticle.SunMoon)
                {
                case Database.LetterDataSunMoon.Sun:
                    correctWords.Add(choice1);
                    wrongWords.Add(choice2);
                    break;

                case Database.LetterDataSunMoon.Moon:
                    correctWords.Add(choice2);
                    wrongWords.Add(choice1);
                    break;
                }

                // Debug
                if (ConfigAI.VerboseQuestionPacks)
                {
                    string debugString = "--------- TEACHER: question pack result ---------";
                    debugString += "\nQuestion: " + wordWithArticle;
                    debugString += "\nCorrect Word: " + correctWords.Count;
                    foreach (var l in correctWords)
                    {
                        debugString += " " + l;
                    }
                    debugString += "\nWrong Word: " + wrongWords.Count;
                    foreach (var l in wrongWords)
                    {
                        debugString += " " + l;
                    }
                    ConfigAI.AppendToTeacherReport(debugString);
                }

                var pack = QuestionPackData.Create(wordWithArticle, correctWords, wrongWords);
                packs.Add(pack);
            }

            return(packs);
        }
示例#5
0
        private bool IsSamePack(QuestionPackData pack1, QuestionPackData pack2)
        {
            bool isSame = (pack1.question == null || pack1.question == pack2.question) &&
                          (pack1.questions == null || (pack1.questions[0] == pack2.questions[0])) &&
                          (pack1.correctAnswers == null || (pack1.correctAnswers[0] == pack2.correctAnswers[0]));

            return(isSame);
        }
示例#6
0
        public static QuestionPackData CreateFromWrong <T2>(IConvertibleToLivingLetterData question, List <T2> wrongAnswers)
            where T2 : IConvertibleToLivingLetterData
        {
            QuestionPackData questionPackData = new QuestionPackData();

            questionPackData.question     = question;
            questionPackData.wrongAnswers = wrongAnswers.ConvertAll(x => (IConvertibleToLivingLetterData)x);
            return(questionPackData);
        }
示例#7
0
        public static QuestionPackData CreateFromCorrect <T1>(IConvertibleToLivingLetterData question, List <T1> correctAnswers)
            where T1 : IConvertibleToLivingLetterData
        {
            QuestionPackData questionPackData = new QuestionPackData();

            questionPackData.question       = question;
            questionPackData.correctAnswers = correctAnswers.ConvertAll(x => (IConvertibleToLivingLetterData)x);
            return(questionPackData);
        }
示例#8
0
        public static QuestionPackData Create <T1, T2>(List <T1> questions, List <T2> correctAnswers, List <T2> wrongAnswers)
            where T1 : IConvertibleToLivingLetterData where T2 : IConvertibleToLivingLetterData
        {
            QuestionPackData questionPackData = new QuestionPackData();

            questionPackData.questions      = questions.ConvertAll <IConvertibleToLivingLetterData>(x => (IConvertibleToLivingLetterData)x);
            questionPackData.correctAnswers = correctAnswers.ConvertAll(x => (IConvertibleToLivingLetterData)x);
            questionPackData.wrongAnswers   = wrongAnswers.ConvertAll(x => (IConvertibleToLivingLetterData)x);
            return(questionPackData);
        }
示例#9
0
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            // Get a question phrase at random
            int nToUse           = 1;
            var selectionParams1 = new SelectionParameters(parameters.correctSeverity, nToUse, useJourney: parameters.useJourneyForCorrect,
                                                           packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs);

            selectionParams1.AssignJourney(parameters.insideJourney);
            var usablePhrases = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetPhrasesByCategory(Database.PhraseDataCategory.Question, parameters.wordFilters, parameters.phraseFilters), selectionParams1);
            var question = usablePhrases[0];

            // Get the linked reply phrase
            var reply = vocabularyHelper.GetLinkedPhraseOf(question);

            var correctAnswers = new List <Database.PhraseData>();

            correctAnswers.Add(reply);

            // Get random wrong phrases
            var selectionParams2 = new SelectionParameters(parameters.correctSeverity, nWrong,
                                                           useJourney: parameters.useJourneyForWrong,
                                                           packListHistory: PackListHistory.NoFilter,
                                                           journeyFilter: SelectionParameters.JourneyFilter.CurrentJourney);

            selectionParams2.AssignJourney(parameters.insideJourney);

            var wrongPhrases = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetPhrasesNotIn(parameters.wordFilters, parameters.phraseFilters, question, reply), selectionParams2);

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nQuestion: " + question;
                debugString += "\nCorrect Answers: " + correctAnswers.Count;
                foreach (var l in correctAnswers)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Answers: " + wrongPhrases.Count;
                foreach (var l in wrongPhrases)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctAnswers, wrongPhrases));
        }
示例#10
0
        private QuestionPackData CreateSingleQuestionPackData(LetterData letter, LetterForm correctForm)
        {
            var teacher = AppManager.I.Teacher;

            // Find a word with the letter in that form
            var usableWords = teacher.VocabularyAi.SelectData(
                () => FindEligibleWords(maximumWordLength, letter, correctForm),
                new SelectionParameters(parameters.correctSeverity, 1, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_words)
                );
            var question = usableWords[0];

            // Place the correct letter and form
            var correctAnswers = new List <LetterData>();
            var letterWithForm = AppManager.I.VocabularyHelper.ConvertToLetterWithForcedForm(letter, correctForm);

            correctAnswers.Add(letterWithForm);

            // Place the other forms as wrong forms
            var wrongAnswers = new List <LetterData>();

            foreach (var wrongForm in letter.GetAvailableForms())
            {
                if (wrongForm == correctForm)
                {
                    continue;
                }
                letterWithForm = AppManager.I.VocabularyHelper.ConvertToLetterWithForcedForm(letter, wrongForm);
                wrongAnswers.Add(letterWithForm);
            }

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nQuestion: " + question;
                debugString += "\nCorrect Answers: " + correctAnswers.Count;
                foreach (var l in correctAnswers)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctAnswers, wrongAnswers));
        }
示例#11
0
        private static float getAverageIntrinsicDifficulty(QuestionPackData pack)
        {
            float qDiff = 0;
            float cDiff = 0;

            float qWeight = 0.5f;
            float cWeight = 0.5f;

            if (pack.questions != null && pack.questions.Count > 0)
            {
                foreach (var q in pack.questions)
                {
                    qDiff += ((IVocabularyData)q).GetIntrinsicDifficulty();
                }
                qDiff /= pack.questions.Count;
            }

            if (pack.question != null)
            {
                qDiff += ((IVocabularyData)pack.question).GetIntrinsicDifficulty();
            }
            else
            {
                qWeight = 0;
            }

            if (pack.correctAnswers.Count > 0)
            {
                foreach (var c in pack.correctAnswers)
                {
                    cDiff += ((IVocabularyData)c).GetIntrinsicDifficulty();
                }
                cDiff /= pack.correctAnswers.Count;
            }
            else
            {
                cWeight = 0;
            }

            float diff = (qWeight * qDiff + cWeight * cDiff) / (qWeight + cWeight);

            //UnityEngine.Debug.Log("Pack " + pack.question + " diff: " + diff);
            return(diff);
        }
示例#12
0
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            var selectionParams1 = new SelectionParameters(parameters.correctSeverity, nCorrect,
                                                           useJourney: parameters.useJourneyForCorrect,
                                                           packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs);

            selectionParams1.AssignJourney(parameters.insideJourney);
            var correctLetters = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetAllLetters(parameters.letterFilters), selectionParams1);

            var selectionParams2 = new SelectionParameters(parameters.wrongSeverity, nWrong,
                                                           useJourney: parameters.useJourneyForWrong,
                                                           packListHistory: PackListHistory.NoFilter);

            selectionParams2.AssignJourney(parameters.insideJourney);
            var wrongLetters = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetLettersNotIn(LetterEqualityStrictness.Letter, parameters.letterFilters, correctLetters.ToArray()),
                selectionParams2
                );

            var question = firstCorrectIsQuestion ? correctLetters[0] : null;

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nCorrect Letters: " + correctLetters.Count;
                foreach (var l in correctLetters)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Letters: " + wrongLetters.Count;
                foreach (var l in wrongLetters)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctLetters, wrongLetters));
        }
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            var correctWords = teacher.VocabularyAi.SelectData(
                () => words_cache,
                new SelectionParameters(parameters.correctSeverity, nCorrect, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs)
                );


            wrongWords_cache.Clear();
            wrongWords_cache.AddRange(vocabularyHelper.GetWordsNotInOptimized(parameters.wordFilters, correctWords));
            var wrongWords = teacher.VocabularyAi.SelectData(
                () => wrongWords_cache,
                new SelectionParameters(parameters.wrongSeverity, nWrong, useJourney: parameters.useJourneyForWrong,
                                        packListHistory: PackListHistory.NoFilter,
                                        journeyFilter: SelectionParameters.JourneyFilter.CurrentJourney)
                );

            var question = firstCorrectIsQuestion ? correctWords[0] : null;

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nCorrect Words: " + correctWords.Count;
                foreach (var l in correctWords)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Words: " + wrongWords.Count;
                foreach (var l in wrongWords)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctWords, wrongWords));
        }
示例#14
0
        private QuestionPackData CreateSingleQuestionPackData(WordDataCategory dataCategory)
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            // Ordered words
            var selectionParams1 = new SelectionParameters(parameters.correctSeverity, getMaxData: true,
                                                           useJourney: parameters.useJourneyForCorrect);

            selectionParams1.AssignJourney(parameters.insideJourney);
            parameters.wordFilters.allowedCategories = new[] { dataCategory };
            var words = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetAllWords(parameters.wordFilters),
                selectionParams1
                );

            // sort by id
            words.Sort((x, y) => int.Parse(x.SortValue) - int.Parse(y.SortValue));
            if (skipWordZero)
            {
                words.RemoveAt(0);
            }

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "Words: " + words.Count;
                foreach (var w in words)
                {
                    debugString += " " + w;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            if (maxAnswers > 0)
            {
                words = words.GetRange(0, Mathf.Min(words.Count, maxAnswers));
            }

            return(QuestionPackData.CreateFromCorrect(null, words));
        }
示例#15
0
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            parameters.wordFilters.allowedCategories = null; // Reset forced category

            // Get a phrase
            int nToUse           = 1;
            var selectionParams1 =
                new SelectionParameters(parameters.correctSeverity, nToUse, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs);

            selectionParams1.AssignJourney(parameters.insideJourney);
            var usablePhrases = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetAllPhrases(
                    parameters.wordFilters,
                    parameters.phraseFilters), selectionParams1);
            var question = usablePhrases.RandomSelectOne();

            // Get words related to the phrase
            var             correctWords = new List <WordData>();
            List <WordData> relatedWords = new List <WordData>();

            var phraseWords = vocabularyHelper.GetWordsInPhrase(question, parameters.wordFilters);

            relatedWords.AddRange(phraseWords);

            if (usePhraseAnswersIfFound && question.Answers.Length > 0)
            {
                var answerWords = vocabularyHelper.GetAnswersToPhrase(question, parameters.wordFilters);
                correctWords.AddRange(answerWords);
                relatedWords.AddRange(answerWords);
            }
            else
            {
                correctWords.AddRange(phraseWords);
            }

            // Choose the word/s we want to use
            if (!useAllCorrectWords)
            {
                correctWords = correctWords.RandomSelect(nCorrect);
            }

            // Get wrong words from the same category of the correct one
            parameters.wordFilters.allowedCategories = new[] { correctWords[0].Category };
            var selectionParams2 =
                new SelectionParameters(parameters.correctSeverity, nWrong, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: PackListHistory.NoFilter,
                                        journeyFilter: parameters.JourneyFilter);
            var wrongWords = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetWordsNotIn(parameters.wordFilters, relatedWords.ToArray()),
                selectionParams2
                );

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nQuestion: " + question;
                debugString += "\nCorrect Answers: " + correctWords.Count;
                foreach (var l in correctWords)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Answers: " + wrongWords.Count;
                foreach (var l in wrongWords)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctWords, wrongWords));
        }
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            //Debug.Log(FindLettersThatAppearInWords(maxWordLength: maximumWordLength).ToDebugStringNewline());

            // First, choose a letter (base only, due to filters)
            var eligibleLetters = teacher.VocabularyAi.SelectData(
                () => FindLettersThatAppearInWords(maxWordLength: maximumWordLength),
                new SelectionParameters(parameters.correctSeverity, 1, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_letters)
                );
            //Debug.Log(eligibleLetters.ToDebugStringNewline());

            // Choose one letter randomly from the eligible ones
            var chosenLetter = eligibleLetters.RandomSelectOne();
            //Debug.Log("Chosen: " + chosenLetter);

            // Find a word with the letter (strict)
            var usableWords = teacher.VocabularyAi.SelectData(
                () => FindWordsWithLetterStrict(chosenLetter, maximumWordLength),
                new SelectionParameters(parameters.correctSeverity, 1, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_words)
                );
            var question = usableWords[0];

            // Get the correct form inside the word
            //Debug.Log("Word is: " + question.ToString());
            //Debug.Log("Letters: " + vocabularyHelper.GetLettersInWord(question).ToDebugString());
            //Debug.Log("Letters correct: " + vocabularyHelper.GetLettersInWord(question).Where(l => l.IsSameLetterAs(chosenLetter, LetterEqualityStrictness.LetterOnly)).ToDebugString());
            var chosenLetterWithForm = vocabularyHelper.GetLettersInWord(question).Where(l => l.IsSameLetterAs(chosenLetter, LetterEqualityStrictness.LetterOnly)).ToList().RandomSelectOne();
            //chosenLetterWithForm = vocabularyHelper.ExtractLettersWithForms(chosenLetterWithForm);
            //Debug.Log("Correct form: " + chosenLetterWithForm + " form is " + chosenLetterWithForm.Form);

            // Place the correct alteration in the correct list
            var correctAnswers = new List <LetterData>();

            correctAnswers.Add(chosenLetterWithForm);

            // Place some alterations in the wrong list
            List <LetterData> baseLetters;

            if (letterAlterationFilters.differentBaseLetters)
            {
                baseLetters = AppManager.I.VocabularyHelper.GetAllLetters(parameters.letterFilters);
            }
            else
            {
                baseLetters = eligibleLetters;
            }

            // Filter out unknown letters
            var filteredBaseLetters = teacher.VocabularyAi.SelectData(
                () => baseLetters,
                new SelectionParameters(parameters.wrongSeverity, getMaxData: true, useJourney: true,
                                        packListHistory: PackListHistory.NoFilter)
                );
            //Debug.LogWarning("Filtered bases: " + filteredBaseLetters.ToDebugStringNewline());

            var alterationsPool = AppManager.I.VocabularyHelper.GetAllLetterAlterations(filteredBaseLetters, letterAlterationFilters);
            var wrongAnswers    = new List <LetterData>();

            //Debug.Log("N Alterations before remove correct: " + alterationsPool.Count + " " + alterationsPool.ToDebugString());

            // Remove the correct alteration (making sure to get the actual form)
            for (int i = 0; i < alterationsPool.Count; i++)
            {
                if (alterationsPool[i].IsSameLetterAs(chosenLetterWithForm, LetterEqualityStrictness.WithVisualForm))
                {
                    alterationsPool.RemoveAt(i);
                }
            }

            //Debug.Log("N Alterations after remove correct: " + alterationsPool.Count + " " + alterationsPool.ToDebugString());
            wrongAnswers.AddRange(alterationsPool.RandomSelect(nWrongs));

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nQuestion: " + question;
                debugString += "\nCorrect Answers: " + correctAnswers.Count;
                foreach (var l in correctAnswers)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Answers: " + wrongAnswers.Count;
                foreach (var l in wrongAnswers)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctAnswers, wrongAnswers));
        }
示例#17
0
        private QuestionPackData CreateSingleQuestionPackData(int inRoundPackIndex, HashSet <LetterData> availableLettersWithForms)
        {
            var teacher = AppManager.I.Teacher;

            /*bool useJourneyForLetters = parameters.useJourneyForCorrect;
             * // @note: we also force the journey if the packs must be used together, as the data filters for journey clash with the new filter
             * if (packsUsedTogether)
             * {
             *  useJourneyForLetters = false;
             * }*/

            int SAFE_COUNT = 0;

            while (true)
            {
                var commonLetter = availableLettersWithForms.ToList().RandomSelectOne();

                var correctLetters = new List <LetterData>();
                correctLetters.Add(commonLetter);
                availableLettersWithForms.Remove(commonLetter);
                currentRound_letters.Add(commonLetter);
                //Debug.Log(availableLettersWithForms.ToDebugStringNewline());

                // Find words with that letter
                // Check if it has enough words
                var selectionParams2 =
                    new SelectionParameters(SelectionSeverity.AllRequired, nCorrect,
                                            useJourney: parameters.useJourneyForCorrect,
                                            packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_words);
                selectionParams2.AssignJourney(parameters.insideJourney);
                List <WordData> wordsWithCommonLetter = null;
                try {
                    wordsWithCommonLetter = teacher.VocabularyAi.SelectData(
                        () => FindWordsWithCommonLetter(commonLetter), selectionParams2);
                } catch (Exception) {
                    //Debug.LogWarning(e);
                    SAFE_COUNT++;
                    if (SAFE_COUNT == 100)
                    {
                        throw new Exception("Could not find enough data for WordsWithLetter");
                    }
                    continue;
                }
                var correctWords = wordsWithCommonLetter;
                currentRound_words.AddRange(correctWords);

                // Get words without the letter (only for the first pack of a round)
                var wrongWords = new List <WordData>();
                if (inRoundPackIndex == 0)
                {
                    var selectionParams3 =
                        new SelectionParameters(parameters.wrongSeverity, nWrong,
                                                useJourney: parameters.useJourneyForWrong,
                                                packListHistory: PackListHistory.NoFilter,
                                                journeyFilter: parameters.JourneyFilter);
                    selectionParams3.AssignJourney(parameters.insideJourney);

                    wrongWords = teacher.VocabularyAi.SelectData(
                        () => FindWrongWords(correctWords), selectionParams3);
                    currentRound_words.AddRange(wrongWords);
                }


                /*
                 * // Get a letter
                 * var usableLetters = teacher.VocabularyAi.SelectData(
                 * () => FindLettersThatAppearInWords(atLeastNWords: nCorrect),
                 * new SelectionParameters(parameters.correctSeverity, 1, useJourney: useJourneyForLetters,
                 *      packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_letters));
                 * var commonLetter = usableLetters[0];
                 * currentRound_letters.Add(commonLetter);
                 */
                /*
                 *  // Get words with the letter
                 *  // (but without the previous letters)
                 *  var correctWords = teacher.VocabularyAi.SelectData(
                 *      () => FindWordsWithCommonLetter(commonLetter),
                 *      new SelectionParameters(parameters.correctSeverity, nCorrect,
                 *          useJourney: parameters.useJourneyForCorrect,
                 *          packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_words));
                 *  currentRound_words.AddRange(correctWords);
                 *
                 *  // Get words without the letter (only for the first pack of a round)
                 *  var wrongWords = new List<WordData>();
                 *  if (inRoundPackIndex == 0)
                 *  {
                 *      wrongWords = teacher.VocabularyAi.SelectData(
                 *          () => FindWrongWords(correctWords),
                 *          new SelectionParameters(parameters.wrongSeverity, nWrong,
                 *              useJourney: parameters.useJourneyForWrong,
                 *              packListHistory: PackListHistory.NoFilter,
                 *              journeyFilter: SelectionParameters.JourneyFilter.CurrentJourney));
                 *      currentRound_words.AddRange(wrongWords);
                 *  }
                 */
                var pack = QuestionPackData.Create(commonLetter, correctWords, wrongWords);

                if (ConfigAI.VerboseQuestionPacks)
                {
                    string debugString = "--------- TEACHER: question pack result ---------";
                    debugString += "\nQuestion: " + commonLetter;
                    debugString += "\nCorrect Answers: " + correctWords.Count;
                    foreach (var l in correctWords)
                    {
                        debugString += " " + l;
                    }
                    debugString += "\nWrong Answers: " + wrongWords.Count;
                    foreach (var l in wrongWords)
                    {
                        debugString += " " + l;
                    }
                    ConfigAI.AppendToTeacherReport(debugString);
                }

                return(pack);
            }
        }
示例#18
0
        private QuestionPackData CreateSingleQuestionPackData(int inRoundPackIndex)
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            // Choose a single eligible word
            var usableWords = teacher.VocabularyAi.SelectData(
                () => FindEligibleWords(maxWordLength: maximumWordLength),
                new SelectionParameters(parameters.correctSeverity, 1, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_words)
                );
            var wordQuestion = usableWords[0];

            currentRound_words.Add(wordQuestion);
            //UnityEngine.Debug.LogWarning("Chosen word: " + question);

            // Get letters of that word
            var wordLetters = vocabularyHelper.GetLettersInWord(wordQuestion);
            //UnityEngine.Debug.LogWarning("Found letters: " + wordLetters.ToArray().ToDebugString());

            bool useJourneyForLetters = parameters.useJourneyForCorrect;

            // @note: we force journey in this case to be off so that all letters can be found
            // @note: we also force the journey if the packs must be used together, as the data filters for journey clash with the new filter
            if (useAllCorrectLetters || packsUsedTogether)
            {
                useJourneyForLetters = false;
            }

            // Get some letters (from that word)
            var correctLetters = teacher.VocabularyAi.SelectData(
                () => FindCorrectLetters(wordQuestion, wordLetters),
                new SelectionParameters(parameters.correctSeverity, nCorrect, getMaxData: useAllCorrectLetters,
                                        useJourney: useJourneyForLetters, filteringIds: previousPacksIDs_letters));

            currentRound_letters.AddRange(correctLetters);

            // Get some wrong letters (not from that word, nor other words, nor previous letters)
            // Only for the first pack of the round
            var wrongLetters = new List <LetterData>();

            if (inRoundPackIndex == 0)
            {
                wrongLetters = teacher.VocabularyAi.SelectData(
                    () => FindWrongLetters(wordQuestion, wordLetters),
                    new SelectionParameters(
                        parameters.wrongSeverity, nWrong, useJourney: parameters.useJourneyForWrong,
                        journeyFilter: SelectionParameters.JourneyFilter.CurrentJourney));
                currentRound_letters.AddRange(wrongLetters);
            }

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nQuestion: " + wordQuestion;
                debugString += "\nCorrect Answers: " + correctLetters.Count;
                foreach (var l in correctLetters)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Answers: " + wrongLetters.Count;
                foreach (var l in wrongLetters)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(wordQuestion, correctLetters, wrongLetters));
        }
        private QuestionPackData CreateSingleQuestionPackData(HashSet <LetterData> availableLettersWithForms)
        {
            QuestionPackData pack = null;
            var teacher           = AppManager.I.Teacher;

            int SAFE_COUNT = 0;

            while (true)
            {
                var commonLetter = availableLettersWithForms.ToList().RandomSelectOne();

                var correctLetters = new List <LetterData>();
                correctLetters.Add(commonLetter);
                availableLettersWithForms.Remove(commonLetter);
                //Debug.Log("Test " + SAFE_COUNT + ": Trying letter " + commonLetter);

                // Check if it has enough words
                List <WordData> wordsWithCommonLetter = null;
                try {
                    wordsWithCommonLetter = teacher.VocabularyAi.SelectData(
                        () => FindWordsWithCommonLetter(commonLetter),
                        new SelectionParameters(SelectionSeverity.AllRequired, nWords,
                                                useJourney: parameters.useJourneyForCorrect,
                                                packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_words));
                } catch (Exception) {
                    SAFE_COUNT++;
                    if (SAFE_COUNT == 100)
                    {
                        throw new Exception("Could not find enough data for CommonLettersInWord");
                    }
                    continue;
                }
                //Debug.Log("Found letter " + commonLetter + " at trial count: " + SAFE_COUNT);

                var lettersNotInCommon = teacher.VocabularyAi.SelectData(
                    () => FindLettersNotInCommon(wordsWithCommonLetter),
                    new SelectionParameters(parameters.wrongSeverity, nWrong, useJourney: parameters.useJourneyForWrong,
                                            journeyFilter: SelectionParameters.JourneyFilter.CurrentJourney,
                                            getMaxData: true                  // needed to skip priority filtering, which will filter out forms!
                                            ));
                lettersNotInCommon = lettersNotInCommon.RandomSelect(nWrong); // needed to skip priority filtering, which will filter out forms!

                pack = QuestionPackData.Create(wordsWithCommonLetter, correctLetters, lettersNotInCommon);

                if (ConfigAI.VerboseQuestionPacks)
                {
                    string debugString = "--------- TEACHER: question pack result ---------";
                    debugString += "\nQuestion: " + wordsWithCommonLetter.ToDebugString();
                    debugString += "\nCorrect Answers: " + correctLetters.Count;
                    foreach (var l in correctLetters)
                    {
                        debugString += " " + l;
                    }
                    debugString += "\nWrong Answers: " + lettersNotInCommon.Count;
                    foreach (var l in lettersNotInCommon)
                    {
                        debugString += " " + l;
                    }
                    ConfigAI.AppendToTeacherReport(debugString);
                }
                return(pack);
            }
        }
示例#20
0
        private QuestionPackData CreateSingleQuestionPackData()
        {
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            // Get a phrase
            int nToUse        = 1;
            var usablePhrases = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetAllPhrases(
                    parameters.wordFilters,
                    parameters.phraseFilters),
                new SelectionParameters(parameters.correctSeverity, nToUse, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs)
                );
            var question = usablePhrases[0];

            // Get words related to the phrase
            var             correctWords = new List <WordData>();
            List <WordData> relatedWords = null;

            if (usePhraseAnswersIfFound && question.Answers.Length > 0)
            {
                relatedWords = vocabularyHelper.GetAnswersToPhrase(question, parameters.wordFilters);
            }
            else
            {
                relatedWords = vocabularyHelper.GetWordsInPhrase(question, parameters.wordFilters);
            }

            correctWords.AddRange(relatedWords);

            if (!useAllCorrectWords)
            {
                correctWords = correctWords.RandomSelect(nCorrect);
            }

            var wrongWords = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetWordsNotIn(parameters.wordFilters, relatedWords.ToArray()),
                new SelectionParameters(parameters.correctSeverity, nWrong, useJourney: parameters.useJourneyForCorrect,
                                        packListHistory: PackListHistory.NoFilter,
                                        journeyFilter: SelectionParameters.JourneyFilter.CurrentJourney)
                );

            if (ConfigAI.VerboseQuestionPacks)
            {
                string debugString = "--------- TEACHER: question pack result ---------";
                debugString += "\nQuestion: " + question;
                debugString += "\nCorrect Answers: " + correctWords.Count;
                foreach (var l in correctWords)
                {
                    debugString += " " + l;
                }
                debugString += "\nWrong Answers: " + wrongWords.Count;
                foreach (var l in wrongWords)
                {
                    debugString += " " + l;
                }
                ConfigAI.AppendToTeacherReport(debugString);
            }

            return(QuestionPackData.Create(question, correctWords, wrongWords));
        }
        public List <QuestionPackData> CreateAllQuestionPacks()
        {
            var packs            = new List <QuestionPackData>();
            var teacher          = AppManager.I.Teacher;
            var vocabularyHelper = AppManager.I.VocabularyHelper;

            var db      = AppManager.I.DB;
            var choice1 = db.GetWordDataById("with_article");
            var choice2 = db.GetWordDataById("without_article");

            int nPerType = nPacks / 2;

            var list_choice1 = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetWordsByArticle(Database.WordDataArticle.Determinative, parameters.wordFilters),
                new SelectionParameters(parameters.correctSeverity, nPerType, useJourney: parameters.useJourneyForCorrect)
                );

            var list_choice2 = teacher.VocabularyAi.SelectData(
                () => vocabularyHelper.GetWordsByArticle(Database.WordDataArticle.None, parameters.wordFilters),
                new SelectionParameters(parameters.wrongSeverity, nPerType, useJourney: parameters.useJourneyForCorrect)
                );

            foreach (var wordWithArticle in list_choice1)
            {
                var correctWords = new List <Database.WordData>();
                var wrongWords   = new List <Database.WordData>();
                correctWords.Add(choice1);
                wrongWords.Add(choice2);

                var pack = QuestionPackData.Create(wordWithArticle, correctWords, wrongWords);
                packs.Add(pack);
            }

            foreach (var wordWithoutArticle in list_choice2)
            {
                var correctWords = new List <Database.WordData>();
                var wrongWords   = new List <Database.WordData>();
                correctWords.Add(choice2);
                wrongWords.Add(choice1);

                var pack = QuestionPackData.Create(wordWithoutArticle, correctWords, wrongWords);
                packs.Add(pack);
            }

            // Shuffle the packs at the end
            packs.Shuffle();

            if (ConfigAI.VerboseQuestionPacks)
            {
                foreach (var pack in packs)
                {
                    string debugString = "--------- TEACHER: question pack result ---------";
                    debugString += "\nQuestion: " + pack.question;
                    debugString += "\nCorrect Word: " + pack.correctAnswers.Count;
                    foreach (var l in pack.correctAnswers)
                    {
                        debugString += " " + l;
                    }
                    debugString += "\nWrong Word: " + pack.wrongAnswers.Count;
                    foreach (var l in pack.wrongAnswers)
                    {
                        debugString += " " + l;
                    }
                    ConfigAI.AppendToTeacherReport(debugString);
                }
            }

            return(packs);
        }