public void ReferencesToDeletedWordformsShouldSwitch()
        {
            var wf1  = MakeWordform("wordXX");
            var wf2  = MakeWordform("wordXX");
            var wf3  = MakeWordform("wordXX");
            var text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create();
            //Cache.LangProject.TextsOC.Add(text);
            var stText = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();

            text.ContentsOA = stText;
            var para = Cache.ServiceLocator.GetInstance <IStTxtParaFactory>().Create();

            stText.ParagraphsOS.Add(para);
            var seg = Cache.ServiceLocator.GetInstance <ISegmentFactory>().Create();

            para.SegmentsOS.Add(seg);
            seg.AnalysesRS.Add(wf1);
            seg.AnalysesRS.Add(wf2);
            seg.AnalysesRS.Add(wf3);
            seg.AnalysesRS.Add(wf2);
            seg.AnalysesRS.Add(wf3);

            var wordset = Cache.ServiceLocator.GetInstance <IWfiWordSetFactory>().Create();

            Cache.LangProject.MorphologicalDataOA.TestSetsOC.Add(wordset);
            wordset.CasesRC.Add(wf2);

            ICmPossibilityList list = Cache.LangProject.KeyTermsList;
            var term = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create();

            list.PossibilitiesOS.Add(term);
            var rendering = Cache.ServiceLocator.GetInstance <IChkRenderingFactory>().Create();

            term.RenderingsOC.Add(rendering);
            rendering.SurfaceFormRA = wf2;
            var chkRef = Cache.ServiceLocator.GetInstance <IChkRefFactory>().Create();

            term.OccurrencesOS.Add(chkRef);
            chkRef.RenderingRA = wf2;

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            // One but only one should survive.
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(seg.AnalysesRS.Count, Is.EqualTo(5));
            Assert.That(seg.AnalysesRS[0], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[1], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[2], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[3], Is.EqualTo(wf));
            Assert.That(seg.AnalysesRS[4], Is.EqualTo(wf));

            // for several tests to prove anything, the wordform that survives must NOT be the
            // one that was there already.
            Assert.That(wf, Is.Not.EqualTo(wf2));

            Assert.That(wordset.CasesRC, Has.Member(wf));
            Assert.That(rendering.SurfaceFormRA, Is.EqualTo(wf));
            Assert.That(chkRef.RenderingRA, Is.EqualTo(wf));
        }
Пример #2
0
        /// <summary>
        /// Combine this instance (which must have a wordform) with the next (which must also have one, in the same WS).
        /// Returns null if it can't be done.
        /// </summary>
        public AnalysisOccurrence MakePhraseWithNextWord()
        {
            if (!CanMakePhraseWithNextWord())
            {
                return(null);
            }
            int beginOffset = GetMyBeginOffsetInPara();
            var oldWf1      = Analysis.Wordform;
            var next        = NextAnalysisOccurrence();
            var oldWf2      = next.Analysis.Wordform;
            int endOffset   = next.GetMyEndOffsetInPara();
            var newForm     = Paragraph.Contents.Substring(beginOffset, endOffset - beginOffset);
            var wordform    = WfiWordformServices.FindOrCreateWordform(Segment.Cache, newForm);
            var mainWs      = newForm.get_WritingSystem(0);
            var otherWss    =
                oldWf1.Form.AvailableWritingSystemIds.Union(oldWf2.Form.AvailableWritingSystemIds).Where(ws => ws != mainWs);

            // If the wordforms we're merging have other writing system information, and the destination wordform doesn't
            // already have values for those WSs, copy it over.
            foreach (var ws in otherWss)
            {
                if (wordform.Form.get_String(ws).Length == 0)
                {
                    var combined = oldWf1.Form.get_String(ws);
                    var other    = oldWf2.Form.get_String(ws);
                    if (combined.Length == 0)
                    {
                        combined = other;                         // just copy oldWf2, nothing in oldWf1
                    }
                    else if (other.Length > 0)
                    {
                        // concatenate them, with a space between
                        var bldr = combined.GetBldr();
                        bldr.Replace(bldr.Length, bldr.Length, " ", null);
                        bldr.ReplaceTsString(bldr.Length, bldr.Length, other);
                        combined = bldr.GetString();
                    }
                    // else combined is already the whole value, from oldWf1
                    wordform.Form.set_String(ws, combined);
                }
            }
            //We need to replace the next analysis and the current one, or possibly the next 2 if there is a
            //zero width space.
            Segment.AnalysesRS.Replace(Index, 1 + next.Index - Index, new ICmObject[] { wordform });
            // We may be able to make guesses of this phrase elsewhere.
            // Review JohnT: this is needed to make a 6.0 test pass, but it's a bit strange: in principle,
            // this new phrase could be discovered and guessed anywhere, not just in this paragraph.
            Paragraph.ParseIsCurrent = false;
            // One of the old wordforms may now be able to be deleted (especially if it was a shorter phrase).
            DeleteWordformIfPossible(oldWf1);
            if (oldWf1 != oldWf2)             // otherwise it may already have been deleted
            {
                DeleteWordformIfPossible(oldWf2);
            }
            return(this);            // still has the correct segment and index, no reason to make a new one.
        }
Пример #3
0
        public void DifferentAnalyses_AreNotMerged()
        {
            var wf        = MakeWordform("bank");
            var wa1       = MakeAnalysis(wf);
            var entryBank = MakeEntry("bank", "side of river");

            MakeBundle(wa1, entryBank.SensesOS[0]);

            var wa2       = MakeAnalysis(wf);
            var entryKick = MakeEntry("bank", "place for money");

            MakeBundle(wa2, entryKick.SensesOS[0]);

            var wa3 = MakeAnalysis(wf);

            MakeBundle(wa3, entryBank.SensesOS[0]);
            var verb = MakePartOfSpeech("verb");

            wa3.CategoryRA = verb;

            var wa4 = MakeAnalysis(wf);

            MakeBundle(wa4, "bank");             // analysis only to morpheme level
            var wa5 = MakeAnalysis(wf);

            MakeBundle(wa5, "bank0");             // analysis only to morpheme level

            var wa6     = MakeAnalysis(wf);
            var bundle6 = MakeBundle(wa6, "bank");

            bundle6.MsaRA = MakeMsa(entryBank);

            var wa7     = MakeAnalysis(wf);
            var bundle7 = MakeBundle(wa7, "bank0");

            bundle7.MorphRA = MorphServices.MakeMorph(entryBank, TsStringUtils.MakeString("bank", Cache.DefaultVernWs));

            var wa8 = MakeAnalysis(wf);

            MakeBundle(wa8, entryBank.SensesOS[0]);
            MakeBundle(wa8, entryBank.SensesOS[0]);             // makes sure it handles different number of bundles


            WfiWordformServices.MergeDuplicateAnalyses(Cache, m_progress);

            // We could try for something stronger; the basic idea is that it should change nothing.
            // But the kind of changes it makes is deleting objects, so this should cover it.
            Assert.That(wa1.IsValidObject);
            Assert.That(wa2.IsValidObject);
            Assert.That(wa3.IsValidObject);
            Assert.That(wa4.IsValidObject);
            Assert.That(wa5.IsValidObject);
            Assert.That(wa6.IsValidObject);
            Assert.That(wa7.IsValidObject);
            Assert.That(wa8.IsValidObject);
        }
        public void WordformsWithNothingSpecialMerged()
        {
            var wf1 = MakeWordform("wordXX");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            // One but only one should survive.
            Survivor(wf1, wf2, wf3);
        }
        public void CopesWithNullVernacular()
        {
            var wf1 = MakeWordform("");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            Survivor(wf2, wf3);
            Assert.That(wf1.IsValidObject, Is.True);
        }
Пример #6
0
        public void IdenticalTrivialAnalyses_AreMerged()
        {
            var wf  = MakeWordform("bank");
            var wa1 = MakeAnalysis(wf);
            var wa2 = MakeAnalysis(wf);

            WfiWordformServices.MergeDuplicateAnalyses(Cache, m_progress);

            Assert.That(!wa1.IsValidObject || !wa2.IsValidObject);           // one should be deleted
            Assert.That(wa1.IsValidObject || wa2.IsValidObject);             // and one should survive!
        }
        public void ExtraWritingSystemsAreCopied()
        {
            var wf1   = MakeWordform("wordXX");
            var wf2   = MakeWordform("wordXX");
            var wf3   = MakeWordform("wordXX");
            int wsSpn = Cache.WritingSystemFactory.GetWsFromStr("es");

            wf2.Form.set_String(wsSpn, TsStringUtils.MakeString("Spanish", wsSpn));
            WfiWordformServices.FixDuplicates(Cache, m_progress);
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wf, Is.Not.EqualTo(wf2));             // otherwise it doesn't prove much
            Assert.That(wf.Form.get_String(wsSpn).Text, Is.EqualTo("Spanish"));
        }
        public void SpellingInCorrectBeatsUnknown()
        {
            var wf1 = MakeWordform("wordXX");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            wf2.SpellingStatus = (int)SpellingStatusStates.incorrect;
            WfiWordformServices.FixDuplicates(Cache, m_progress);
            // One but only one should survive.
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wf, Is.Not.EqualTo(wf2));             // otherwise it doesn't prove much
            Assert.That(wf.SpellingStatus, Is.EqualTo((int)SpellingStatusStates.incorrect));
        }
        public void ChecksumIsReset()
        {
            var wf1 = MakeWordform("wordXX");
            var wf2 = MakeWordform("wordXX");
            var wf3 = MakeWordform("wordXX");

            wf1.Checksum = 5;
            wf2.Checksum = 6;
            wf3.Checksum = 7;
            WfiWordformServices.FixDuplicates(Cache, m_progress);
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wf, Is.Not.EqualTo(wf2));             // otherwise it doesn't prove much
            Assert.That(wf.Checksum, Is.EqualTo(0));
        }
Пример #10
0
        public void AnalysesPreserved()
        {
            var wf1 = MakeWordform("wordXX");
            var wa1 = MakeAnalysis(wf1);
            var wf2 = MakeWordform("wordXX");
            var wa2 = MakeAnalysis(wf2);
            var wf3 = MakeWordform("wordXX");
            var wa3 = MakeAnalysis(wf3);

            WfiWordformServices.FixDuplicates(Cache, m_progress);
            var wf = Survivor(wf1, wf2, wf3);

            Assert.That(wa1.Owner, Is.EqualTo(wf));
            Assert.That(wa2.Owner, Is.EqualTo(wf));
            Assert.That(wa3.Owner, Is.EqualTo(wf));
        }
Пример #11
0
        public void InconsistentAlternativesPreventMergeAndAreReported()
        {
            var wf1   = MakeWordform("wordXX");
            var wf2   = MakeWordform("wordXX");
            var wf3   = MakeWordform("wordZZ");
            var wf4   = MakeWordform("wordZZ");
            var wf5   = MakeWordform("wordZZ");
            int wsSpn = Cache.WritingSystemFactory.GetWsFromStr("es");

            wf1.Form.set_String(wsSpn, TsStringUtils.MakeString("Spanish", wsSpn));
            wf2.Form.set_String(wsSpn, TsStringUtils.MakeString("SpanishOther", wsSpn));
            wf3.Form.set_String(wsSpn, TsStringUtils.MakeString("Spanish", wsSpn));
            wf4.Form.set_String(wsSpn, TsStringUtils.MakeString("SpanishOther", wsSpn));
            wf5.Form.set_String(wsSpn, TsStringUtils.MakeString("SpanishYetAnother", wsSpn));
            var failureList = WfiWordformServices.FixDuplicates(Cache, m_progress);

            // None should be deleted.
            Assert.That(wf1.IsValidObject && wf2.IsValidObject && wf3.IsValidObject && wf4.IsValidObject && wf5.IsValidObject);
            Assert.That(failureList, Is.EqualTo("wordXX wordZZ"));
        }
Пример #12
0
        public void ComplexMerge_SucceedsAndFixesRefs()
        {
            var wf             = MakeWordform("bank");
            var wa1            = MakeAnalysis(wf);
            var entryBankRiver = MakeEntry("bank", "side of river");

            MakeBundle(wa1, entryBankRiver.SensesOS[0]);

            var wa2            = MakeAnalysis(wf);
            var entryBankMoney = MakeEntry("bank", "place for money");

            MakeBundle(wa2, entryBankMoney.SensesOS[0]);

            var wadup1 = MakeAnalysis(wf);

            MakeBundle(wadup1, entryBankMoney.SensesOS[0]);

            var wadup2 = MakeAnalysis(wf);

            MakeBundle(wadup2, entryBankMoney.SensesOS[0]);

            var wgMoney      = MakeGloss(wa2, "money");
            var wgPlaceMoney = MakeGloss(wadup1, "place for money");
            var wgdup1       = MakeGloss(wa2, "money");
            var wgdup2       = MakeGloss(wadup1, "money");
            var wgdup3       = MakeGloss(wadup2, "money");

            var text = MakeText("");
            var seg  = MakeSegment(text.ContentsOA, "bank bank bank bank bank bank bank bank");

            seg.AnalysesRS.Add(wa1);
            seg.AnalysesRS.Add(wa2);
            seg.AnalysesRS.Add(wadup1);
            seg.AnalysesRS.Add(wadup2);
            seg.AnalysesRS.Add(wgMoney);
            seg.AnalysesRS.Add(wgPlaceMoney);
            seg.AnalysesRS.Add(wgdup1);
            seg.AnalysesRS.Add(wgdup2);
            seg.AnalysesRS.Add(wgdup3);

            WfiWordformServices.MergeDuplicateAnalyses(Cache, m_progress);

            // Theoretically, wa3 or wa4 could legitimately be the survivor. But in fact it is now wa1.
            var survivor = wa2;

            Assert.That(survivor.IsValidObject);
            Assert.That(wa2.IsValidObject);
            Assert.That(wadup1.IsValidObject, Is.False);
            Assert.That(wadup2.IsValidObject, Is.False);

            var survivingGloss = wgMoney;             // Enhance: any other duplicate surviving is OK.

            Assert.That(survivingGloss.IsValidObject);
            Assert.That(wgPlaceMoney.IsValidObject);
            Assert.That(wgPlaceMoney.Owner, Is.EqualTo(survivor));
            Assert.That(wgdup1.IsValidObject, Is.False);
            Assert.That(wgdup2.IsValidObject, Is.False);
            Assert.That(wgdup3.IsValidObject, Is.False);

            Assert.That(seg.AnalysesRS[0], Is.EqualTo(wa1));
            Assert.That(seg.AnalysesRS[1], Is.EqualTo(survivor));
            Assert.That(seg.AnalysesRS[2], Is.EqualTo(survivor));
            Assert.That(seg.AnalysesRS[3], Is.EqualTo(survivor));
            Assert.That(seg.AnalysesRS[4], Is.EqualTo(survivingGloss));
            Assert.That(seg.AnalysesRS[5], Is.EqualTo(wgPlaceMoney));
            Assert.That(seg.AnalysesRS[6], Is.EqualTo(survivingGloss));
            Assert.That(seg.AnalysesRS[7], Is.EqualTo(survivingGloss));
            Assert.That(seg.AnalysesRS[8], Is.EqualTo(survivingGloss));
        }