Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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!
        }
Ejemplo n.º 3
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));
        }