Пример #1
0
        private WfiAnalysis Make2BundleAnalysis(string form1, string form2, string gloss1, string gloss2)
        {
            WfiAnalysis result;
            ILexEntry   entry1 = MakeEntry(form1, gloss1);
            ILexEntry   entry2 = MakeEntry(form2, gloss2);

            result = new WfiAnalysis();
            m_wfAxx.AnalysesOC.Add(result);
            IWfiMorphBundle bundle = result.MorphBundlesOS.Append(new WfiMorphBundle());

            bundle.MorphRA = entry1.LexemeFormOA;
            bundle.SenseRA = entry1.SensesOS[0];
            bundle         = result.MorphBundlesOS.Append(new WfiMorphBundle());
            bundle.MorphRA = entry2.LexemeFormOA;
            bundle.SenseRA = entry2.SensesOS[0];

            WfiGloss gloss = new WfiGloss();

            result.MeaningsOC.Add(gloss);
            gloss.Form.AnalysisDefaultWritingSystem = gloss1 + "." + gloss2;
            result.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves);

            m_cAnalyses++;

            return(result);
        }
Пример #2
0
        public void NewGlossExistingLexEntryAllomorphNewLexSense()
        {
            int hvoCba0_0 = GetCbaHvo(0, 0, 0);

            m_sandbox.SwitchWord(hvoCba0_0, false);
            string    formLexEntry     = "xxxab";
            ITsString tssLexEntryForm  = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
            string    formAllomorph    = "xxxa";
            ITsString tssAllomorphForm = StringUtils.MakeTss(formAllomorph, Cache.DefaultVernWs);

            // first create an entry with a matching allomorph that doesn't match 'verb' POS we will be selecting in the sandbox
            ILexEntry lexEntry_NounPos;
            ILexSense lexSense_NounPos;

            SetupLexEntryAndSense("xxxab", "0.0.xxxab_NounPos", "noun", out lexEntry_NounPos, out lexSense_NounPos);
            IMoStemAllomorph allomorph0 = lexEntry_NounPos.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph;

            allomorph0.Form.SetAlternativeTss(tssAllomorphForm);

            // now create the entry we want to match, that has a 'verb' POS.
            ILexEntry lexEntry1_Entry;
            ILexSense lexEntry1_Sense1;

            SetupLexEntryAndSense("xxxab", "0.0.xxxab_VerbPos", "verb", out lexEntry1_Entry, out lexEntry1_Sense1);
            IMoStemAllomorph allomorph = lexEntry1_Entry.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph;

            allomorph.Form.SetAlternativeTss(tssAllomorphForm);

            // mark the count of LexEntries
            int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

            // add a new word gloss
            ITsString   tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
            int         hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
            WfiWordform wf    = new WfiWordform(Cache, hvoWf);
            // set word pos to verb
            int hvoSbWordPos = m_sandbox.GetComboItemHvo(InterlinLineChoices.kflidWordPos, 0, "transitive verb");

            m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordPos, 0, hvoSbWordPos);

            // confirm the analysis (making a real analysis and a LexSense)
            int      hvoGloss = m_sandbox.ConfirmAnalysis();
            WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

            // make sure we didn't add entries to the Lexicon.
            int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;

            Assert.AreEqual(cEntriesOrig, cEntriesAfter);

            // confirm we have only one analysis and that it is monomorphemic
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
            Assert.AreEqual(1, wf.AnalysesOC.Count);
            Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

            // make sure the strings of the wfi gloss matches the strings of the lex gloss.
            ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos, true, allomorph);
        }
Пример #3
0
        private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph)
        {
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            CompareTss(sense.Gloss.GetAlternativeTss(Cache.DefaultAnalWs),
                       wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));

            // make sure the morph is linked to the lexicon sense, msa, and part of speech.
            IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0];

            Assert.AreEqual(sense.Hvo, morphBundle.SenseRAHvo);
            Assert.AreEqual(sense.MorphoSyntaxAnalysisRAHvo, morphBundle.MsaRAHvo);
            if (!fMatchMainPossibility)
            {
                // expect exact possibility
                Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo);
            }
            else
            {
                IPartOfSpeech posTarget = PartOfSpeech.CreateFromDBObject(Cache, hvoSbWordPos);
                Assert.AreEqual(posTarget.MainPossibility.Hvo, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA.MainPossibility.Hvo);
            }
            Assert.AreEqual(allomorph.Hvo, morphBundle.MorphRAHvo);
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo);
        }
Пример #4
0
        public void NewGlossNewLexEntryNewLexSense()
        {
            // load sandbox for first 'xxxa'
            int hvoCba0_0 = GetCbaHvo(0, 0, 0);

            m_sandbox.SwitchWord(hvoCba0_0, false);

            // verify that the word gloss is empty
            ITsString tssEmpty     = StringUtils.MakeTss("", Cache.DefaultAnalWs);
            ITsString tssWordGloss = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs);

            CompareTss(tssEmpty, tssWordGloss);
            // add a new word gloss and confirm the analysis.
            ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
            // mark the count of LexEntries
            int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;
            // verify no analyses exist for this wordform;
            int         hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
            WfiWordform wf    = new WfiWordform(Cache, hvoWf);

            Assert.AreEqual(0, wf.AnalysesOC.Count);

            // set word pos, to first possibility (e.g. 'adjunct')
            int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

            Assert.IsFalse(hvoSbWordPos == 0);                   // select nonzero pos

            // confirm the analysis (making a real analysis and a LexSense)
            int hvoGloss = m_sandbox.ConfirmAnalysis();

            WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

            CompareTss(tssWordGlossInSandbox, wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));
            // confirm we have only one analysis and that it is monomorphemic
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
            Assert.AreEqual(1, wf.AnalysesOC.Count);
            Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

            // make sure the strings of the wfi gloss matches the strings of the lex gloss.
            ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos);

            // make sure a new entry is in the Lexicon.
            int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;

            Assert.AreEqual(cEntriesOrig + 1, cEntriesAfter);
        }
Пример #5
0
        // Make some sort of wfics for the text of the specified paragraph. Assumes no double spaces!
        // Caches results and does not repeat on same para
        internal int[] MakeAnnotations(StTxtPara para)
        {
            int[] previous;
            if (m_annotations.TryGetValue(para.Hvo, out previous))
            {
                return(previous);
            }
            string contents = para.Contents.Text;

            string[]          words    = contents.Split(new char[] { ' ', '.' });
            int               ich      = 0;
            List <int>        results  = new List <int>();
            ICmAnnotationDefn WficType = CmAnnotationDefn.Twfic(Cache);

            foreach (string word in words)
            {
                if (word == "")
                {
                    ich++;
                    continue;
                }
                WfiWordform wordform = new WfiWordform();
                Cache.LangProject.WordformInventoryOA.WordformsOC.Add(wordform);
                wordform.Form.SetAlternative(word, Cache.DefaultVernWs);
                // JohnT: This should ideally use CmBaseAnnotation.CreateUnownedCba. But most or all uses of this
                // method are memory-only tests, and that method requires a database.
                CmBaseAnnotation cba = new CmBaseAnnotation();
                Cache.LangProject.AnnotationsOC.Add(cba);
                cba.BeginOffset = ich;
                ich            += word.Length;
                cba.EndOffset   = ich;
                ich++;                 // past space or dot
                cba.BeginObjectRA    = para;
                cba.AnnotationTypeRA = WficType;
                //cba.AnnotationTypeRA = ?? can we get CmAnnotationDefn.Twfic(Cache) with a non-database cache?
                WfiAnalysis analysis = new WfiAnalysis();
                wordform.AnalysesOC.Add(analysis);
                WfiGloss gloss = new WfiGloss();
                analysis.MeaningsOC.Add(gloss);
                gloss.Form.SetAlternative(word + "Gloss" + ich, Cache.DefaultAnalWs);
                cba.InstanceOfRA = gloss;
                results.Add(cba.Hvo);
            }
            int[] result = results.ToArray();
            m_annotations[para.Hvo] = result;
            return(result);
        }
Пример #6
0
        public void PickLexGlossCreatingNewAnalysis()
        {
            int hvoCba0_0 = GetCbaHvo(0, 0, 0);

            m_sandbox.SwitchWord(hvoCba0_0, false);
            ILexEntry lexEntry1_Entry;
            ILexSense lexEntry1_Sense1;

            SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1);

            // mark the count of LexEntries
            int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

            // add a new word gloss
            ITsString   tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
            int         hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
            WfiWordform wf    = new WfiWordform(Cache, hvoWf);
            // set word pos, to first possibility (e.g. 'adjunct')
            int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

            // confirm the analysis (making a real analysis and a LexSense)
            int      hvoGloss = m_sandbox.ConfirmAnalysis();
            WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

            // make sure we didn't add entries or senses to the Lexicon.
            int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.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 morph is linked to our lexicon sense, msa, and part of speech.
            ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos);

            // confirm we have created a new analysis and that it is monomorphemic
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
            Assert.AreEqual(1, wf.AnalysesOC.Count);
            Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);
        }
Пример #7
0
        /// <summary>
        /// Make (two) monomorphemic analyses on our favorite wordform, connected to two entries, one with two glosses.
        /// </summary>
        private void MakeMonoAnalyses()
        {
            string    formLexEntry    = "axx";
            ITsString tssLexEntryForm = Cache.MakeVernTss(formLexEntry);
            int       clsidForm;
            ILexEntry entry = LexEntry.CreateEntry(Cache,
                                                   MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
                                                   "axe", null);
            ILexSense senseAxe = entry.SensesOS[0];
            IMoForm   form     = entry.LexemeFormOA;

            m_wfaAxe = new WfiAnalysis();
            m_wfAxx.AnalysesOC.Add(m_wfaAxe);
            IWfiMorphBundle bundle = m_wfaAxe.MorphBundlesOS.Append(new WfiMorphBundle());

            bundle.MorphRA = form;
            bundle.SenseRA = senseAxe;

            m_wgAxe = new WfiGloss();
            m_wfaAxe.MeaningsOC.Add(m_wgAxe);
            m_wgAxe.Form.AnalysisDefaultWritingSystem = "axe";

            m_wgChopper = new WfiGloss();
            m_wfaAxe.MeaningsOC.Add(m_wgChopper);
            m_wgChopper.Form.AnalysisDefaultWritingSystem = "chopper";
            m_wfaAxe.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves);

            ILexEntry entryCut = LexEntry.CreateEntry(Cache,
                                                      MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
                                                      "cut", null);

            m_wfaCut = new WfiAnalysis();
            m_wfAxx.AnalysesOC.Add(m_wfaCut);
            bundle         = m_wfaCut.MorphBundlesOS.Append(new WfiMorphBundle());
            bundle.MorphRA = entryCut.LexemeFormOA;
            bundle.SenseRA = entryCut.SensesOS[0];

            m_wgCut = new WfiGloss();
            m_wfaCut.MeaningsOC.Add(m_wgCut);
            m_wgCut.Form.AnalysisDefaultWritingSystem = "cut";
            m_wfaCut.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves);

            m_cAnalyses += 2;
        }
Пример #8
0
        public void NewGlossExistingLexEntryNewLexSense()
        {
            int hvoCba0_0 = GetCbaHvo(0, 0, 0);

            m_sandbox.SwitchWord(hvoCba0_0, false);
            string    formLexEntry    = "xxxa";
            ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
            int       clsidForm;
            ILexEntry lexEntry1_Entry = LexEntry.CreateEntry(Cache,
                                                             MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
                                                             "xxxa.existingsense1", null);
            ILexSense lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0];

            // mark the count of LexEntries
            int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

            // add a new word gloss
            ITsString   tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
            int         hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
            WfiWordform wf    = new WfiWordform(Cache, hvoWf);
            // set word pos, to first possibility (e.g. 'adjunct')
            int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

            // confirm the analysis (making a real analysis and a LexSense)
            int      hvoGloss = m_sandbox.ConfirmAnalysis();
            WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

            // make sure we didn't add entries to the Lexicon.
            int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;

            Assert.AreEqual(cEntriesOrig, cEntriesAfter);

            // confirm we have only one analysis and that it is monomorphemic
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
            Assert.AreEqual(1, wf.AnalysesOC.Count);
            Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

            // make sure the strings of the wfi gloss matches the strings of the lex gloss.
            ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos);
        }
Пример #9
0
        public void PickLexGlossUsingExistingAnalysis()
        {
            int hvoCba0_0 = GetCbaHvo(0, 0, 0);

            m_sandbox.SwitchWord(hvoCba0_0, false);
            ILexEntry lexEntry1_Entry;
            ILexSense lexEntry1_Sense1;

            SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1);
            ILexEntry lexEntry2_Entry;
            ILexSense lexEntry2_Sense1;

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

            // load sandbox with a guess.
            m_sandbox.SwitchWord(hvoCba0_0, false);
            Assert.IsTrue(m_sandbox.UsingGuess);

            // mark the count of LexEntries
            int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.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)
            int      hvoGloss = m_sandbox.ConfirmAnalysis();
            WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

            // make sure we didn't add entries or senses to the Lexicon.
            int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.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 = wfiGloss.Owner as WfiAnalysis;

            Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo);
            Assert.AreEqual(2, wf.AnalysesOC.Count);
            Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
            Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);
            IWfiAnalysis wfiAnalysis2 = (morphBundle2 as WfiMorphBundle).Owner as WfiAnalysis;

            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);
        }
Пример #10
0
 private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos)
 {
     ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos, false, sense.Entry.LexemeFormOA as IMoStemAllomorph);
 }
Пример #11
0
            protected override void ValidateSegForms(object expectedSegForm, object actualSegForm, string segFormContext)
            {
                string msg = "Mismatched {0} in {1}.";
                // Get the paragraph string corresponding to the annotation.
                ICmBaseAnnotation cbaExpected = CmBaseAnnotation.CreateFromDBObject(m_cache, (int)expectedSegForm);

                // first make sure we have a txt item.
                if (IsLineEnabled(InterlinLineChoices.kflidWord))
                {
                    ITsString tssExpectedForm = m_para.Contents.UnderlyingTsString.GetSubstring(cbaExpected.BeginOffset, cbaExpected.EndOffset);
                    string    lang            = "xkal";
                    // Review: get WsLabel from tssExpectedForm.
                    string actualForm = "";
                    if (cbaExpected.AnnotationTypeRAHvo == TwficAnnotationType)
                    {
                        actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "txt", lang);
                    }
                    else if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
                    {
                        actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "punct", lang);
                    }
                    Assert.AreEqual(tssExpectedForm.Text, actualForm,
                                    String.Format(msg, "word", segFormContext));
                }
                // if WordGloss is enabled, verify it.
                if (IsLineEnabled(InterlinLineChoices.kflidWordGloss))
                {
                    string lang            = "en";
                    string actualWordGloss = m_reader.GetItemInnerText(actualSegForm as XmlNode, "gls", lang);
                    if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
                    {
                        // must be a punctuation (non-wfic)
                        Assert.AreEqual("", actualWordGloss);
                    }
                    else
                    {
                        WfiGloss expectedGloss = null;
                        int      clsId         = m_cache.GetClassOfObject(cbaExpected.InstanceOfRAHvo);
                        if (clsId == WfiGloss.kclsidWfiGloss)
                        {
                            expectedGloss = new WfiGloss(m_cache, cbaExpected.InstanceOfRAHvo);
                        }
                        else if (clsId == WfiWordform.kclsidWfiWordform)
                        {
                            // should be a twfic so get its guess.
                            StTxtPara.TwficInfo cbaInfo = new StTxtPara.TwficInfo(m_cache, cbaExpected.Hvo);
                            int hvoExpectedGloss        = cbaInfo.GetGuess();
                            if (hvoExpectedGloss != 0)
                            {
                                expectedGloss = new WfiGloss(m_cache, hvoExpectedGloss);
                            }
                        }
                        // TODO: There are cases for other classes (e.g. WfiAnalysis) but
                        // the tests do not generate those right now, so we won't worry about them right now.
                        if (expectedGloss != null)
                        {
                            Assert.AreEqual(expectedGloss.Form.AnalysisDefaultWritingSystem, actualWordGloss);
                        }
                        else
                        {
                            Assert.AreEqual("", actualWordGloss);
                        }
                    }
                }
                // validate morph bundle lines.
                if (IsLineEnabled(InterlinLineChoices.kflidMorphemes) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexEntries) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexGloss) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexPos))
                {
                    // compare exported document to the LexEntries information in the WfiAnalysis
                    int hvoWfiAnalysis = 0;
                    if (cbaExpected.AnnotationTypeRAHvo != PunctuationAnnotationType)
                    {
                        hvoWfiAnalysis = WfiAnalysis.GetWfiAnalysisFromInstanceOf(m_cache, cbaExpected.Hvo);
                    }
                    List <XmlNode> morphNodes = m_reader.GetMorphNodes(actualSegForm as XmlNode);
                    if (hvoWfiAnalysis == 0)
                    {
                        // make sure we don't have any morphs.
                        Assert.IsEmpty(morphNodes);
                    }
                    else
                    {
                        IWfiAnalysis wfiAnalysis = WfiAnalysis.CreateFromDBObject(m_cache, hvoWfiAnalysis);
                        foreach (WfiMorphBundle morphBundle in wfiAnalysis.MorphBundlesOS)
                        {
                            int     iMorph          = morphBundle.OwnOrd - 1;
                            string  morphContext    = segFormContext + "/Morph(" + iMorph + ")";
                            XmlNode actualMorphNode = iMorph < morphNodes.Count ? morphNodes[iMorph] : null;
                            if (actualMorphNode == null)
                            {
                                Assert.Fail(String.Format(msg, "missing morph", morphContext));
                            }
                            ITsString tssLexEntry = null;
                            int       hvoMorph    = morphBundle.MorphRAHvo;
                            if (hvoMorph != 0)
                            {
                                // first test the morph form
                                if (IsLineEnabled(InterlinLineChoices.kflidMorphemes))
                                {
                                    string actualMorphForm = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "txt", "xkal");
                                    Assert.AreEqual(morphBundle.MorphRA.Form.VernacularDefaultWritingSystem,
                                                    actualMorphForm,
                                                    String.Format(msg, "morph/txt", morphContext));
                                }

                                // next test the lex entry
                                if (IsLineEnabled(InterlinLineChoices.kflidLexEntries))
                                {
                                    string actualLexEntry     = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "cf", "xkal");
                                    string actualHomograph    = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "hn", "en");
                                    string actualVariantTypes = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "variantTypes", "en");
                                    tssLexEntry = InterlinDocChild.GetLexEntryTss(m_cache, morphBundle, m_cache.DefaultVernWs);
                                    Assert.AreEqual(tssLexEntry.Text, actualLexEntry + actualHomograph + actualVariantTypes,
                                                    String.Format(msg, "morph/cf[hn|variantTypes]", morphContext));
                                }

                                if (IsLineEnabled(InterlinLineChoices.kflidLexGloss))
                                {
                                    string actualLexGloss = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "gls", "en");
                                    string expectedGloss  = "";
                                    if (morphBundle.SenseRA != null && morphBundle.SenseRA.Gloss != null)
                                    {
                                        expectedGloss = morphBundle.SenseRA.Gloss.AnalysisDefaultWritingSystem;
                                    }
                                    Assert.AreEqual(expectedGloss, actualLexGloss,
                                                    String.Format(msg, "morph/gls", morphContext));
                                }
                                if (IsLineEnabled(InterlinLineChoices.kflidLexPos))
                                {
                                    string actualLexMsa = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "msa", "en");
                                    string expectedMsa  = "";
                                    if (morphBundle.SenseRA != null && morphBundle.SenseRA.MorphoSyntaxAnalysisRA != null)
                                    {
                                        expectedMsa = morphBundle.SenseRA.MorphoSyntaxAnalysisRA.InterlinearAbbr;
                                    }
                                    Assert.AreEqual(expectedMsa, actualLexMsa,
                                                    String.Format(msg, "morph/msa", morphContext));
                                }
                            }
                        }
                        Assert.AreEqual(wfiAnalysis.MorphBundlesOS.Count, morphNodes.Count);
                    }
                }
            }