示例#1
0
        public void ApproveAndMoveNext_NewWordGloss()
        {
#if WANTPORTWFIC // Undo is not working. The part of the test up to Undo works, but leaves extra things on the Undo stack
            // that mess things up when this test is run first (NUnit) though not when run last (Resharper).
            var xfics = AnnotationServices.GetAnalysisOccurrences(m_para0_0).ToList();
            m_interlinDoc.SelectAnnotation(xfics[0]);
            var initialAnalysisTree_wfic0 = m_focusBox.InitialAnalysis;
            var newAnalysisTree_wfic0     = m_focusBox.NewAnalysisTree;
            m_focusBox.DoDuringUnitOfWork = () =>
                                            WordAnalysisOrGlossServices.CreateNewAnalysisTreeGloss(initialAnalysisTree_wfic0.Wordform);
            var undoRedoText = new MockUndoRedoText("Undo", "Redo");
            m_focusBox.ApproveAndMoveNext(undoRedoText);

            // expect change to the first wfic.
            Assert.AreEqual(newAnalysisTree_wfic0.Gloss, xfics[0].Analysis);
            // expect the focus box to be on the next wfic.
            Assert.AreEqual(xfics[1], m_focusBox.SelectedWfic);

            // test undo.
            Assert.AreEqual(1, Cache.ActionHandlerAccessor.UndoableSequenceCount);
            Cache.ActionHandlerAccessor.Undo();
            Assert.AreEqual(initialAnalysisTree_wfic0.Object, xfics[0].Analysis);
            // expect the focus box to be back on the first wfic.
            Assert.AreEqual(xfics[0], m_focusBox.SelectedWfic);
#endif
        }
示例#2
0
        public void ApproveAndStayPut_NewWordGloss()
        {
            var occurrences = SegmentServices.GetAnalysisOccurrences(m_para0_0).ToList();

            m_interlinDoc.SelectOccurrence(occurrences[0]);
            // create a new analysis.
            var initialAnalysisTree = m_focusBox.InitialAnalysis;

            m_focusBox.DoDuringUnitOfWork = () =>
                                            WordAnalysisOrGlossServices.CreateNewAnalysisTreeGloss(initialAnalysisTree.Wordform);
            var undoRedoText = new MockUndoRedoText("Undo", "Redo");

            m_focusBox.ApproveAndStayPut(undoRedoText);

            // expect change to the first occurrence.
            Assert.AreEqual(m_focusBox.NewAnalysisTree.Gloss, occurrences[0].Analysis);
            // expect the focus box to still be on the first occurrence.
            Assert.AreEqual(occurrences[0], m_focusBox.SelectedOccurrence);

            // test undo.
            Assert.AreEqual(1, Cache.ActionHandlerAccessor.UndoableSequenceCount);
            Cache.ActionHandlerAccessor.Undo();
            Assert.AreEqual(initialAnalysisTree.Analysis, occurrences[0].Analysis);
            // expect the focus box to still be on the first occurrence.
            Assert.AreEqual(occurrences[0], m_focusBox.SelectedOccurrence);
        }
示例#3
0
        private IWfiAnalysis SetupAnalysisForEntry(AnalysisOccurrence cba0_0, string gloss, ILexSense lexEntry1_Sense1, out IWfiWordform wf)
        {
            wf = cba0_0.Analysis.Wordform;
            var wag = WordAnalysisOrGlossServices.CreateNewAnalysisTreeGloss(wf);

            wag.WfiAnalysis.CategoryRA = (lexEntry1_Sense1.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA;
            wag.Gloss.Form.set_String(Cache.DefaultAnalWs, gloss);
            return(wag.WfiAnalysis);
        }
示例#4
0
        public void GetActualWs_MorphBundleBehavesLikeMoForm()
        {
            var wsManager = new WritingSystemManager();
            CoreWritingSystemDefinition enWs;

            wsManager.GetOrSet("en", out enWs);
            int wsEng = enWs.Handle;

            CoreWritingSystemDefinition frWs;

            wsManager.GetOrSet("fr", out frWs);
            int wsFrn = frWs.Handle;

            var choices = new InterlinLineChoices(m_lp, wsFrn, wsEng);

            MakeStandardState(choices);
            InterlinLineSpec spec = choices[1];

            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, spec.Flid);
            // The StringFlid for this line spec always corresponds to a MoForm
            Assert.AreEqual(MoFormTags.kflidForm, spec.StringFlid);

            IWfiWordform    wf;
            IWfiAnalysis    wag;
            ITsString       str = TsStringUtils.MakeString("WordForm", spec.WritingSystem);
            IWfiMorphBundle wmb = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create();

            NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                wf  = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(str);
                wag = WordAnalysisOrGlossServices.CreateNewAnalysisWAG(wf);
                wag.MorphBundlesOS.Add(wmb);
                ILexEntry entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
                IMoForm moForm  = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create();
                entry.AlternateFormsOS.Add(moForm);
                moForm.Form.set_String(spec.WritingSystem, "Morph");
                wmb.MorphRA = moForm;
            });
            // The line spec for displaying the Morpheme must be able to handle getting the ws from both
            // MorphBundles or MoForms
            Assert.True(spec.Flid == InterlinLineChoices.kflidMorphemes);
            int wmbWs = spec.GetActualWs(Cache, wmb.Hvo, spec.WritingSystem);
            int mfWs  = spec.GetActualWs(Cache, wmb.MorphRA.Hvo, spec.WritingSystem);

            Assert.True(wmbWs == spec.WritingSystem);
            Assert.True(mfWs == spec.WritingSystem);
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="word"></param>
        /// <param name="analysis">the new analysis Gloss. If multiple glosses, returns the last one created.</param>
        private static void UpgradeToWordGloss(Word word, ref IAnalysis analysis)
        {
            FdoCache cache        = analysis.Cache;
            var      tsStrFactory = cache.ServiceLocator.GetInstance <ITsStrFactory>();
            var      wsFact       = cache.WritingSystemFactory;

            if (s_importOptions.AnalysesLevel == ImportAnalysesLevel.WordGloss)
            {
                // test for adding multiple glosses in the same language. If so, create separate analyses with separate glosses.
                bool fHasMultipleGlossesInSameLanguage = false;
                var  dictMapLangToGloss = new Dictionary <string, string>();
                foreach (var wordGlossItem in word.Items.Select(i => i).Where(i => i.type == "gls"))
                {
                    string gloss;
                    if (!dictMapLangToGloss.TryGetValue(wordGlossItem.lang, out gloss))
                    {
                        dictMapLangToGloss.Add(wordGlossItem.lang, wordGlossItem.Value);
                        continue;
                    }
                    if (wordGlossItem.Value == gloss)
                    {
                        continue;
                    }
                    fHasMultipleGlossesInSameLanguage = true;
                    break;
                }

                AnalysisTree analysisTree = null;
                foreach (var wordGlossItem in word.Items.Select(i => i).Where(i => i.type == "gls"))
                {
                    if (wordGlossItem == null)
                    {
                        continue;
                    }
                    if (wordGlossItem.analysisStatusSpecified &&
                        wordGlossItem.analysisStatus != analysisStatusTypes.humanApproved)
                    {
                        continue;
                    }
                    // first make sure that an existing gloss does not already exist. (i.e. don't add duplicate glosses)
                    int       wsNewGloss  = GetWsEngine(wsFact, wordGlossItem.lang).Handle;
                    ITsString newGlossTss = tsStrFactory.MakeString(wordGlossItem.Value,
                                                                    wsNewGloss);
                    var       wfiWord       = analysis.Wordform;
                    bool      hasGlosses    = wfiWord.AnalysesOC.Any(wfia => wfia.MeaningsOC.Any());
                    IWfiGloss matchingGloss = null;
                    if (hasGlosses)
                    {
                        foreach (var wfa in wfiWord.AnalysesOC)
                        {
                            matchingGloss = wfa.MeaningsOC.FirstOrDefault(wfg => wfg.Form.get_String(wsNewGloss).Equals(newGlossTss));
                            if (matchingGloss != null)
                            {
                                break;
                            }
                        }
                    }

                    if (matchingGloss != null)
                    {
                        analysis = matchingGloss;
                    }
                    else
                    {
                        // TODO: merge with analysis having same morpheme breakdown (or at least the same stem)

                        if (analysisTree == null || dictMapLangToGloss.Count == 1 || fHasMultipleGlossesInSameLanguage)
                        {
                            // create a new WfiAnalysis to store a new gloss
                            analysisTree = WordAnalysisOrGlossServices.CreateNewAnalysisTreeGloss(wfiWord);
                        }
                        else
                        {
                            // reuse the same analysisTree for setting a gloss alternative
                        }
                        analysisTree.Gloss.Form.set_String(wsNewGloss, wordGlossItem.Value);
                        // Make sure this analysis is marked as user-approved (green check mark)
                        cache.LangProject.DefaultUserAgent.SetEvaluation(analysisTree.WfiAnalysis, Opinions.approves);
                        // Create a morpheme form that matches the wordform.
                        var morphemeBundle = cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create();
                        var wordItem       = word.Items.Select(i => i).Where(i => i.type == "txt").First();
                        int wsWord         = GetWsEngine(wsFact, wordItem.lang).Handle;
                        analysisTree.WfiAnalysis.MorphBundlesOS.Add(morphemeBundle);
                        morphemeBundle.Form.set_String(wsWord, wordItem.Value);

                        analysis = analysisTree.Gloss;
                    }
                }
            }
        }