Esempio n. 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);
        }
        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);
        }
Esempio n. 3
0
        public void AddWordAnalysis(WordAnalysis lexemes)
        {
            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                IWfiWordform wordform;
                if (!TryGetWordform(lexemes.Word, out wordform))
                {
                    wordform = m_cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(
                        TsStringUtils.MakeString(lexemes.Word.Normalize(NormalizationForm.FormD), DefaultVernWs));
                }

                IWfiAnalysis analysis = m_cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create();
                wordform.AnalysesOC.Add(analysis);
                analysis.ApprovalStatusIcon = (int)Opinions.approves;

                foreach (Lexeme lexeme in lexemes)
                {
                    var entryLexeme = (FdoLexEntryLexeme)lexeme;
                    ILexEntry entry;
                    if (TryGetEntry(entryLexeme.Key, out entry))
                    {
                        IWfiMorphBundle mb = m_cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create();
                        analysis.MorphBundlesOS.Add(mb);
                        mb.MorphRA = entry.LexemeFormOA;
                        mb.SenseRA = entry.SensesOS[0];
                        mb.MsaRA   = entry.SensesOS[0].MorphoSyntaxAnalysisRA;
                    }
                }
            });
        }
Esempio n. 4
0
        private void ValidateSenseWithAnalysis(ILexSense sense, IWfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph)
        {
            IWfiAnalysis wfiAnalysis = wfiGloss.Owner as IWfiAnalysis;

            CompareTss(sense.Gloss.get_String(Cache.DefaultAnalWs),
                       wfiGloss.Form.get_String(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, morphBundle.SenseRA);
            Assert.AreEqual(sense.MorphoSyntaxAnalysisRA, morphBundle.MsaRA);
            if (!fMatchMainPossibility)
            {
                // expect exact possibility
                Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Hvo);
            }
            else
            {
                IPartOfSpeech posTarget = Cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(hvoSbWordPos);
                Assert.AreEqual(posTarget.MainPossibility, (sense.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.MainPossibility);
            }
            Assert.AreEqual(allomorph, morphBundle.MorphRA);
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRA.Hvo);
        }
        private static IWfiMorphBundle AppendMorphBundleToAnalysis(ILexEntry lexEntry1_Entry, ILexSense lexEntry1_Sense1, IWfiAnalysis analysis)
        {
            IWfiMorphBundle morphBundle = analysis.MorphBundlesOS.Append(new WfiMorphBundle());

            morphBundle.MorphRA = lexEntry1_Entry.LexemeFormOA;
            morphBundle.SenseRA = lexEntry1_Sense1;
            morphBundle.MsaRA   = lexEntry1_Sense1.MorphoSyntaxAnalysisRA;
            return(morphBundle);
        }
Esempio n. 6
0
            /// <summary>
            /// Put the sandbox info into the real WfiAnalysis (based on the m_hvoWfiAnalysis id).
            /// </summary>
            /// <returns>'true', if anything changed, otherwise 'false'.</returns>
            internal bool UpdateRealAnalysis()
            {
                bool isDirty = false;

                BuildMorphLists();

                /* Sets these three variables up.
                 * m_analysisMorphs = new int[m_cmorphs];
                 * m_analysisMsas = new int[m_cmorphs];
                 * m_analysisSenses = new int[m_cmorphs];
                 */

                Debug.Assert(m_anal.MorphBundlesOS.Count == m_cmorphs);                 // Better be the same.
                for (int imorph = 0; imorph < m_cmorphs; imorph++)
                {
                    IWfiMorphBundle mb = m_anal.MorphBundlesOS[imorph];

                    // Process Morph.
                    int oldHvo = mb.MorphRAHvo;
                    int newHvo = m_analysisMorphs[imorph];
                    if (oldHvo != newHvo)
                    {
                        if (newHvo == 0 && oldHvo != 0)
                        {
                            // Change to 'unknown'. Will no longer be able to use the morph property to get
                            // at the actual form, so reinstate it in the bundle.
                            foreach (int ws in mb.Cache.LangProject.VernWssRC.HvoArray)
                            {
                                mb.Form.SetAlternativeTss(mb.Cache.GetMultiStringAlt(oldHvo,
                                                                                     (int)MoForm.MoFormTags.kflidForm, ws));
                            }
                        }
                        mb.MorphRAHvo = newHvo;
                        isDirty       = true;
                    }

                    // Process Sense.
                    oldHvo = mb.SenseRAHvo;
                    newHvo = m_analysisSenses[imorph];
                    if (oldHvo != newHvo)
                    {
                        mb.SenseRAHvo = newHvo;
                        isDirty       = true;
                    }

                    // Process MSA.
                    oldHvo = mb.MsaRAHvo;
                    newHvo = m_analysisMsas[imorph];
                    if (oldHvo != newHvo)
                    {
                        mb.MsaRAHvo = newHvo;
                        isDirty     = true;
                    }
                }
                return(isDirty);
            }
Esempio n. 7
0
 private static bool DuplicateBundles(IWfiMorphBundle bundle1, IWfiMorphBundle bundle2)
 {
     if (bundle1.SenseRA != bundle2.SenseRA || bundle1.MsaRA != bundle2.MsaRA || bundle1.MorphRA != bundle2.MorphRA)
     {
         return(false);
     }
     return
         (bundle1.Form.AvailableWritingSystemIds.Union(bundle2.Form.AvailableWritingSystemIds)
          .All(ws => bundle1.Form.get_String(ws).Equals(bundle2.Form.get_String(ws))));
 }
Esempio n. 8
0
        private static IWfiMorphBundle AppendMorphBundleToAnalysis(ILexEntry lexEntry1_Entry, ILexSense lexEntry1_Sense1, IWfiAnalysis analysis)
        {
            var             mbFactory   = analysis.Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>();
            IWfiMorphBundle morphBundle = mbFactory.Create();

            analysis.MorphBundlesOS.Add(morphBundle);
            morphBundle.MorphRA = lexEntry1_Entry.LexemeFormOA;
            morphBundle.SenseRA = lexEntry1_Sense1;
            morphBundle.MsaRA   = lexEntry1_Sense1.MorphoSyntaxAnalysisRA;
            return(morphBundle);
        }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="morphBundle"></param>
        /// <param name="wsVern"></param>
        /// <returns></returns>
        static public ITsString GetLexEntryTss(IWfiMorphBundle morphBundle, int wsVern)
        {
            LcmCache   cache   = morphBundle.Cache;
            LexEntryVc vcEntry = new LexEntryVc(cache);

            vcEntry.WritingSystemCode = wsVern;
            TsStringCollectorEnv collector = new TsStringCollectorEnv(null, cache.MainCacheAccessor, morphBundle.Hvo);

            collector.RequestAppendSpaceForFirstWordInNewParagraph = false;
            vcEntry.Display(collector, morphBundle.Hvo, (int)LexEntryVc.kfragEntryAndVariant);
            return(collector.Result);
        }
Esempio n. 10
0
        public LexiconSense AddSense()
        {
            LexiconSense sense       = null;
            bool         lexemeAdded = false;

            using (m_lexicon.ActivationContext.Activate())
            {
                NonUndoableUnitOfWorkHelper.Do(m_lexicon.Cache.ActionHandlerAccessor, () =>
                {
                    IWfiWordform wordform;
                    if (!m_lexicon.TryGetWordform(m_key.LexicalForm, out wordform))
                    {
                        wordform    = m_lexicon.CreateWordform(m_key.LexicalForm);
                        lexemeAdded = true;
                    }
                    // For wordforms, our "senses" could be new meanings of an analysis for the word
                    // or it could be a brand new analysis. Because we have no idea what the user actually
                    // wanted, we just assume the worst (they want to create a new analysis for the word
                    // with a new meaning).
                    IWfiAnalysis analysis = m_lexicon.Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create();
                    wordform.AnalysesOC.Add(analysis);
                    analysis.ApprovalStatusIcon = (int)Opinions.approves;                              // Assume the analysis from the external application is user approved
                    IMoStemAllomorph morph      = m_lexicon.Cache.ServiceLocator.GetInstance <IMoStemAllomorphRepository>().AllInstances().FirstOrDefault(allo =>
                    {
                        ITsString tss = allo.Form.StringOrNull(m_lexicon.DefaultVernWs);
                        if (tss != null)
                        {
                            return(tss.Text == LexicalForm.Normalize(NormalizationForm.FormD));
                        }
                        return(false);
                    });
                    if (morph != null)
                    {
                        IWfiMorphBundle mb = m_lexicon.Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create();
                        analysis.MorphBundlesOS.Add(mb);
                        mb.MorphRA = morph;
                        var entry  = morph.OwnerOfClass <ILexEntry>();
                        mb.SenseRA = entry.SensesOS[0];
                        mb.MsaRA   = entry.SensesOS[0].MorphoSyntaxAnalysisRA;
                    }
                    IWfiGloss gloss = m_lexicon.Cache.ServiceLocator.GetInstance <IWfiGlossFactory>().Create();
                    analysis.MeaningsOC.Add(gloss);
                    sense = new WfiGlossLexiconSense(m_lexicon, m_key, gloss);
                });
            }
            if (lexemeAdded)
            {
                m_lexicon.OnLexemeAdded(this);
            }
            m_lexicon.OnLexiconSenseAdded(this, sense);
            return(sense);
        }
Esempio n. 11
0
        private string GetStemsCategory(IWfiMorphBundle bundle)
        {
            string result = "";
            var    msa    = bundle.MsaRA as IMoStemMsa;

            if (msa != null)
            {
                var pos = msa.PartOfSpeechForWsTSS(Cache.DefaultAnalWs);
                if (pos != null)
                {
                    result = pos.Text;
                }
            }
            return(result);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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;
        }
Esempio n. 14
0
 public void EnsureMorphBundleHasSense(IWfiMorphBundle bundle)
 {
     if (bundle != null)
     {
         using (StreamWriter file = new StreamWriter(tempFileName, true))
         {
             file.WriteLine("\tEMBHS: bundle guid=\"" + bundle.Guid + "\"");
             var sense = bundle.SenseRA;
             if (sense == null)
             {             // bundle does not have a sense (due to coming from parser)
                           // find its sense and set it in bundle
                 file.WriteLine("\t\tbundle missing sense");
                 var msa = bundle.MsaRA;
                 if (msa != null)
                 {
                     file.WriteLine("\t\tmsa guid=\"" + msa.Guid + "\"");
                     var entry = msa.Owner as ILexEntry;
                     if (entry != null)
                     {
                         file.WriteLine("\t\tentry guid=\"" + entry.Guid + "\"");
                         sense = entry.SenseWithMsa(msa);
                         if (sense != null)
                         {
                             file.WriteLine("\t\tsense guid=\"" + sense.Guid + "\"");
                             bundle.SenseRA = sense;
                         }
                     }
                 }
             }
             else
             {
                 file.WriteLine("\t\tsense guid=\"" + sense.Guid + "\"");
             }
         }
     }
     else
     {
         using (StreamWriter file = new StreamWriter(tempFileName, true))
         {
             file.WriteLine("\tEMBHS: bundle is null");
         }
     }
 }
Esempio n. 15
0
        public void HumanApprovedParserPreviouslyApprovedButNowRejectedAnalysisSurvives()
        {
            IWfiWordform theThreeLittlePigs = CheckAnalysisSize("theThreeLittlePigsTEST", 0, true);

            ParseResult  result = null;
            IWfiAnalysis anal   = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Pig entry
                ILexEntry pigN            = m_entryFactory.Create();
                IMoStemAllomorph pigNForm = m_stemAlloFactory.Create();
                pigN.AlternateFormsOS.Add(pigNForm);
                pigNForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("pigNTEST", m_vernacularWS.Handle);
                IMoStemMsa pigNMsa = m_stemMsaFactory.Create();
                pigN.MorphoSyntaxAnalysesOC.Add(pigNMsa);
                ILexSense pigNSense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();
                pigN.SensesOS.Add(pigNSense);

                // Human approved anal. Start with parser approved, but then it failed.
                var analFactory = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>();
                var mbFactory   = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>();
                // Only analysis: human approved, previously parser approved but no longer produced.
                anal = analFactory.Create();
                theThreeLittlePigs.AnalysesOC.Add(anal);
                IWfiMorphBundle mb = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.MorphRA = pigNForm;
                mb.MsaRA   = pigNMsa;
                HumanAgent.SetEvaluation(anal, Opinions.approves);
                ParserAgent.SetEvaluation(anal, Opinions.approves);
                CheckEvaluationSize(anal, 2, true, "anal");
                CheckAnalysisSize("theThreeLittlePigsTEST", 1, true);

                result = new ParseResult(Enumerable.Empty <ParseAnalysis>());
            });

            m_filer.ProcessParse(theThreeLittlePigs, ParserPriority.Low, result);
            ExecuteIdleQueue();
            CheckEvaluationSize(anal, 2, false, "analHvo");
            Assert.IsTrue(anal.IsValidObject, "analysis should end up with one evaluation and not be deleted");
        }
Esempio n. 16
0
        public void HumanHasNoopinionParserHadApprovedButNoLongerApprovesRemovesAnalysis()
        {
            IWfiWordform threeLittlePigs = CheckAnalysisSize("threeLittlePigsTEST", 0, true);

            ParseResult  result = null;
            IWfiAnalysis anal   = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Pig entry
                ILexEntry pigN            = m_entryFactory.Create();
                IMoStemAllomorph pigNForm = m_stemAlloFactory.Create();
                pigN.AlternateFormsOS.Add(pigNForm);
                pigNForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("pigNTEST", m_vernacularWS.Handle);
                IMoStemMsa pigNMsa = m_stemMsaFactory.Create();
                pigN.MorphoSyntaxAnalysesOC.Add(pigNMsa);
                ILexSense pigNSense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();
                pigN.SensesOS.Add(pigNSense);

                // Human no-opinion anal. Parser had approved, but then it failed to produce it.
                var analFactory = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>();
                var mbFactory   = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>();
                // Human no-opinion anal. Parser had approved, but then it failed to produce it.
                anal = analFactory.Create();
                threeLittlePigs.AnalysesOC.Add(anal);
                IWfiMorphBundle mb = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.MorphRA = pigNForm;
                mb.MsaRA   = pigNMsa;
                HumanAgent.SetEvaluation(anal, Opinions.noopinion);
                ParserAgent.SetEvaluation(anal, Opinions.approves);
                CheckEvaluationSize(anal, 1, true, "anal");
                CheckAnalysisSize("threeLittlePigsTEST", 1, true);

                result = new ParseResult(Enumerable.Empty <ParseAnalysis>());
            });

            m_filer.ProcessParse(threeLittlePigs, ParserPriority.Low, result);
            ExecuteIdleQueue();
            Assert.IsFalse(anal.IsValidObject, "analysis should end up with no evaluations and be deleted.");
        }
Esempio n. 17
0
 // Verify something about analysis i of the given wordform, specifically, that it has an analysis at iAnalysis
 // which has a word gloss (at index iGloss) equal to wgloss,
 // and a morph bundle at iMorph with the specified form and gloss.
 // iGloss or iMorph may be -1 to suppress.
 private void VerifyAnalysis(IWfiWordform wf, string wgloss, int iMorph, string form, string mgloss,
                             string message)
 {
     foreach (WfiAnalysis analysis in wf.AnalysesOC)
     {
         foreach (IWfiGloss wg in analysis.MeaningsOC)
         {
             if (wgloss == wg.Form.AnalysisDefaultWritingSystem)
             {
                 if (iMorph >= 0)
                 {
                     IWfiMorphBundle bundle = analysis.MorphBundlesOS[iMorph];
                     Assert.AreEqual(mgloss, bundle.SenseRA.Gloss.AnalysisDefaultWritingSystem, message + " morph gloss");
                     Assert.AreEqual(form, bundle.MorphRA.Form.VernacularDefaultWritingSystem, message + " morph form");
                 }
                 return;                         // found what we want, mustn't hit the Fail below!
             }
         }
     }
     Assert.Fail(message + " word gloss not found");
 }
Esempio n. 18
0
        private bool GetWordAnalysis(IWfiAnalysis analysis, out WordAnalysis lexemes)
        {
            var lexemeArray = new Lexeme[analysis.MorphBundlesOS.Count];

            for (int i = 0; i < analysis.MorphBundlesOS.Count; i++)
            {
                IWfiMorphBundle mb = analysis.MorphBundlesOS[i];
                if (mb.MorphRA == null)
                {
                    lexemes = null;
                    return(false);
                }
                var entry = mb.MorphRA.OwnerOfClass <ILexEntry>();
                if (entry.LexemeFormOA != mb.MorphRA)
                {
                    lexemes = null;
                    return(false);
                }
                lexemeArray[i] = GetEntryLexeme(entry);
            }

            lexemes = new FdoWordAnalysis(analysis.Wordform.Form.get_String(DefaultVernWs).Text.Normalize(), lexemeArray);
            return(true);
        }
Esempio n. 19
0
		private static bool DuplicateBundles(IWfiMorphBundle bundle1, IWfiMorphBundle bundle2)
		{
			if (bundle1.SenseRA != bundle2.SenseRA || bundle1.MsaRA != bundle2.MsaRA || bundle1.MorphRA != bundle2.MorphRA)
				return false;
			return
				bundle1.Form.AvailableWritingSystemIds.Union(bundle2.Form.AvailableWritingSystemIds)
					.All(ws => bundle1.Form.get_String(ws).Equals(bundle2.Form.get_String(ws)));
		}
Esempio n. 20
0
        public void DuplicateAnalysesApproval()
        {
            int    hvoBearTEST = CheckAnalysisSize("bearTEST", 0, true);
            string xmlFragment = "";
            int    anal1Hvo;
            int    anal2Hvo;
            int    anal3Hvo;

            using (FdoCache cache = FdoCache.Create("TestLangProj"))
            {
                IWfiAnalysis anal = null;
                ILexDb       ldb  = cache.LangProject.LexDbOA;

                // Bear entry
                ILexEntry bearN = (ILexEntry)ldb.EntriesOC.Add(new LexEntry());
                AddIdToList(bearN.Hvo);
                IMoStemAllomorph bearNForm = (IMoStemAllomorph)bearN.AlternateFormsOS.Append(new MoStemAllomorph());
                bearNForm.Form.VernacularDefaultWritingSystem = "bearNTEST";
                IMoStemMsa bearNMSA = (IMoStemMsa)bearN.MorphoSyntaxAnalysesOC.Add(new MoStemMsa());
                ILexSense  bearNLS  = (ILexSense)bearN.SensesOS.Append(new LexSense());;

                IWfiWordform wf = WfiWordform.CreateFromDBObject(cache, hvoBearTEST);
                // First of two duplicate analyses
                anal     = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis());
                anal1Hvo = anal.Hvo;
                IWfiMorphBundle mb = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle());
                mb.MorphRA = bearNForm;
                mb.MsaRA   = bearNMSA;
                CheckEvaluationSize(anal1Hvo, 0, true, "anal1Hvo");

                // Non-duplicate, to make sure it does not get approved.
                anal       = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis());
                anal2Hvo   = anal.Hvo;
                mb         = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle());
                mb.SenseRA = bearNLS;
                CheckEvaluationSize(anal2Hvo, 0, true, "anal2Hvo");

                // Second of two duplicate analyses
                anal       = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis());
                anal3Hvo   = anal.Hvo;
                mb         = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle());
                mb.MorphRA = bearNForm;
                mb.MsaRA   = bearNMSA;
                CheckEvaluationSize(anal3Hvo, 0, true, "anal3Hvo");
                CheckAnalysisSize("bearTEST", 3, false);

                xmlFragment =
                    "<Wordform DbRef='" + hvoBearTEST.ToString() + "' Form='bearTEST'>\n"
                    + "<WfiAnalysis>\n"
                    + "<Morphs>\n"
                    + "<Morph>\n"
                    + "<MoForm DbRef='" + bearNForm.Hvo.ToString() + "' Label='bearNTEST'/>\n"
                    + "<MSI DbRef='" + bearNMSA.Hvo.ToString() + "'/>\n"
                    + "</Morph>\n"
                    + "</Morphs>\n"
                    + "</WfiAnalysis>\n"
                    + "</Wordform>\n";
            }

            m_filer.ProcessParse(MakeXML(xmlFragment, true));
            CheckEvaluationSize(anal1Hvo, 1, false, "anal1Hvo");
            CheckEvaluationSize(anal2Hvo, 0, false, "anal2Hvo");
            CheckEvaluationSize(anal3Hvo, 1, false, "anal3Hvo");
        }
Esempio n. 21
0
        public void DuplicateAnalysesApproval()
        {
            IWfiWordform pigs = CheckAnalysisSize("pigsTEST", 0, true);

            ParseResult  result = null;
            IWfiAnalysis anal1 = null, anal2 = null, anal3 = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Bear entry
                ILexEntry pigN            = m_entryFactory.Create();
                IMoStemAllomorph pigNForm = m_stemAlloFactory.Create();
                pigN.AlternateFormsOS.Add(pigNForm);
                pigNForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("pigNTEST", m_vernacularWS.Handle);
                IMoStemMsa pigNMsa = m_stemMsaFactory.Create();
                pigN.MorphoSyntaxAnalysesOC.Add(pigNMsa);
                ILexSense pigNSense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();
                pigN.SensesOS.Add(pigNSense);

                var analFactory = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>();
                var mbFactory   = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>();
                // First of two duplicate analyses
                IWfiAnalysis anal = analFactory.Create();
                pigs.AnalysesOC.Add(anal);
                anal1 = anal;
                IWfiMorphBundle mb = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.MorphRA = pigNForm;
                mb.MsaRA   = pigNMsa;
                CheckEvaluationSize(anal1, 0, true, "anal1");

                // Non-duplicate, to make sure it does not get approved.
                anal = analFactory.Create();
                pigs.AnalysesOC.Add(anal);
                anal2 = anal;
                mb    = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.SenseRA = pigNSense;
                CheckEvaluationSize(anal2, 0, true, "anal2");

                // Second of two duplicate analyses
                anal = analFactory.Create();
                pigs.AnalysesOC.Add(anal);
                anal3 = anal;
                mb    = mbFactory.Create();
                anal.MorphBundlesOS.Add(mb);
                mb.MorphRA = pigNForm;
                mb.MsaRA   = pigNMsa;
                CheckEvaluationSize(anal3, 0, true, "anal3");
                CheckAnalysisSize("pigsTEST", 3, false);

                result = new ParseResult(new[]
                {
                    new ParseAnalysis(new[]
                    {
                        new ParseMorph(pigNForm, pigNMsa)
                    })
                });
            });

            m_filer.ProcessParse(pigs, ParserPriority.Low, result);
            ExecuteIdleQueue();
            CheckEvaluationSize(anal1, 1, false, "anal1Hvo");
            Assert.IsFalse(anal2.IsValidObject, "analysis 2 should end up with no evaluations and so be deleted");
            CheckEvaluationSize(anal3, 1, false, "anal3Hvo");
        }
Esempio n. 22
0
        public string ExtractTextSegmentAsANA(ISegment segment)
        {
            BadGlosses.Clear();
            var sb   = new StringBuilder();
            var sbA  = new StringBuilder();
            var sbD  = new StringBuilder();
            var sbC  = new StringBuilder();
            var sbFD = new StringBuilder();
            var sbP  = new StringBuilder();
            var sbW  = new StringBuilder();

            foreach (IAnalysis analysis in segment.AnalysesRS)
            {
                var wordform = analysis.Wordform;
                if (wordform == null)
                {
                    continue;
                }
                sbA.Clear();
                sbA.Append("\\a ");
                sbD.Clear();
                sbD.Append("\\d ");
                sbC.Clear();
                sbC.Append("\\cat ");
                sbFD.Clear();
                sbFD.Append("\\fd ");
                sbP.Clear();
                sbP.Append("\\p ");
                sbW.Clear();
                sbW.Append("\\w ");
                var shape = wordform.Form.VernacularDefaultWritingSystem.Text;
                sbW.Append(shape + "\n");
                int ambiguities = wordform.AnalysesOC.Count;
                if (ambiguities > 1)
                {
                    String ambigs = "%" + ambiguities + "%";
                    sbA.Append(ambigs);
                    sbD.Append(ambigs);
                    sbC.Append(ambigs);
                    sbFD.Append(ambigs);
                    sbP.Append(ambigs);
                }
                foreach (IWfiAnalysis wfiAnalysis in wordform.AnalysesOC)
                {
                    IWfiMorphBundle previous      = null;
                    IMoForm         previousMorph = null;
                    var             maxMorphs     = wfiAnalysis.MorphBundlesOS.Count;
                    int             i             = 0;
                    foreach (IWfiMorphBundle bundle in wfiAnalysis.MorphBundlesOS)
                    {
                        var msa = bundle.MsaRA;
                        if (msa == null)
                        {
                            continue;
                        }
                        var morph = bundle.MorphRA;
                        if (morph == null)
                        {
                            continue;
                        }
                        if (msa is IMoStemMsa && !IsAttachedClitic(morph.MorphTypeRA.Guid, maxMorphs))
                        {
                            if (previous == null)
                            {
                                sbA.Append("< ");
                            }
                            else
                            {
                                if (previousMorph.MorphTypeRA.IsPrefixishType ||
                                    previousMorph.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphProclitic)
                                {
                                    sbA.Append(" < ");
                                }
                            }
                        }
                        if (msa is IMoStemMsa && !IsAttachedClitic(morph.MorphTypeRA.Guid, maxMorphs))
                        {
                            var cat = msa.PartOfSpeechForWsTSS(Cache.DefaultAnalWs).Text;
                            sbA.Append(cat + " ");
                        }
                        else if (i > 0)
                        {
                            sbA.Append(" ");
                        }
                        if (morph != null)
                        {
                            sbD.Append(morph.Form.VernacularDefaultWritingSystem.Text);
                        }
                        var sense = bundle.SenseRA;
                        if (sense == null)
                        {                         // a sense can be missing from a bundle if the bundle is built by the parser filer
                            var entryOfMsa = (ILexEntry)msa.Owner;
                            sense = entryOfMsa.SensesOS.FirstOrDefault(s => s.MorphoSyntaxAnalysisRA == msa);
                            if (sense != null)
                            {
                                HandleSense(sbA, sbFD, sense);
                            }
                            else if (morph != null)
                            {
                                var entry  = (ILexEntry)morph.Owner;
                                var sense2 = entry.SensesOS.FirstOrDefault();
                                if (sense2 == null)
                                {
                                    sbA.Append("missing_sense");
                                }
                                else
                                {
                                    HandleSense(sbA, sbFD, sense2);
                                }
                            }
                        }
                        else
                        {
                            HandleSense(sbA, sbFD, sense);
                        }
                        if (msa is IMoStemMsa && !IsAttachedClitic(morph.MorphTypeRA.Guid, maxMorphs))
                        {
                            sbA.Append(" ");
                            var next = wfiAnalysis.MorphBundlesOS.ElementAtOrDefault(i + 1);
                            if (next == null)
                            {
                                sbA.Append(">");
                            }
                            else
                            {
                                var nextMorph = next.MorphRA;
                                if (nextMorph == null ||
                                    nextMorph.MorphTypeRA.IsSuffixishType ||
                                    nextMorph.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphEnclitic)
                                {
                                    sbA.Append(">");
                                }
                            }
                        }
                        sbP.Append(bundle.Guid.ToString());
                        previous      = bundle;
                        previousMorph = morph;
                        i++;
                        if (i < maxMorphs)
                        {
                            sbD.Append("-");
                            sbFD.Append("=");
                            sbP.Append("=");
                        }
                    }
                    sbC.Append(GetOrComputeWordCategory(wfiAnalysis));
                    if (ambiguities > 1)
                    {
                        sbA.Append("%");
                        sbD.Append("%");
                        sbC.Append("%");
                        sbFD.Append("%");
                        sbP.Append("%");
                    }
                }
                sbA.Append("\n");
                sbD.Append("\n");
                sbC.Append("\n");
                sbFD.Append("\n");
                sbP.Append("\n");
                sbW.Append("\n");
                sb.Append(sbA.ToString());
                sb.Append(sbD.ToString());
                sb.Append(sbC.ToString());
                sb.Append(sbP.ToString());
                sb.Append(sbFD.ToString());
                sb.Append(sbW.ToString());
            }
            return(sb.ToString());
        }
Esempio n. 23
0
        /// <summary>
        /// Process an analysis.
        /// </summary>
        /// <remarks>
        /// This method contains the port of the UpdWfiAnalysisAndEval$ SP.
        /// The SP was about 220 lines of code (not counting a commetned out section).
        /// The C# version is about 60 lines long.
        /// </remarks>
        private void ProcessAnalysis(IWfiWordform wordform, ParseAnalysis analysis)
        {
            /*
             *      Try to find matching analysis(analyses) that already exist.
             *      A "match" is one in which:
             *      (1) the number of morph bundles equal the number of the MoForm and
             *              MorphoSyntaxAnanlysis (MSA) IDs passed in to the stored procedure, and
             *      (2) The objects of each MSA+Form pair match those of the corresponding WfiMorphBundle.
             */
            // Find matching analysis/analyses, if any exist.
            var matches = new HashSet <IWfiAnalysis>();

            foreach (IWfiAnalysis anal in wordform.AnalysesOC)
            {
                if (anal.MorphBundlesOS.Count == analysis.Morphs.Count)
                {
                    // Meets match condition (1), above.
                    bool mbMatch = false;                     //Start pessimistically.
                    int  i       = 0;
                    foreach (IWfiMorphBundle mb in anal.MorphBundlesOS)
                    {
                        var current = analysis.Morphs[i++];
                        if (mb.MorphRA == current.Form && mb.MsaRA == current.Msa && mb.InflTypeRA == current.InflType)
                        {
                            // Possibly matches condition (2), above.
                            mbMatch = true;
                        }
                        else
                        {
                            // Fails condition (2), above.
                            mbMatch = false;
                            break;                             // No sense in continuing.
                        }
                    }
                    if (mbMatch)
                    {
                        // Meets matching condition (2), above.
                        matches.Add(anal);
                    }
                }
            }
            if (matches.Count == 0)
            {
                // Create a new analysis, since there are no matches.
                var newAnal = m_analysisFactory.Create();
                wordform.AnalysesOC.Add(newAnal);
                // Make WfiMorphBundle(s).
                foreach (ParseMorph morph in analysis.Morphs)
                {
                    IWfiMorphBundle mb = m_mbFactory.Create();
                    newAnal.MorphBundlesOS.Add(mb);
                    mb.MorphRA = morph.Form;
                    mb.MsaRA   = morph.Msa;
                    if (morph.InflType != null)
                    {
                        mb.InflTypeRA = morph.InflType;
                    }
                }
                matches.Add(newAnal);
            }
            // (Re)set evaluations.
            foreach (IWfiAnalysis matchingAnal in matches)
            {
                m_parserAgent.SetEvaluation(matchingAnal, Opinions.approves);
            }
        }
Esempio n. 24
0
		/// <summary>
		///
		/// </summary>
		/// <param name="morphBundle"></param>
		/// <param name="wsVern"></param>
		/// <returns></returns>
		static public ITsString GetLexEntryTss(IWfiMorphBundle morphBundle, int wsVern)
		{
			FdoCache cache = morphBundle.Cache;
			LexEntryVc vcEntry = new LexEntryVc(cache);
			vcEntry.WritingSystemCode = wsVern;
			TsStringCollectorEnv collector = new TsStringCollectorEnv(null, cache.MainCacheAccessor, morphBundle.Hvo);
			collector.RequestAppendSpaceForFirstWordInNewParagraph = false;
			vcEntry.Display(collector, morphBundle.Hvo, (int)LexEntryVc.kfragEntryAndVariant);
			return collector.Result;
		}
Esempio n. 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argument">The xCore Command object.</param>
        /// <returns>true</returns>
        public bool OnAddApprovedAnalysis(object argument)
        {
            var mainWnd = (FwXWindow)m_dataEntryForm.FindForm();

            using (EditMorphBreaksDlg dlg = new EditMorphBreaksDlg(mainWnd.Mediator.HelpTopicProvider))
            {
                IWfiWordform wf = Wordform;
                if (wf == null)
                {
                    return(true);
                }
                ITsString tssWord = Wordform.Form.BestVernacularAlternative;
                string    morphs  = tssWord.Text;
                var       cache   = Cache;
                dlg.Initialize(tssWord, morphs, cache.MainCacheAccessor.WritingSystemFactory,
                               cache, m_dataEntryForm.Mediator.StringTbl, m_dataEntryForm.StyleSheet);
                // Making the form active fixes problems like LT-2619.
                // I'm (RandyR) not sure what adverse impact might show up by doing this.
                mainWnd.Activate();
                if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
                {
                    morphs = dlg.GetMorphs().Trim();
                    if (morphs.Length == 0)
                    {
                        return(true);
                    }

                    string[] prefixMarkers  = MorphServices.PrefixMarkers(cache);
                    string[] postfixMarkers = MorphServices.PostfixMarkers(cache);

                    List <string> allMarkers = new List <string>();
                    foreach (string s in prefixMarkers)
                    {
                        allMarkers.Add(s);
                    }

                    foreach (string s in postfixMarkers)
                    {
                        if (!allMarkers.Contains(s))
                        {
                            allMarkers.Add(s);
                        }
                    }
                    allMarkers.Add(" ");

                    string[] breakMarkers = new string[allMarkers.Count];
                    for (int i = 0; i < allMarkers.Count; ++i)
                    {
                        breakMarkers[i] = allMarkers[i];
                    }

                    string fullForm = SandboxBase.MorphemeBreaker.DoBasicFinding(morphs, breakMarkers, prefixMarkers, postfixMarkers);

                    var command = (Command)argument;
                    UndoableUnitOfWorkHelper.Do(command.UndoText, command.RedoText, cache.ActionHandlerAccessor,
                                                () =>
                    {
                        IWfiAnalysis newAnalysis = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create();
                        Wordform.AnalysesOC.Add(newAnalysis);
                        newAnalysis.ApprovalStatusIcon = 1;                                         // Make it human approved.
                        int vernWS = TsStringUtils.GetWsAtOffset(tssWord, 0);
                        foreach (string morph in fullForm.Split(Unicode.SpaceChars))
                        {
                            if (morph != null && morph.Length != 0)
                            {
                                IWfiMorphBundle mb = cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create();
                                newAnalysis.MorphBundlesOS.Add(mb);
                                mb.Form.set_String(vernWS, Cache.TsStrFactory.MakeString(morph, vernWS));
                            }
                        }
                    });
                }
            }
            return(true);
        }
Esempio n. 26
0
        public void VerifyOkToReconcileChanges()
        {
            // Create some test data to play with.
            var entry1   = MakeEntry("kick", "strike with foot");
            var sense1_2 = AddSense(entry1, "propel football");
            var entry2   = MakeEntry("punch", "strike with hand");
            var sense1   = entry1.SensesOS[0];

            // From here on w want to manage our own units of work.
            m_actionHandler.EndUndoTask();
            // Mark this as the starting point.
            var undoManager = Cache.ServiceLocator.GetInstance <IUndoStackManager>();

            undoManager.Save();
            UndoableUnitOfWorkHelper.Do("undo change gloss", "redo", m_actionHandler,
                                        () => sense1.Gloss.AnalysisDefaultWritingSystem =
                                            Cache.TsStrFactory.MakeString("strike with boot", Cache.DefaultAnalWs));
            var cmoFactory = Cache.ServiceLocator.GetInstance <ICmObjectSurrogateFactory>();
            var modified   = new List <ICmObjectSurrogate>();

            modified.Add(GetSurrogate(sense1, cmoFactory));
            m_actionHandler.Undo();
            var uowService = (UnitOfWorkService)undoManager;
            var reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), modified, new List <ICmObjectId>());

            // Only other client made changes
            Assert.That(reconciler.OkToReconcileChanges(), Is.True,
                        "we should be able to make any change if there are no outstanding changes.");

            // Both clients changed the same thing
            UndoableUnitOfWorkHelper.Do("undo change gloss", "redo", m_actionHandler,
                                        () => sense1.Gloss.AnalysisDefaultWritingSystem =
                                            Cache.TsStrFactory.MakeString("strike with shoe", Cache.DefaultAnalWs));
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), modified, new List <ICmObjectId>());
            Assert.That(reconciler.OkToReconcileChanges(), Is.False,
                        "we should not be able to make a change if we have a conflicting change to the same object.");
            m_actionHandler.Undo();
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), modified, new List <ICmObjectId>());
            Assert.That(reconciler.OkToReconcileChanges(), Is.True);

            // Foreign modified, local deleted.
            UndoableUnitOfWorkHelper.Do("undo delete sense", "redo", m_actionHandler,
                                        () => entry1.SensesOS.RemoveAt(0));
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), modified, new List <ICmObjectId>());
            Assert.That(reconciler.OkToReconcileChanges(), Is.False,
                        "we should not be able to make a change if we have deleted an object that the change modifies.");
            m_actionHandler.Undo();
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), modified, new List <ICmObjectId>());
            Assert.That(reconciler.OkToReconcileChanges(), Is.True);

            // Local modified, foreign deleted.
            UndoableUnitOfWorkHelper.Do("undo change gloss", "redo", m_actionHandler,
                                        () => sense1.Gloss.AnalysisDefaultWritingSystem =
                                            Cache.TsStrFactory.MakeString("strike with boot", Cache.DefaultAnalWs));
            var listOfSense1Id = new List <ICmObjectId>();

            listOfSense1Id.Add(sense1.Id);
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), new List <ICmObjectSurrogate>(), listOfSense1Id);
            Assert.That(reconciler.OkToReconcileChanges(), Is.False,
                        "we should not be able to make a change if it involves deleting an object that we have modified.");
            m_actionHandler.Undo();
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), modified, new List <ICmObjectId>());
            Assert.That(reconciler.OkToReconcileChanges(), Is.True);

            // We added a reference to something they deleted (on a new object).
            IWfiMorphBundle bundle = null;

            UndoableUnitOfWorkHelper.Do("undo make ref", "redo", m_actionHandler,
                                        () => bundle = MakeBundle("kick", sense1));
            // We will use these surrogates in a later test.
            var newObjectSurrogates = new List <ICmObjectSurrogate>();

            newObjectSurrogates.Add(GetSurrogate(bundle.Owner.Owner, cmoFactory));
            newObjectSurrogates.Add(GetSurrogate(bundle.Owner, cmoFactory));
            newObjectSurrogates.Add(GetSurrogate(bundle, cmoFactory));
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), new List <ICmObjectSurrogate>(), listOfSense1Id);
            Assert.That(reconciler.OkToReconcileChanges(), Is.False,
                        "we should not be able to make a change if it involves deleting an object that one we have added refers to.");

            // We added a reference to something they deleted (on an existing object).
            UndoableUnitOfWorkHelper.Do("undo clear ref", "redo", m_actionHandler,
                                        () => bundle.SenseRA = null);
            undoManager.Save();
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), new List <ICmObjectSurrogate>(), listOfSense1Id);
            Assert.That(reconciler.OkToReconcileChanges(), Is.True);
            UndoableUnitOfWorkHelper.Do("undo set ref", "redo", m_actionHandler,
                                        () => bundle.SenseRA = sense1);
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), new List <ICmObjectSurrogate>(), listOfSense1Id);
            Assert.That(reconciler.OkToReconcileChanges(), Is.False,
                        "we should not be able to make a change if it involves deleting an object that we have made a reference to.");
            m_actionHandler.Undo();         // setting the sense of the bundle
            m_actionHandler.Undo();         // clearing the sense of the bundle
            m_actionHandler.Undo();         // creating the bundle.
            undoManager.Save();             // back to square 1.

            // They added a reference to something we deleted
            UndoableUnitOfWorkHelper.Do("undo delete sense", "redo", m_actionHandler,
                                        () => entry1.SensesOS.RemoveAt(0));
            // Now pretend THEY made the change adding the objects referring to sense1, which we just deleted.
            reconciler = uowService.Reconciler(newObjectSurrogates, new List <ICmObjectSurrogate>(), new List <ICmObjectId>());
            Assert.That(reconciler.OkToReconcileChanges(), Is.False,
                        "we should not be able to make a change if it involves adding an object that refers to an object we have deleted.");

            // This is cheating a little bit, because we're passing as modified objects things not in our db at all.
            // But it exercises the relevant code, making sure we check the modified objects for refs to our deleted ones.
            reconciler = uowService.Reconciler(new List <ICmObjectSurrogate>(), newObjectSurrogates, new List <ICmObjectId>());
            Assert.That(reconciler.OkToReconcileChanges(), Is.False,
                        "we should not be able to make a change if it involves adding a ref to an object we have deleted.");
        }
Esempio n. 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argument">The xCore Command object.</param>
        /// <returns>true</returns>
        public bool OnAddApprovedAnalysis(object argument)
        {
            using (EditMorphBreaksDlg dlg = new EditMorphBreaksDlg())
            {
                IWfiWordform wf = Wordform;
                if (wf == null)
                {
                    return(true);
                }
                ITsString tssWord = Wordform.Form.BestVernacularAlternative;
                string    morphs  = tssWord.Text;
                FdoCache  cache   = Cache;
                dlg.Initialize(tssWord, morphs, cache.MainCacheAccessor.WritingSystemFactory,
                               cache, m_dataEntryForm.Mediator.StringTbl, m_dataEntryForm.StyleSheet);
                Form mainWnd = m_dataEntryForm.FindForm();
                // Making the form active fixes problems like LT-2619.
                // I'm (RandyR) not sure what adverse impact might show up by doing this.
                mainWnd.Activate();
                if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
                {
                    morphs = dlg.GetMorphs().Trim();
                    if (morphs.Length == 0)
                    {
                        return(true);
                    }

                    string[] prefixMarkers  = MoMorphType.PrefixMarkers(cache);
                    string[] postfixMarkers = MoMorphType.PostfixMarkers(cache);

                    List <string> allMarkers = new List <string>();
                    foreach (string s in prefixMarkers)
                    {
                        allMarkers.Add(s);
                    }

                    foreach (string s in postfixMarkers)
                    {
                        if (!allMarkers.Contains(s))
                        {
                            allMarkers.Add(s);
                        }
                    }
                    allMarkers.Add(" ");

                    string[] breakMarkers = new string[allMarkers.Count];
                    for (int i = 0; i < allMarkers.Count; ++i)
                    {
                        breakMarkers[i] = allMarkers[i];
                    }

                    string fullForm = SandboxBase.MorphemeBreaker.DoBasicFinding(morphs, breakMarkers, prefixMarkers, postfixMarkers);

                    using (UndoRedoCommandHelper undoRedoTask = new UndoRedoCommandHelper(Cache,
                                                                                          argument as Command))
                    {
                        IWfiAnalysis newAnalysis = Wordform.AnalysesOC.Add(new WfiAnalysis());
                        newAnalysis.ApprovalStatusIcon = 1;                         // Make it human approved.
                        int vernWS = StringUtils.GetWsAtOffset(tssWord, 0);
                        foreach (string morph in fullForm.Split(Unicode.SpaceChars))
                        {
                            if (morph != null && morph.Length != 0)
                            {
                                IWfiMorphBundle mb = newAnalysis.MorphBundlesOS.Append(new WfiMorphBundle());
                                mb.Form.SetAlternative(morph, vernWS);
                            }
                        }
                        int outlineFlid = BaseVirtualHandler.GetInstalledHandlerTag(cache, "WfiAnalysis", "HumanApprovedNumber");
                        foreach (int haaHvo in Wordform.HumanApprovedAnalyses)
                        {
                            // Do PropChanged for the outline number for all of them.
                            // This fixes LT-5007, as the older ones kept their old number,
                            // which could have been a duplicate number.
                            cache.PropChanged(
                                null,
                                PropChangeType.kpctNotifyAll,
                                haaHvo,
                                outlineFlid,
                                0, 0, 0);
                        }
                        cache.PropChanged(
                            null,
                            PropChangeType.kpctNotifyAll,
                            Wordform.Hvo,
                            BaseVirtualHandler.GetInstalledHandlerTag(cache, "WfiWordform", "HumanApprovedAnalyses"),
                            0, 1, 0);
                    }
                }
            }

            return(true);
        }
Esempio n. 28
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);
        }
Esempio n. 29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Display a view of the LexEntry (or fragment thereof).
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvo"></param>
        /// <param name="frag"></param>
        /// ------------------------------------------------------------------------------------
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            CheckDisposed();

            switch (frag)
            {
            case (int)VcFrags.kfragHeadWord:
                // This case should stay in sync with
                // LexEntry.LexemeFormMorphTypeAndHomographStatic
                vwenv.OpenParagraph();
                AddHeadwordWithHomograph(vwenv, hvo);
                vwenv.CloseParagraph();
                break;

            case (int)kfragEntryAndVariant:
                IWfiMorphBundle wfb         = WfiMorphBundle.CreateFromDBObject(m_cache, hvo);
                int             hvoMf       = wfb.MorphRAHvo;
                int             hvoLexEntry = m_cache.GetOwnerOfObject(hvoMf);
                // if morphbundle morph (entry) is in a variant relationship to the morph bundle sense
                // display its entry headword and variant type information (LT-4053)
                ILexEntryRef ler     = null;
                ILexEntry    variant = LexEntry.CreateFromDBObject(m_cache, hvoLexEntry);
                if ((variant as LexEntry).IsVariantOfSenseOrOwnerEntry(wfb.SenseRA, out ler))
                {
                    // build Headword from sense's entry
                    vwenv.OpenParagraph();
                    vwenv.OpenInnerPile();
                    vwenv.AddObj(wfb.SenseRA.EntryID, this, (int)VcFrags.kfragHeadWord);
                    vwenv.CloseInnerPile();
                    vwenv.OpenInnerPile();
                    // now add variant type info
                    vwenv.AddObj(ler.Hvo, this, kfragVariantTypes);
                    vwenv.CloseInnerPile();
                    vwenv.CloseParagraph();
                    break;
                }
                else
                {
                    // build Headword even though we aren't in a variant relationship.
                    vwenv.AddObj(hvoLexEntry, this, (int)VcFrags.kfragHeadWord);
                }
                break;

            case kfragVariantTypes:
                ler = LexEntryRef.CreateFromDBObject(m_cache, hvo);
                bool fNeedInitialPlus = true;
                vwenv.OpenParagraph();
                foreach (ILexEntryType let in ler.VariantEntryTypesRS)
                {
                    // just concatenate them together separated by comma.
                    ITsString tssVariantTypeRevAbbr = let.ReverseAbbr.BestAnalysisAlternative;
                    if (tssVariantTypeRevAbbr != null && tssVariantTypeRevAbbr.Length > 0)
                    {
                        if (fNeedInitialPlus)
                        {
                            vwenv.AddString(StringUtils.MakeTss("+", m_cache.DefaultUserWs));
                        }
                        else
                        {
                            vwenv.AddString(StringUtils.MakeTss(",", m_cache.DefaultUserWs));
                        }
                        vwenv.AddString(tssVariantTypeRevAbbr);
                        fNeedInitialPlus = false;
                    }
                }
                vwenv.CloseParagraph();
                break;

            case kfragFormForm:                     // form of MoForm
                vwenv.AddStringAltMember((int)MoForm.MoFormTags.kflidForm, m_wsActual, this);
                break;

            default:
                base.Display(vwenv, hvo, frag);
                break;
            }
        }