Exemplo n.º 1
0
        public void PickLexGlossUsingExistingAnalysis()
        {
            var cba0_0 = GetNewAnalysisOccurence(m_text1, 0, 0, 0);

            m_sandbox.SwitchWord(cba0_0);
            ILexEntry    lexEntry1_Entry;
            ILexSense    lexEntry1_Sense1;
            ILexEntry    lexEntry2_Entry;
            ILexSense    lexEntry2_Sense1;
            IWfiWordform wf;

            SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1);
            SetupLexEntryAndSense("xxxa", "xxxa.AlternativeGloss", out lexEntry2_Entry, out lexEntry2_Sense1);
            // setup an existing analysis and gloss to match existing entry
            var morphBundle1 = SetupMorphBundleForEntry(cba0_0, "0.0.xxxa", lexEntry1_Entry, lexEntry1_Sense1, out wf);
            var morphBundle2 = SetupMorphBundleForEntry(cba0_0, "xxxa.AlternativeGloss", lexEntry2_Entry, lexEntry2_Sense1, out wf);

            // load sandbox with a guess.
            m_sandbox.SwitchWord(cba0_0);
#if WANTTESTPORT
            Assert.IsTrue(m_sandbox.UsingGuess);
#endif

            // mark the count of LexEntries
            int cEntriesOrig = Cache.LangProject.LexDbOA.Entries.Count();

            // first select 'unknown' to clear the guess for the word gloss/pos
            m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, "Unknown");
            // confirm Sandbox is in the expected state.
            ITsString tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                                        Cache.DefaultAnalWs);
            Assert.AreEqual(null, tssWordGlossInSandbox.Text);
            int hvoPos = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
            Assert.AreEqual(0, hvoPos);

            // simulate selecting a lex gloss '0.0.xxxa'
            m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, lexEntry1_Sense1.Hvo);
            // confirm Sandbox is in the expected state.
            tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                              Cache.DefaultAnalWs);
            Assert.AreEqual("0.0.xxxa", tssWordGlossInSandbox.Text);
            int hvoPos2 = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
            Assert.AreNotEqual(0, hvoPos2);

            // simulate selecting the other lex gloss 'xxxa.AlternativeGloss'
            m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, lexEntry2_Sense1.Hvo);
            // confirm Sandbox is in the expected state.
            tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                              Cache.DefaultAnalWs);
            Assert.AreEqual("xxxa.AlternativeGloss", tssWordGlossInSandbox.Text);
            int hvoPos3 = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
            Assert.AreNotEqual(0, hvoPos3);

            // Next simulate picking an existing word gloss/pos by typing/selecting
            tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss,
                                                              Cache.DefaultAnalWs, "0.0.xxxa");
            // set word pos, to first possibility (e.g. 'adjunct')
            int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

            // confirm the analysis (using existing analysis and a LexSense)
            var       wag      = m_sandbox.ConfirmAnalysis();
            IWfiGloss wfiGloss = wag.Gloss;

            // make sure we didn't add entries or senses to the Lexicon.
            int cEntriesAfter = Cache.LangProject.LexDbOA.Entries.Count();
            Assert.AreEqual(cEntriesOrig, cEntriesAfter);
            Assert.AreEqual(1, lexEntry1_Entry.SensesOS.Count);

            // make sure the sense matches the existing one.
            ILexSense sense = m_sandbox.GetLexSenseForWord();
            Assert.AreEqual(lexEntry1_Sense1.Hvo, sense.Hvo);
            // make sure the strings of the wfi gloss matches the strings of the lex gloss.
            ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos);

            // confirm we have not created a new analysis and that it is monomorphemic
            IWfiAnalysis wfiAnalysis = wag.WfiAnalysis;
            Assert.AreEqual(wf, wag.Wordform, "Expected confirmed analysis to be owned by the original wordform.");
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRA.Hvo);
            Assert.AreEqual(2, wf.AnalysesOC.Count);
            Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);
            IWfiAnalysis wfiAnalysis2 = (morphBundle2 as IWfiMorphBundle).Owner as IWfiAnalysis;
            Assert.AreEqual(1, wfiAnalysis2.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis2.MeaningsOC.Count);

            // make sure the morph is linked to our lexicon sense, msa, and part of speech.
            IWfiMorphBundle wfiMorphBundle = wfiAnalysis.MorphBundlesOS[0];
            Assert.AreEqual(morphBundle1.Hvo, wfiMorphBundle.Hvo);
        }