Ejemplo n.º 1
0
        public override async Task <ResultArgs <StudyItemViewModelArgs> > GetNextStudyItemViewModelAsync()
        {
            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            //WE ARE CYCLING THROUGH ALL OF THE MLTS, SO GET NEXT MLT TO STUDY INDEX
            var multiLineTextIndex   = GetNextMultiLineTextIndex();
            var currentMultiLineText = _Target[multiLineTextIndex];
            var studier = _Studiers[currentMultiLineText.Id];

            //WE HAVE ALREADY INITIALIZED EACH STUDIER, SO NOW JUST DELEGATE THE WORK TO THE STUDIER
            return(await studier.GetNextStudyItemViewModelAsync());
        }
Ejemplo n.º 2
0
        public async override Task <ResultArgs <StudyItemViewModelArgs> > GetNextStudyItemViewModelAsync()
        {
            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            UpdateKnowledge();
            ChooseAggregateSize();
            var nextLineNumber = -1;
            var nextStudier    = ChooseNextLineStudier(out nextLineNumber);

            if (nextStudier == null || nextLineNumber < 0)
            {
                throw new Exception("todo: all lines are studied, publish completion event or something");
            }

            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            var nextLineEdit = _Target.Lines[nextLineNumber];

            if (nextLineEdit.LineNumber != nextLineNumber)
            {
                var results = from line in _Target.Lines
                              where line.LineNumber == nextLineNumber
                              select line;

                nextLineEdit = results.FirstOrDefault();
                if (nextLineEdit == null)
                {
                    throw new Exception("cannot find line with corresponding line number");
                }
            }

            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            _LastActiveLineStudiedIndex = nextLineEdit.LineNumber;
            return(await nextStudier.GetNextStudyItemViewModelAsync());
        }
Ejemplo n.º 3
0
        public async override Task <ResultArgs <StudyItemViewModelArgs> > GetNextStudyItemViewModelAsync()
        {
            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            LineEdit lineToStudy = null;

            //IF WE KNOW ALL OF OUR GROUPS, RESET AND START OVER
            if (_KnownGroupNumbers.Count == _LineGroups.Count)
            {
                _PrevGroupNumberStudied = -1;
                _PrevStudyWasHit        = false;
                _KnownGroupNumbers.Clear();
                foreach (var completedGroup in _LineGroups)
                {
                    completedGroup.Reset();
                }
            }

            //GET THE INITIAL GROUP NUMBER TO TRY TO STUDY
            int       groupNumberToStudy = _PrevGroupNumberStudied;
            LineGroup group = null;

            if (_PrevStudyWasHit)
            {
                //PREV STUDY WAS HIT, SO TRY TO STAY WITH THE PREV GROUP.
                group = GetGroupFromGroupNumber(_PrevGroupNumberStudied);

                if (group == null)
                {
                    throw new Exception();//SINCE PREV STUDY WAS HIT, THIS SHOULD NEVER HAPPEN.
                }
                //IF THE GROUP IS NOT YET COMPLETED, GET ITS NEXT LINE, OTHERWISE WE NEED TO TRY THE NEXT GROUP.
                if (!group.Completed)
                {
                    lineToStudy = group.GetLine();
                    if (lineToStudy == null)
                    {
                        throw new Exception();
                    }
                    _PrevGroupNumberStudied = group.GroupNumber;
                }
                else
                {
                    //PREVIOUS GROUP WAS A HIT AND THAT COMPLETED THAT GROUP, SO GET NEXT GROUP
                    int nextGroupNumber = GetNextUnknownGroupNumber();
                    group = GetGroupFromGroupNumber(nextGroupNumber);
                    if (group.Completed)
                    {
                        throw new Exception();
                    }
                    lineToStudy             = group.GetLine();
                    _PrevGroupNumberStudied = group.GroupNumber;
                }
            }
            else
            {
                //PREVIOUS WAS A MISS, SO GET LINE FROM NEXT UNKNOWN GROUP
                int nextGroupNumber = GetNextUnknownGroupNumber();
                group = GetGroupFromGroupNumber(nextGroupNumber);
                if (group.Completed)
                {
                    throw new Exception();
                }
                lineToStudy             = group.GetLine();
                _PrevGroupNumberStudied = group.GroupNumber;
            }

            //groupNumberToStudy = _PrevGroupNumberStudied;
            //if (groupNumberToStudy == _LineGroups.Count)
            //  groupNumberToStudy = 0;

            ////FIND THE FIRST GROUP NUMBER THAT IS UNKNOWN
            //for (int i = 0; i < _LineGroups.Count; i++)
            //{
            //  if (!_KnownGroupNumbers.Contains(groupNumberToStudy))
            //    break;

            //  //THAT GROUP NUMBER IS ALREADY KNOWN.  UPDATE FOR THE NEXT TRY.
            //  groupNumberToStudy++;
            //  if (groupNumberToStudy == _LineGroups.Count)
            //    groupNumberToStudy = 0;
            //}

            ////WE NOW HAVE THE GROUP NUMBER TO STUDY.
            //var group = _LineGroups[groupNumberToStudy];
            //var lineToStudy = group.GetLine();

            //WE NOW HAVE THE LINE TO STUDY.  PROCURE A LINE ORDER
            var result = await StudyItemViewModelFactory.Ton.Procure(lineToStudy, group.MultiLineText);

            var viewModel = result.Object;
            StudyItemViewModelArgs args = new StudyItemViewModelArgs(viewModel);
            var resultArgs = new ResultArgs <StudyItemViewModelArgs>(args);

            var retArgs = await StudyHelper.WrapInTask <ResultArgs <StudyItemViewModelArgs> >(resultArgs);

            return(retArgs);
        }
Ejemplo n.º 4
0
        public override async Task <ResultArgs <StudyItemViewModelArgs> > GetNextStudyItemViewModelAsync()
        {
            #region Abort Check
            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }
            #endregion

            //IF OUR _LASTSTUDIEDINDEX IS MAXED OUT STUDIERS COUNT, THEN WE
            //HAVE COMPLETED ONE ITERATION THROUGH OUR UNKNOWN AGGREGATE PHRASE TEXTS.
            if (_Studiers == null || _LastStudiedIndex >= (_Studiers.Count - 1))
            {
                //NOW WE WILL AGGREGATE OUR ADJACENT KNOWN TEXTS AND REPOPULATE OUR PHRASE STUDIERS
                //WITH ONLY THOSE PHRASES THAT WE DON'T KNOW
                var maxIterations = int.Parse(StudyResources.DefaultMaxIterationsAggregateAdjacentKnownPhraseTexts);
                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion
                AggregateAdjacentKnownPhraseTexts(maxIterations);

                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion
                await PopulateStudiersWithAggregatePhraseTexts();

                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion
                if (_Studiers.Count == 0)
                {
                    //WE KNOW OUR ENTIRE LINE, SO POPULATE STUDIERS WITH A SINGLE PHRASE STUDIER WITH OUR LINE.PHRASE
                    var studier = new DefaultPhraseMeaningStudier();
                    await studier.InitializeForNewStudySessionAsync(_Target.Phrase);

                    _Studiers.Add(0, studier);
                    _LastStudiedIndex = 0;
                    return(await _Studiers[0].GetNextStudyItemViewModelAsync());
                }
                else
                {
                    //WE RETURN OUR FIRST STUDIER FOR THIS NEW STUDY CYCLE
                    return(await _Studiers[0].GetNextStudyItemViewModelAsync());
                }
            }
            else
            {
                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion

                //WE ARE CONTINUING A STUDY CYCLE, SO RUN THE NEXT ONE AND UPDATE OUR LAST STUDIED INDEX.
                var indexToStudy = _LastStudiedIndex + 1;
                _LastStudiedIndex++;
                return(await _Studiers[indexToStudy].GetNextStudyItemViewModelAsync());
            }
        }
Ejemplo n.º 5
0
        public override async Task <ResultArgs <StudyItemViewModelArgs> > GetNextStudyItemViewModelAsync()
        {
            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            //USING THE TARGET PHRASE,
            //IF IT IS IN THE NATIVE LANGUAGE, THEN IT JUST POPS UP A NATIVE LANGUAGE STUDY QUESTION.
            //IF IT IS IN A DIFFERENT LANGUAGE, THEN IT POPS UP EITHER DIRECTION Q & A, 50% CHANCE.
            #region Thinking
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            #endregion
            var retriever = await StudyDataRetriever.CreateNewAsync();

            #region Thinked
            History.Events.ThinkedAboutTargetEvent.Publish(targetId);
            #endregion

            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            var nativeLanguageText = retriever.StudyData.NativeLanguageText;
            if (string.IsNullOrEmpty(nativeLanguageText))
            {
                throw new StudyException("No native language set.");
            }

            if (_Target == null)
            {
                throw new StudyException("No PhraseEdit to study, _StudyJobInfo.Target == null.");
            }

            var phraseEdit = _Target;
            var phraseText = phraseEdit.Text;
            if (string.IsNullOrEmpty(phraseText))
            {
                throw new StudyException("Attempted to study empty phrase text, (PhraseEdit)_Target.Text is null or empty.");
            }

            var languageText = phraseEdit.Language.Text;

            //WE HAVE A PHRASEEDIT WITH A LANGUAGE AND WE HAVE OUR NATIVE LANGUAGE,
            //SO WE HAVE ENOUGH TO PROCURE A VIEW MODEL NOW.
            var result = await StudyItemViewModelFactory.Ton.ProcureAsync(phraseEdit, nativeLanguageText);

            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            var studyItemViewModel = result.Object;
            studyItemViewModel.Shown += new EventHandler(studyItemViewModel_Shown);
            var args       = new StudyItemViewModelArgs(studyItemViewModel);
            var resultArgs = new ResultArgs <StudyItemViewModelArgs>(args);
            _Phrase = phraseEdit;//hack
            return(await StudyHelper.WrapInTask <ResultArgs <StudyItemViewModelArgs> >(resultArgs));
        }